Question : Query Terminal Server via vbscript

Dear Experts,
I'm trying to query the opened sessions on a Terminal Server running Windows 2008 R2 from a Windows 2008 R2.
I need to retrieve username, sessionid and status.
I don't want to use tools such as quser or similars, I want to use straight vbscript code.
As far as I know I cannot achieve this using WMI.
I googled it A LOT, an it seems we are down to two options:

- EOLWTSCOM: unfortunately this company has disappeared, I found their dll on another website but it only works on Windows XP/2003
- WTSAPI: WTSAPI32.dll: This seems to be the way to go but:
1:
serverhandle = wtsopenserver("servername")

returns: Type mismatch: 'WTSopenserver' (I think this means it didn't find that function).

Any idea?

Thanks in advance,
Roberto.

Answer : Query Terminal Server via vbscript

HTH,
exx
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
server = "MyServer"
Set ws = CreateObject("WScript.Shell")
Set oExec = ws.Exec("quser /server:" & server)
Do 
	WScript.Sleep 10
Loop Until oExec.Status = 1
Do Until oExec.stdOut.atEndOfStream
         'insert code here to evaluate output
	'oExec.StdOut.readLine will allow you to access the output
         'one line at a time
Loop
Random Solutions  
 
programming4us programming4us