Session 0 and checking if someone logged in and sending messages questions

Started by hcbph, April 29, 2015, 03:08:57 AM

Previous topic - Next topic

hcbph

We have a number of things that run via the local System Account in Session 0, now in Windows 7 & 8, 32 & 64 bit systems, the old Xp, Win2K, etc. methods no longer work with these OS.  My problem is I need to figure out if someone is actually logged into the computer.  If they are still logged in, how to positively identify the session number they're using in the case more than 1 person might be logged into the same computer.
If you know a way to positively identify if someone is working and their session # via Winbatch is the first part of this question?
The second part is how to send a screen message to that user in that other session from Session 0?  I found the Wil Extender reference to wtssendmessage but not enough  info on it to actually use wtssendmessage (only found the basic info referenced in the WIL Extender page), help brings up nothing.  I've looked at the Microsoft website and have not been able to figure out how to use the wtssendmessage.api from Winbatch.

I can usually figure out what I need in Winbatch if I have a working example to start from, but I've not found anything useful other than some vague references it's possible.  Anyone have working code or know how to make it work to handle these 2 situations?

Thanks in advance.

hcbph

Forgot to note, the running winbatch exe's is via a software delivery system that runs apps as the local system account on the pc.  They are not running as services etc on the pc, rather directly on the pc via that account.  It runs them on the pc the same as someone with local admin rights on it can but with no screen or keyboard interaction, just silent installs.

td

Quote from: hcbph on April 29, 2015, 03:08:57 AM
We have a number of things that run via the local System Account in Session 0, now in Windows 7 & 8, 32 & 64 bit systems, the old Xp, Win2K, etc. methods no longer work with these OS.  My problem is I need to figure out if someone is actually logged into the computer.  If they are still logged in, how to positively identify the session number they're using in the case more than 1 person might be logged into the same computer.
If you know a way to positively identify if someone is working and their session # via Winbatch is the first part of this question?

You can either use WMI or use the Terminal Service extender to obtain the session ids of all logged on users.  Using the extender's wtsEnumSessions and  wtsQuerySessionInfo
functions in combination will get you the information you want as well as a bunch of other stuff.

Quote
The second part is how to send a screen message to that user in that other session from Session 0?  I found the Wil Extender reference to wtssendmessage but not enough  info on it to actually use wtssendmessage (only found the basic info referenced in the WIL Extender page), help brings up nothing.  I've looked at the Microsoft website and have not been able to figure out how to use the wtssendmessage.api from Winbatch.

You need to have an extender installed on your system to have access to the extender's help information.  Only the Control Manager and Network extenders come as part of the WinBatch installation.  All extenders are available on the download page (link at the top of this forum) and once the extender is properly installed, the extender  help will be automagically integrated into the Consolidated WIL Help system.

Quote
I can usually figure out what I need in Winbatch if I have a working example to start from, but I've not found anything useful other than some vague references it's possible.  Anyone have working code or know how to make it work to handle these 2 situations?

Check out the extender documentation.  It should be a fairly straight forward script.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hcbph

Apparently the help file didn't load correctly the first time, this is all I was working off of:
wtssendmessage()      ;( server, session, title, message, style, timeout, wait-flag )

Unfortunately it didn't tell me much.  Now that the help file loaded, I'll dig into that further.
Thanks.

hcbph

For anyone else fighting this issue, I've figured out how to work it in Winbatch - sending a screen to a logged in user from Session 0.  Load the zip file (wwwts44i.zip) then use this to see how it works.  This is just some sample code (not complete but the important info) that proved it could work, obviously it's just a proof of concept.  Hope this helps someone out.

;================
AddExtender('WWWTS44I.DLL',0,'WWWTS64I.DLL') ;requited for WTSSendMessage
.........
gosub Get_Session_ID
Msg_Timer=3               ;how long should window show by default
gosub Send_msg   ;testing sending msg from Session 0
if strLoggedOnUser > ""
   MSG = "This is a test message from Session 0"
   results=wtssendmessage("",SessId,"Test Message",MSG,0|64|0,15,@FALSE)
endIf
intcontrol(1000,0,0,0,0)  ;autodelivery tools may indicate a install error unless a return code of 0 is set
Exit
;=============
:send_msg;requires AddExtender( "WWWTS44I.DLL" , 0, "WWWTS64I.DLL" ) Requires wwwts44i.zip on source pc
;wtssendmessage()      ;( server, session, title, message, style, timeout, wait-flag ) ; format of command
if strLoggedOnUser > ""
   results=wtssendmessage("",SessId,"Test 1a","This is a test 1a",0|64|0,Msg_Timer,@FALSE)   
endIf
return
;==========
:Get_Session_ID   ;requires AddExtender( "WWWTS44I.DLL" , 0, "WWWTS64I.DLL" ) Requires wwwts44i.zip
ServerSpec = ''
SessId = wtsGetActiveConsoleSessId()
arrSession = wtsQuerySessionInfo( ServerSpec, SessId )
strLoggedOnUser = arrSession[14]
return
;========

This sample uses the OK button but it isn't read and doesn't wait for a user response.  See help for details.

hcbph

Just a FYI.  Found the extender works if someone is logged into a pc, or using a remote control package like Dameware, but not RDP.  I did find some script for vb the did find those rdp sessions though.  Took a coworkers help as I'm not knowdgable in either vb or wmi but it does work.

td

It is a relatively simple and straight forward task to convert any vb script that uses WMI to WinBatch.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

ChuckC

Quote from: hcbph on May 27, 2015, 01:45:16 PM
Just a FYI.  Found the extender works if someone is logged into a pc, or using a remote control package like Dameware, but not RDP.  I did find some script for vb the did find those rdp sessions though.  Took a coworkers help as I'm not knowdgable in either vb or wmi but it does work.


I can assure you that the WTS extender can enumerate all of the "RDP sessions" on a server.  RDP is the underlying protocol [Remote Desktop Protocol] used to connect the Remote Desktop Client application to a terminal services session on a remote Windows Server system.  So, when you are referring to an RDP session, what you are really referring to is a terminal services session which is connected to a client application via RDP.

If you were using Citrix, the underlying protocol was, and probably still is, ICA, which was used with both WinFrame and MetaFrame versions of Citrix.  Citrix itself is a "value-added" add-on product that sits on top of the Windows Terminal Services functionality and extends its capabilities.

td

Thanks Chuck.  Thought it a peculiar assertion that the TS extender couldn't identify RDP sessions. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade