WTSOpenServer in Windows 2008 with parameter "." is not working RRS feed

  • Question

  • Hi,

    We have one application which we are trying to qualify with windows 2008 SP2.

    Inside the application we are checking all the sessions currently we have within terminal server. In order to achieve that we are trying to use WTS API's.

    We have found that when we are trying to get the handle using WTSOpenServer (".") with parameter "." as a local machine the result is returning zero which is working find in the case of windows 2003.

    While WTSOpenServer with parameter "localhost" or hostname or IPAddress is working fine, the only problem is with ".".

    Am I missing or doing something wrong?

    Friday, August 14, 2009 12:26 AM

All replies

  • Hi Twinkle,

    Thank you for your post.

    Here are some suggestion which you may like to try out with:

    Ensure that you have SetLastError=true in your DllImport attribute, then call Marshal.GetLastWin32Error() after the call to WTSOpenServer() to get an idea about why its failing. Also check the eventlog (turn on auditing)

    Here is the link which will explain you more about GetLastError function.

    As windows server 2008 has WRP (windows resourse protection) and high security features so try doing the same operation with administrative privileges, if it works it means this requires elevated privilege.

    if the issue is  "access denied" then You have to impersonate using a privileged account's credentials (like a domain admins, or enterprise admins account).

    Hope this helps.

    Tuesday, August 25, 2009 4:27 PM