Thread: Failure to Retrieve Domain Name

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    88

    Failure to Retrieve Domain Name

    I am using NetWkstaGetInfo in order to determine the domain name of the computer my application is running on. This works fine both as an executable run from a user profile and from a windows service immediately running the code upon launch.

    However, NetWkstaGetInfo fails when I attempt to run it from the Startup routine of a Winlogon Notify dll. If I delay the execution it succeeds. However if it runs without some sort of pause, it fails.

    Does anyone know why exactly this is failing without the pause? I imagine the network information obtained by the function might not be available. Is there anyway to detect when it is available in a non-busy manner (I prefer whenever possible not to sleep and loop)? Is there any other technique that might succeed when NetWkstaGetInfo fails? I have tried GetNetworkParams. It gives no indication of failure, however the domain name it acquires is just an empty string if I do not include a pause.

    Thanks for any help you can give.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    It gives no indication of failure
    This puzzles me. Does this mean that NetWkstaGetInfo returned a NERR_Success but yet the domain string is empty?

    The only thing that comes to mind which might cause NetWkstaGetInfo to fail at startup is that the Workstation Service is not completely functional. In this case, NetWkstaGetInfo would return NERR_WkstaNotStarted. You would now have to continually query the operational status of the Workstation Service to determine if it was up and running and then make your call to NetWkstaGetInfo.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I think this may be caused by the account (Local System?) that the notify DLL is executed in, not having network credentials.

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    88
    Bob: The no indiciation of failure was in reference to GetNetworkParams. GetNetworkParams return ERROR_SUCCESS, yet the domain name string is empty. I believe you are right in that the Workstation is not to the point where it can successfully execute the command. Ideally I am looking for a way to receive a message as soon as it is ready so I can wait on it with a WaitForSingleObject. I do not know how the function works. It may be as simple a matter as the registry hive was not fully loaded so and an attempt to read it fails. Or it might be more complicated. I am hoping to find someway to wait for it to occur without just continuously looping busily if possible. It might very well be impossible.

    Anoytmouse:
    I believe the DLL has proper credentials because if I put a pause into the code, I am able to successfully get the domain name.

    Thanks for your input guys. If anyone has a non-busy way to wait on the availabilty of the network info, I would appreciate it immensely.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Maybe I'm missing something here, but why not just query the registry for the domain name of the computer that your application is running on?

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    88
    Bob:

    Do you have a method for retrieving it from the registry? I do not think it is trivial especially when you get into the situation of a computer that has been on both a workgroup and a domain. If you do have a method that works as consitently as the APIs, I would be very interested. Thanks for the input.

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Take a look at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Servic es\TCPIP\Parameters registry key.

    A starter for using the registry API's can be found at http://www.windowsitlibrary.com/Content/595/1.html

  8. #8
    Registered User
    Join Date
    Nov 2005
    Posts
    88
    Bob, I checked in Parameters like you said but was unable to find the name of my workgroup. I then proceeded to search the entire registry for my workgroup name. The search turned up no results. However, the two API functions listed before (when windows has loaded properly) is capable of returning my workgroup name successfully. If it does exist in the registry (which I am still inclined to believe it does), I would have to assume it exists in some encrypted (or perhaps binary) form.

    Thank you for the suggestion. It is still a possiblity to directly read from the registry, but I am not sure if and where it exists at the moment.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Try HKEY_LOCAL_MACHINE\Software\Microsoft\ Windows NT\CurrentVersion\Winlogon

  10. #10
    Registered User
    Join Date
    Nov 2005
    Posts
    88
    Bob:

    I imagine you are referring to DefaultDomainName. This works correctly if you are logging onto a domain, however if you are logging on to a computer that is on a workgroup, it does not. The DefaultDomainName is the machine name in that case, not the name of the workgroup. Thank you for the suggestion though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Integer Emulation
    By Elysia in forum C++ Programming
    Replies: 31
    Last Post: 03-18-2008, 01:03 PM
  3. registering a domain
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 06-28-2004, 01:13 PM
  4. Domain Resolution :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 08-01-2002, 03:34 PM
  5. MSN Vital Information
    By iain in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 09-22-2001, 08:55 PM