Page 1 of 1 1
Topic Options
#103922 - 2003-08-20 11:00 PM Send Message to Logged in User jt.exe
quihong Offline
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
#103923 - 2003-08-20 11:09 PM Re: Send Message to Logged in User jt.exe
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
code:
shell '%COMSPEC% /C net start messenger'

will start the messenger service.

The MESSAGEBOX will not work as the task cannot interact with the desktop of the currently logged-in user.

There are UDFs in the UDF Forum that can check whether user's are logged into the computer. Be aware that the user under which the task runs will also be counted as a logged-in user.

[ 20. August 2003, 23:10: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#103924 - 2003-08-21 02:30 AM Re: Send Message to Logged in User jt.exe
quihong Offline
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
#103925 - 2003-08-21 04:02 AM Re: Send Message to Logged in User jt.exe
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Take a look at the KiXtart ZIP distribution as it contains XNET, whcih might help, too, in managing services. There are also multiple service-related UDFs in the UDF Forum.

And please fix the long lines in your code.

[ 21. August 2003, 04:03: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#103926 - 2003-08-21 08:54 PM Re: Send Message to Logged in User jt.exe
quihong Offline
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
#103927 - 2003-08-21 08:57 PM Re: Send Message to Logged in User jt.exe
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The logoff event happens because you're not using BREAK ON in the beginning of your script. See the KiXtart Manual for more info.

Also, put a DEBUG ON into the first line of your script to identify the failing line in your code.

Alternatively, try the fnWMILoggedIn() UDF if you have WMI available.
_________________________
There are two types of vessels, submarines and targets.

Top
#103928 - 2003-08-21 08:58 PM Re: Send Message to Logged in User jt.exe
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure.
1st, the processor usage means that it's extensive UDF or that there is logical error.

the logged off thing is kix's normal behaviour.
if you want to exit kixtart, you need to use kill or set the "break on"
_________________________
!

download KiXnet

Top
#103929 - 2003-08-21 11:45 PM Re: Send Message to Logged in User jt.exe
quihong Offline
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
#103930 - 2003-08-21 11:53 PM Re: Send Message to Logged in User jt.exe
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the 259 is from manual:
quote:

EnumValue( )

Action: Allows you to list the names of the registry entries contained in a specific key or subkey.

Syntax: ENUMVALUE ("subkey", index)

Parameters: Subkey
Specifies the key or subkey for which you want to enumerate the value entries.

Index

A numeric value representing the position of the entry whose name you want to discover. Zero (0) represents the first entry in the subkey.
Returns: String Function returns a string representing the entry in the specified key or subkey.
259 Subkey does not exist.
Error code Function failed.

so, if it's blank, there is something weird going on.
_________________________
!

download KiXnet

Top
#103931 - 2003-08-22 12:32 AM Re: Send Message to Logged in User jt.exe
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
XNET could do the trick...

I tried this at the command prompt:

c:\XNET MODIFY \\machine\service /s:auto
c:\XNET START \\machine\service
c:\net send %COMPUTERNAME% "Blaster patch installed"
c:\XNET MODIFY \\machine\service /s:disabled
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#103932 - 2003-08-22 12:44 AM Re: Send Message to Logged in User jt.exe
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
nice postcount pat [Wink]
_________________________
!

download KiXnet

Top
#103933 - 2003-08-22 01:07 AM Re: Send Message to Logged in User jt.exe
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Didn't notice it...

888, euh 889 now. 111 to go to be a M-club member [Big Grin] Can't wait to get the T-shirt [Wink]
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#103934 - 2003-08-22 05:36 PM Re: Send Message to Logged in User jt.exe
quihong Offline
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
#103935 - 2003-08-22 05:51 PM Re: Send Message to Logged in User jt.exe
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Time to point out ABC's of KiXtart board etiquette and message to new forum users , Section F.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 931 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.072 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org