Solved

Accessing WTSQueryUserConfig in the wtsapi32.dll library

Posted on 2002-06-26
11
865 Views
Last Modified: 2007-11-27
I'm currently trying to access the WTSQueryUserConfig function in wtsapi32.dll using the following code (see below)

The function TSEQueryConfig seems to work as I get a True value for 'Rtn' and 'Data' returns the correct length of the buffer, however nothing is returned in the buffer.

This is VERY urgent, hence the 500 points. It doesn't matter if it's a stupid mistake, you still get all the points.

Cheers.
Greg.

----------------------------------------------------
Public Declare Function TSEQueryConfig Lib "wtsapi32" Alias _
    "WTSQueryUserConfigA" (ByVal pServername As String, _
    ByVal pUserName As String, ByVal WTSConfigClass As WTS_CONFIG_CLASS, _
   ByVal pBuffer As String, ByRef DataLength As Long) As Boolean
   
Enum WTS_CONFIG_CLASS
   WTSUserConfigInitialProgram
   WTSUserConfigWorkingDirectory
   WTSUserConfigfInheritInitialProgram
   WTSUserConfigfAllowLogonTerminalServer
   WTSUserConfigTimeoutSettingsConnections
   WTSUserConfigTimeoutSettingsDisconnections
   WTSUserConfigTimeoutSettingsIdle
   WTSUserConfigfDeviceClientDrives
   WTSUserConfigfDeviceClientPrinters
   WTSUserConfigfDeviceClientDefaultPrinter
   WTSUserConfigBrokenTimeoutSettings
   WTSUserConfigReconnectSettings
   WTSUserConfigModemCallbackSettings
   WTSUserConfigModemCallbackPhoneNumber
   WTSUserConfigShadowingSettings
   WTSUserConfigTerminalServerProfilePath
   WTSUserConfigTerminalServerHomeDir
   WTSUserConfigTerminalServerHomeDirDrive
   WTSUserConfigfTerminalServerRemoteHomeDir
End Enum

Private Sub Command1_Click()
Dim buffptr As Long

svr = "SERVER" & vbNullChar
usr = "TESTUSER" & vbNullChar

Rtn = TSEQueryConfig(svr, usr, WTSUserConfigTerminalServerProfilePath, buffptr, Data)
End Sub
------------------------------------------------------
0
Comment
Question by:GregD
11 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 7111072
You have declared the function to use pBuffer as a string but are using a long in buffptr to retrieve the result. I would imagine that if it is really a string that is returned then it should be passed as a string, if not then you would need to use CopyMemory api function to convert the returned pointer to a string.
0
 
LVL 5

Expert Comment

by:rpai
ID: 7111084
Did you try changing the WTSConfigClass parameter to check if that works?
WTSUserConfigTerminalServerProfilePath :-
The directory the path identifies must be created manually, and must exist prior to the logon. WTSSetUserConfig will not create the directory if it does not already exist.
0
 
LVL 1

Author Comment

by:GregD
ID: 7111169
TimCottee

I've tried almost all combinations for pbuffer & buffer, this one is the only one to return a True value for Rtn.
Buffer actually returns 0, not even a pointer, which is strange because the Data variable returns the correct length for the data that should be in the buffer.

rpai

Yup, tried most of the paramaters available, the one's that have data in them return the correct length in the data var, but nothing in the buffer. i.e. WTSUserConfigTerminalServerProfilePath returns 46 in the data var, which is the correct profile path & a nullchar.

WTSUserConfigTerminalServerHomeDirDrive returns 3 in the data var, which is the correct drive (H:) and a null char.

Any more ideas Guys???
0
 
LVL 1

Author Comment

by:GregD
ID: 7111177
TimCottee

I've tried almost all combinations for pbuffer & buffer, this one is the only one to return a True value for Rtn.
Buffer actually returns 0, not even a pointer, which is strange because the Data variable returns the correct length for the data that should be in the buffer.

rpai

Yup, tried most of the paramaters available, the one's that have data in them return the correct length in the data var, but nothing in the buffer. i.e. WTSUserConfigTerminalServerProfilePath returns 46 in the data var, which is the correct profile path & a nullchar.

WTSUserConfigTerminalServerHomeDirDrive returns 3 in the data var, which is the correct drive (H:) and a null char.

Any more ideas Guys???
0
 
LVL 3

Expert Comment

by:PNJ
ID: 7111273
Ah. Do you need AddressOF Buffptr where BuffPtr is Dim'ed as a String (not Long)?

Long shot and a guess really.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:PNJ
ID: 7111275
As in:

Dim BuffPtr as String

Rtn = TSEQueryConfig(svr, usr, WTSUserConfigTerminalServerProfilePath, AddressOf buffptr, Data)
0
 
LVL 1

Author Comment

by:GregD
ID: 7115919
Thanks for the tip PNJ , but I keep getting compile errors when I try that.

However if I fill the buffer first I do get some output, but it's rubbish i.e.

Dim ppBuffer As String
svr = "SERVER" & vbNullChar
usr = "TESTUSER" & vbNullChar

ppBuffer = Space$(80)
tmp = TSEQueryConfig(svr, usr, WTSUserConfigTerminalServerProfilePath, ppBuffer, Data)

I have the feeling I'm nearly there, but i'm just missing the finale piece of the puzzle. This is getting really urgent now, so I'm upping the points.

Hope someone can shed some light on this

Thanks guys
Greg.
0
 
LVL 1

Author Comment

by:GregD
ID: 7115921
Unfortunatly I can't add more than 500 points for a single question, so I will post up another 500 points (1000 points in total) to anyone who solves my little problem.

Greg.
0
 
LVL 3

Expert Comment

by:PNJ
ID: 7121370
Thinking about the last two parameters and the way other API calls seem to work, I wonder if you need to set "Data" to (eg) 80 and "ppBuffer"  to 80 spaces (as you have). I'm just wondering that not setting "Data" to anything means it gets set left at 0 and the API call is saying, "fair enough, your buffer is zero long, so you won't get anything back".

I cant' find out anything about TSEQueryConfig so I couldn't try this. (sorry about AddressOf - it needs a Function to point to)
0
 
LVL 3

Accepted Solution

by:
PNJ earned 500 total points
ID: 7121415
GregD, you've probably seen this, but in case you haven't:
http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q292631&

The code example given supports TimCottee's initial thoughts about using CopyMemory API.
0
 
LVL 1

Author Comment

by:GregD
ID: 7121616
I had searched & searched msdn & technet but couldn't find anything like this,

In the end it was something stupid I'd forgotton to include the '\\' before the server name :))

Thanks for all the tips guys, but after testing the msdn code provided by PNJ my mistake became obvious.

I'll post you another 500 points as promised PNJ.

Thanks
Greg.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 115
Copy a row 12 59
How to Add / Edit Windows Menu 4 52
Can we place a tooltip on the actual vb6 form 5 35
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now