Wednesday, December 05, 2007

DirectoryEntry: "Domain not found or cannot bind"

Be careful using System.DirectoryServices.DirectoryEntry() in a Web Service.

Even if user and password are specified in constructor, the connection somatimes cnnot be established.

DirectoryEntry de = new DirectoryEntry("LDAP://dc=abcde,dc=fgh","ADuser","ADpwd");

string sName = de.Name, // <-- Exception thrown

Same code may run without problems as console application, but stuck on thrown exception in Web Service.
The reason is: the service account used for Web Service cannot resolve domain name and detect DC address.

Workaround: resolve DC address and put it into LDAP connection string:

DirectoryEntry de = new DirectoryEntry("LDAP://dcMachineNameOrIPAddress/dc=abcde,dc=fgh","ADuser","ADpwd");

string sName = de.Name, // Works now

Enjoy!

Wednesday, July 04, 2007

Windows Server 2003 SBS: Active Directory related issues

Do you have/plan for Windows Server 2003? Mind following caveats:

  1. W2K3 SBS operates on different AD model (3.0) as W2K3 SBS R2 (3.1).
  2. There's only one W2K3 SBS in a domain – and it is at its root!
  3. Do not even think to add W2K3 SBS as DC to an existing domain!
  4. Mind the W2K3 doesn't "understand" and operate trusts – it just removes from AD (in case if you succeeded to joint it to domain as a DC) on the next replication.

…and one more thing to do, if you install a W2K3 pure (means - no SPs): apply SP2 before joining domain. Otherwise you may encounter problem receiving "Timeout expired for semaphore…"

Enjoy!

Friday, June 01, 2007

Get printer state using SNMP

Nothing easier on windows: there's a very useful library called OLEPRN.DLL sitting in system folder.

You may use VBS like follows:

dim o

' create an COM object to communicate to network printer

set o = createobject("oleprn.olesnmp")

' open a snmp session to printer using its IP address, public interface, retry count 1 and 6000 msecs as timeout

o.open "192.168.1.18","public",1,6000

' get printer state by state OID

x = o.GetAsByte("25.3.2.1.5.1") '

' output the state: 2 is OK, all others are warning/error codes '

' change MsgBox to desired notification method '

MsgBox x


 

You may want to write a C++ code:

#include
"stdafx.h"

#import
"d:\\windows\\system32\\oleprn.dll" no_namespace

#define USAGE _T("usage: %s <printer IP address>\nsample: %s 10.10.10.10")


 

int _tmain(int argc, _TCHAR* argv[])

{

    if(argc < 2)

    {

        wprintf(USAGE,argv[0],argv[0]);

        return -1;

    }

    CoInitialize(NULL);

    ISNMPPtr aPtr;

    _bstr_t bstrHost(argv[1]);

    _bstr_t bstrCommunity("public");

    _bstr_t bstrOID("25.3.2.1.5.1");

    HRESULT hr = S_OK;

    try

    {

        hr = aPtr.CreateInstance(__uuidof(SNMP));

        hr = aPtr->Open(bstrHost,bstrCommunity);

        int iStatus = aPtr->GetAsByte(bstrOID);

        printf("Status %d\n",iStatus);

        aPtr.Release();

    }

    catch(_com_error *e)

    {

        wprintf(e->ErrorMessage());

    }

    catch(...)

    {        

        wprintf(_T("Unknown error occured\n"));

    }

    CoUninitialize();

    return 0;

}


 

Or you may want to get it working in managed code:

http://blog.crowe.co.nz/archive/2005/08/08/182.aspx


 

Enjoy!

Wednesday, May 30, 2007

Lenovo x60, x60s notebook: „cannot find boot drive“ problem

Lenovo x60/x60s notebooks are available with preinstalled Windows with an rescue "ThinkVantage" partition to restore OS in case of danger.


 

But once you try to add another Windows installation to your machine, you get problems.

That all starts with partitioning: you need a separate partition to install another Windows there. So get a partitioning tool and go ahead.

  • I failed to boot from USB drive (bootable for my desktop PC!) containing partitioning tools, so needed to have an USB CD-ROM since the box has no own CD-ROM neither slot for that purpose.
  • Booting from CD-ROM is also not funny since you need to load proper USB drivers supporting external CD-ROMs to be able to access CD-ROM files and programs after boot. I succeeded finally to boot from the _you_know_what_disk_I_mean disk while many other (free, shareware and license-based) distributives made me sick hanging the machine during the boot and making the box not responsible.

    Mind to boot DOS first, then select USB drivers with no EMM support, then select the second option (not all available drivers, but explicitly the second option!).
  • Well, once booted, then after some "dances with a drums and trumpets" I succeeded to split existing primary partition to two holding Windows on one of result partitions and second one as clean.
  • Now start to install Windows on the second partition: after brave copying setup bootstrap files, Windows restarts the machine and shows blue screen (error 0x00000007) which means "no boot disks" detected.
  • You may retry, scream and cry - whatever… the only solution is: restart the machine, go to BIOS settings and change the SATA HDD controller mode to "Compatibility". Do not forget to save the changes and restart the box again. Now you can setup Windows on the new partition as you may have done hundred times before.


Refer also: http://www-307.ibm.com/pc/support/site.wss/MIGR-65345.html.


Enjoy!

Tuesday, May 29, 2007

RSS Viewer MOSS 2007 Webpart via proxy

You may want to extend your MOSS 2007 Web page with a RSS Viewer WebPart. It works fine until you use your Web access via proxy server. This way you will be confused seeing RSS feeds just fine in an Internet Browser, but getting an error message with the same URL in MOSS Web page with RSS Viewer WebPart:


An unexpected error occurred processing your request.


Edit your web.config: insert following snippet and edit your proxy server/port data:


<system.net>

<defaultproxy>

<proxy proxyaddress="http://Proxy_Server:port" bypassonlocal = "true"/>

</defaultproxy>

</system.net>

Restart IIS and enjoy!

Wednesday, February 21, 2007

Implementing „Cockpit“ view for InfoPath 2003 based forms

Yes, there are still some InfoPath 2003 based forms in use all over the world. And yes, there are still some requirements to adjust them to business needs.


Wherever it goes, I recommend to go to InfoPath 2007. But sometimes it is too hard due to business requirements (update huge amount of workstations, change forms, user education etc.). I was just involved in one of the projects requiring changes in existing IP03 forms. Sure, InfoPath 2007 is far more extensible as InfoPath 2003, but even with 2003 version you can do amazing things.


The challenge was to design a form with one view for print out (as near to its original paper version as possible) and one simplified – for data entry and editing only (we called it later "Cockpit view"). The benefit of the solution is: the user gets a compact front end for data entry and changes and printed form looks likes the paper version.


So how we did it:

  1. We designed a form with two views and called them "Cockpit" (Default view for the form) and "PrintView" (what should be sent to printer).
  2. "PrintView" implements all the graphics and layout of paper version.
  3. "Cockpit" contains only simplified design with controls for data entry and edit.
  4. Both views are connected via "Data Source" – the field in Cockpit and PrintView have synchronized bindings.
  5. PrintView should be excluded from View menu (uncheck in View properties) – this way the user will see only Cockpit entering or changing data.


  6. Cockpit still can be shown to user and is a default view for the form:




  7. We do not want to get Cockpit view printed, so change the print setting for the view:




  8. Now save and publish.

Sample form available on request.

Enjoy!