#103922 - 2003-08-20 11:00 PM
Send Message to Logged in User jt.exe
|
quihong
Fresh Scripter
Registered: 2003-08-20
Posts: 5
|
Hello,
I am testing Remote Task Scheduler (jt.exe) to deploy application/patches. In this case I am trying to deploy the Mblast virus patch.
I use jt.exe to schedule a task on a user's computer which allows the script to run as a Admin. The script runs find and the patch gets installed.
However, when I use the MESSAGEBOX() function it does not display a message box for the current logged in user (if there is one). It will only display the message box if the current logged in user is the Admin account that scheduled the script. Does that make sense? I guess the when the Task Schedule run the script as admin_user, Windows NT creates a new shell for that admin_user and MessageBox get displayed in admin_user's shell and not the regular user that is logged in, shell.
Basically, I want to notify the user that is logged in to reboot there computer so the patch can take affect.
I tried to use the SENDMESSAGE() function however the Messenger Service is DISABLE on all the workstation. Is there a way to start a service by commandline if it is disabled? If this is possible I can enable the Messenger Service, Send a message, and disable it again.
Also, It would be nice to reboot the computer if no one is logged in. Does anyone know how to check if a user is logged in and reboot the computer if no one is logged in?
Any help would be great. Thanks.
|
|
Top
|
|
|
|
#103924 - 2003-08-21 02:30 AM
Re: Send Message to Logged in User jt.exe
|
quihong
Fresh Scripter
Registered: 2003-08-20
Posts: 5
|
Thanks for the quick reply.
code:
shell '%COMSPEC% /C net start messenger'
Will not work since the service is DISABLED.
I searched around and found sc.exe from the NT resource kit which allows me to ENABLE the service and then start it.
code:
;start messenger service so we can alert user to reboot shell "Z:\tools\sc config messenger start= auto" shell "Z:\tools\sc start messenger"
;give it some time to start sleep 5
$retcode=sendmessage(@WKSTA, 'Your computer has just been patched for the Mblast Virus. Please reboot this computer AS SOON AS POSSIBLE and log in again.')
sleep 2 shell "Z:\tools\sc config messenger start= disable" shell "Z:\tools\sc stop messenger"
I did a search on the UDF forum but couldn't find the "check if user is logged on" fuction.
Qui [ 21. August 2003, 20:51: Message edited by: quihong ]
|
|
Top
|
|
|
|
#103926 - 2003-08-21 08:54 PM
Re: Send Message to Logged in User jt.exe
|
quihong
Fresh Scripter
Registered: 2003-08-20
Posts: 5
|
Jens,
Okay I found the LoggedInUsers() UDF that you wrote. However, when I try to run it, it locks up. My processor time goes to 99% and nothing happens. When I end the cmd screen, all my applications closes and the computer logs me off.
code:
;FUNCTION LOGGEDINUSERS() ; ;ACTION Retrieves a list of users/SIDs currently logged into the specified computer ; ;AUTHOR Jens Meyer (sealeopard@usa.net) ; ;VERSION 1.4 (cleaned up code, added error code return) ; 1.3 (removed dependency) ; 1.2 ; ;DATE CREATED 2002/02/13 ; ;DATE MODIFIED 2003/06/24 ; ;KIXTART 4.20+ ; ;SYNTAX ARRAY = LOGGEDINUSERS([COMPUTER]) ; ;PARAMETERS COMPUTER ; Optional string specifying the remote computer to check, by default the local ; computer will be used to retrieve the list of users ; ;RETURN List of usernames/SIDs ; ;REMARKS Services that run under a specific user account will be returned, too. This function is ; not limited to interactive sessions. ; ;DEPENDENCIES none ; ;EXAMPLE $array = loggedinusers('WORKSTATION') ; ;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000167 ; function loggedinusers(optional $computer) Dim $regkey, $hivelist, $hive, $usersid, $username Dim $userlist
$loggedinusers='' $regkey='HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\HiveList' if trim($computer) $regkey='\\'+trim($computer)+'\'+$regkey endif if keyexist($regkey) do $hive=enumvalue($regkey,ubound($hivelist)+1) if not @ERROR redim preserve $hivelist[ubound($hivelist)+1] $hivelist[ubound($hivelist)]=$hive endif until $hive=259 or @ERROR
for each $hive in $hivelist if instr($hive,'\REGISTRY\USER') and not instr($hive,'\REGISTRY\USER\.DEFAULT') $usersid=right($hive,len($hive)-instrrev($hive,'\')) $username=sidtoname($usersid) if $username='' $username=$usersid endif if ascan($userlist,$username)=-1 redim preserve $userlist[ubound($userlist)+1] $userlist[ubound($userlist)]=$username endif endif next endif
if ubound($userlist)+1 $loggedinusers=$userlist endif exit 0 endfunction
Any idea why?
Thanks
|
|
Top
|
|
|
|
#103929 - 2003-08-21 11:45 PM
Re: Send Message to Logged in User jt.exe
|
quihong
Fresh Scripter
Registered: 2003-08-20
Posts: 5
|
Thanks for the quick reply guys.
I turned the BREAK and DEBUG ON.
Here is what I found out. There is a infinite loop here:
code:
do $hive=enumvalue($regkey,ubound($hivelist)+1) ? $hive if not @ERROR redim preserve $hivelist[ubound($hivelist)+1] $hivelist[ubound($hivelist)]=$hive endif ? $hive ? @ERROR until $hive=259 or @ERROR
At the end of the loop, $hive has a value of nothing (nothing gets printed) and @ERROR remains at 0.
Why do it check if $hive equals 259?
Any idea on how to fix this. I am new at Kix and don't understand the logic. Any help would be great.
Thanks
|
|
Top
|
|
|
|
#103934 - 2003-08-22 05:36 PM
Re: Send Message to Logged in User jt.exe
|
quihong
Fresh Scripter
Registered: 2003-08-20
Posts: 5
|
Okay,
I figured out the problem with the infinite loop.
I was running a old version of KiX, 4.0.2, which had some some problem with multi-dimensional arrays.
Thanks for everyone's help. [ 22. August 2003, 18:48: Message edited by: quihong ]
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1045 anonymous users online.
|
|
|