GregD
asked on
Accessing WTSQueryUserConfig in the wtsapi32.dll library
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
WTSUserConfigInitialProgra m
WTSUserConfigWorkingDirect ory
WTSUserConfigfInheritIniti alProgram
WTSUserConfigfAllowLogonTe rminalServ er
WTSUserConfigTimeoutSettin gsConnecti ons
WTSUserConfigTimeoutSettin gsDisconne ctions
WTSUserConfigTimeoutSettin gsIdle
WTSUserConfigfDeviceClient Drives
WTSUserConfigfDeviceClient Printers
WTSUserConfigfDeviceClient DefaultPri nter
WTSUserConfigBrokenTimeout Settings
WTSUserConfigReconnectSett ings
WTSUserConfigModemCallback Settings
WTSUserConfigModemCallback PhoneNumbe r
WTSUserConfigShadowingSett ings
WTSUserConfigTerminalServe rProfilePa th
WTSUserConfigTerminalServe rHomeDir
WTSUserConfigTerminalServe rHomeDirDr ive
WTSUserConfigfTerminalServ erRemoteHo meDir
End Enum
Private Sub Command1_Click()
Dim buffptr As Long
svr = "SERVER" & vbNullChar
usr = "TESTUSER" & vbNullChar
Rtn = TSEQueryConfig(svr, usr, WTSUserConfigTerminalServe rProfilePa th, buffptr, Data)
End Sub
-------------------------- ---------- ---------- --------
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
WTSUserConfigInitialProgra
WTSUserConfigWorkingDirect
WTSUserConfigfInheritIniti
WTSUserConfigfAllowLogonTe
WTSUserConfigTimeoutSettin
WTSUserConfigTimeoutSettin
WTSUserConfigTimeoutSettin
WTSUserConfigfDeviceClient
WTSUserConfigfDeviceClient
WTSUserConfigfDeviceClient
WTSUserConfigBrokenTimeout
WTSUserConfigReconnectSett
WTSUserConfigModemCallback
WTSUserConfigModemCallback
WTSUserConfigShadowingSett
WTSUserConfigTerminalServe
WTSUserConfigTerminalServe
WTSUserConfigTerminalServe
WTSUserConfigfTerminalServ
End Enum
Private Sub Command1_Click()
Dim buffptr As Long
svr = "SERVER" & vbNullChar
usr = "TESTUSER" & vbNullChar
Rtn = TSEQueryConfig(svr, usr, WTSUserConfigTerminalServe
End Sub
--------------------------
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.
Did you try changing the WTSConfigClass parameter to check if that works?
WTSUserConfigTerminalServe rProfilePa th :-
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.
WTSUserConfigTerminalServe
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.
ASKER
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. WTSUserConfigTerminalServe rProfilePa th returns 46 in the data var, which is the correct profile path & a nullchar.
WTSUserConfigTerminalServe rHomeDirDr ive returns 3 in the data var, which is the correct drive (H:) and a null char.
Any more ideas Guys???
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. WTSUserConfigTerminalServe
WTSUserConfigTerminalServe
Any more ideas Guys???
ASKER
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. WTSUserConfigTerminalServe rProfilePa th returns 46 in the data var, which is the correct profile path & a nullchar.
WTSUserConfigTerminalServe rHomeDirDr ive returns 3 in the data var, which is the correct drive (H:) and a null char.
Any more ideas Guys???
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. WTSUserConfigTerminalServe
WTSUserConfigTerminalServe
Any more ideas Guys???
Ah. Do you need AddressOF Buffptr where BuffPtr is Dim'ed as a String (not Long)?
Long shot and a guess really.
Long shot and a guess really.
As in:
Dim BuffPtr as String
Rtn = TSEQueryConfig(svr, usr, WTSUserConfigTerminalServe rProfilePa th, AddressOf buffptr, Data)
Dim BuffPtr as String
Rtn = TSEQueryConfig(svr, usr, WTSUserConfigTerminalServe
ASKER
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, WTSUserConfigTerminalServe rProfilePa th, 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.
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, WTSUserConfigTerminalServe
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.
ASKER
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.
Greg.
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)
I cant' find out anything about TSEQueryConfig so I couldn't try this. (sorry about AddressOf - it needs a Function to point to)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.