#159914 - 2006-03-28 02:46 PM
Kix to start a remote service.
|
Stephen Wintle
Seasoned Scripter
Registered: 2001-04-10
Posts: 444
Loc: England
|
Hi,
Thanks to previous posts I can check using kix to see if service exists ie Code:
If GetObject("WinNT://" + $wrkid + "/cron,service")
Else
Endif
But can I get kix to start a given service on a remote machine if service hasn't been started?
Steve
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!
|
Top
|
|
|
|
#159915 - 2006-03-28 02:58 PM
Re: Kix to start a remote service.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
There are UDFs for this already written. Check out the UDF library...
Two service related UDFs I have submitted are: fADSIServiceRun and fADSIServiceStartup
|
Top
|
|
|
|
#159916 - 2006-03-28 03:54 PM
Re: Kix to start a remote service.
|
Stephen Wintle
Seasoned Scripter
Registered: 2001-04-10
Posts: 444
Loc: England
|
Hi Howard,
I can only get Chris's UDF I tried even following the links to the UDFs' on this page but they are no longer there..
Steve
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!
|
Top
|
|
|
|
#159917 - 2006-03-28 03:59 PM
Re: Kix to start a remote service.
|
Stephen Wintle
Seasoned Scripter
Registered: 2001-04-10
Posts: 444
Loc: England
|
Ignore previous post I found the mirror site!
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!
|
Top
|
|
|
|
#159918 - 2006-03-28 04:01 PM
Re: Kix to start a remote service.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
they were submitted more than 3 years ago. When you do your search, change the number of years in the "Newer Than" section to 6. You will get the links then.
|
Top
|
|
|
|
#159920 - 2006-03-28 04:13 PM
Re: Kix to start a remote service.
|
Stephen Wintle
Seasoned Scripter
Registered: 2001-04-10
Posts: 444
Loc: England
|
Thanks for replies,
Still in the dark though. I need to ensure that a service is started on a series of machines. How does the UDF help me to do that? can I use the UDF with RemoteExec to achieve this?
Steve.
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!
|
Top
|
|
|
|
#159923 - 2006-03-28 05:48 PM
Re: Kix to start a remote service.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If you read fADSIServiceRun, you will see that it can connect to a remote computer and then uses the "status" method to get the current current state of the service. below is a code segment from the UDF which you can tune to your own needs.
Code:
$objService = Getobject("WinNT://$Computer/$Service,Service") if @error = 0 $status = $objService.status select case $status = 4 ;Running ; do something case $status = 1 ;Stopped ; do something case $status = 7 ;Paused ; do something case 1 ? "Unhandled service status(0):$status" exit (1) endselect endif
|
Top
|
|
|
|
#159924 - 2006-03-29 11:48 AM
Re: Kix to start a remote service.
|
Stephen Wintle
Seasoned Scripter
Registered: 2001-04-10
Posts: 444
Loc: England
|
Howard,
Thanks for your reply tried the following but to no avail. Could you please give me some pointers?
Code:
Function fADSIServiceRun ($Computer, $Service, $Run) Dim $objService, $status, $StartUp ; Validate input parameters if VarType($Computer) <> 8 exit(87) endif if VarType($Service) <> 8 exit(87) endif if VarType($Run) <> 2 and VarType($Run) <> 3 and $Run >= 0 and $Run <= 3 exit(87) endif
if $Computer = "" $Computer = @wksta endif
$objService = Getobject("WinNT://$Computer/$Service,Service") if @error = 0 $status = $objService.status
select case $Run = 0 select case $status = 4 ;Running $objService.stop case $status = 1 ;Stopped exit (2182) case $status = 7 ;Paused $objService.stop case 1 ? "Unhandled service status(0):$status" exit (1) endselect case $Run = 1 select case $status = 1 ;Not Running $StartUp = $objService.get("StartType") if $StartUp <> 4 $objService.start else exit (1058) endif case $status = 7 ;Paused $objService.continue case $status = 4 ;Running exit (3521) case 1 ? "Unhandled service status(1):$status" exit (1) endselect case $Run = 2 select case $status = 4 ;Running $objService.pause case $status = 1 ;Stopped $StartUp = $objService.get("StartType") if $StartUp <> 4 $objService.start $objService.pause else exit (1058) endif case 1 ? "Unhandled service status(2):$status" exit (1) endselect endselect $objService = "" else exit @error endif EndFunction
$Computer = ReadFile('\\curricsvr1\netlogon\scripts\computers.txt') $Service = 'BeyondLogic RmtExec Server'
$objService = Getobject("WinNT://$Computer/$Service,Service") if @error = 0 $status = $objService.status select case $status = 4 ;Running ; do something
Run "Beyondexecv2 \\" + $Computer + " -d LockWorkstation -l 0" case $status = 1 ;Stopped ; do something
ServiceRun ($Computer, "BeyondLogic RmtExec Server", 1)
case $status = 7 ;Paused ; do something
ServiceRun ($Computer, "BeyondLogic RmtExec Server", 1)
case 1 ? "Unhandled service status(0):$status" exit (1) endselect endif
Function ReadFile($file) Dim $lf, $f, $_, $t $lf=CHR(10) $f=FreeFileHandle $_=Open($f,$file) If @ERROR Exit @ERROR EndIf Do $t=$t+$lf+ReadLine($f) Until @ERROR $_=Close($f) $ReadFile=Split(SubStr($t,2),$lf) EndFunction
Many thanks
Steve
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!
|
Top
|
|
|
|
#159925 - 2006-03-29 05:57 PM
Re: Kix to start a remote service.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You do not say what results/errors your code generated.
$Service = 'BeyondLogic RmtExec Server' <- I would recommend that you use the short name (name of the key for the service) in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
ServiceRun ($Computer, "BeyondLogic RmtExec Server", 1) <- this is not the UDF name. It is fADSIServiceRun.
If you provide more details, I could provide a better answer.
|
Top
|
|
|
|
#159926 - 2006-03-29 05:59 PM
Re: Kix to start a remote service.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Also add an ELSE section to the fllowing if..endif. Code:
$objService = Getobject("WinNT://$Computer/$Service,Service") if @error = 0 ... else ? $Computer ? "Error: " + @error ? " " + @serror endif
This will let you know if the remote service could not be contacted.
Edited by Howard Bullock (2006-03-29 06:00 PM)
|
Top
|
|
|
|
#159927 - 2006-03-30 01:47 PM
Re: Kix to start a remote service.
|
Stephen Wintle
Seasoned Scripter
Registered: 2001-04-10
Posts: 444
Loc: England
|
Hi Howard,
Many thanks for your help. I have tried your suggestions but the scripts does not return anything!
Steve..
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!
|
Top
|
|
|
|
#159928 - 2006-03-30 01:52 PM
Re: Kix to start a remote service.
|
Stephen Wintle
Seasoned Scripter
Registered: 2001-04-10
Posts: 444
Loc: England
|
Sorry Howard also not sure what you meant by 'using shortname' are you refering to exe or not?
Code:
;FUNCTION fADSIServiceRun() ;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com) ;ACTION Starts or stops a service. ;SYNTAX fADSIServiceRun(Computer, Service, $Run) ;PARAMETERS $Computer (Required) - String value ; $Service (Required) - String value ; $Run (Required) (0=stop or 1=start|continue or 2=Pause) ;REMARKS This function starts,stops, pauses, or continues a service on ; the local or a remote computer. This function sets @ERROR on exit. ; when "pausing" a service this function will start a stopped service then ; pause it. ;RETURNS Nothing ;DEPENDENCIES ADSI ;EXAMPLES ServiceRun ("", "Alerter", 0) ; ServiceRun ("SomeComputer", "Alerter", 1)
Function fADSIServiceRun ($Computer, $Service, $Run) Dim $objService, $status, $StartUp ; Validate input parameters if VarType($Computer) <> 8 exit(87) endif if VarType($Service) <> 8 exit(87) endif if VarType($Run) <> 2 and VarType($Run) <> 3 and $Run >= 0 and $Run <= 3 exit(87) endif
if $Computer = "" $Computer = @wksta endif
$objService = Getobject("WinNT://$Computer/$Service,Service") if @error = 0 $status = $objService.status
select case $Run = 0 select case $status = 4 ;Running $objService.stop case $status = 1 ;Stopped exit (2182) case $status = 7 ;Paused $objService.stop case 1 ? "Unhandled service status(0):$status" exit (1) endselect case $Run = 1 select case $status = 1 ;Not Running $StartUp = $objService.get("StartType") if $StartUp <> 4 $objService.start else exit (1058) endif case $status = 7 ;Paused $objService.continue case $status = 4 ;Running exit (3521) case 1 ? "Unhandled service status(1):$status" exit (1) endselect case $Run = 2 select case $status = 4 ;Running $objService.pause case $status = 1 ;Stopped $StartUp = $objService.get("StartType") if $StartUp <> 4 $objService.start $objService.pause else exit (1058) endif case 1 ? "Unhandled service status(2):$status" exit (1) endselect endselect $objService = "" else ? $Computer ? "Error: " + @error ? " " + @serror
endif EndFunction
$Computer = ReadFile('\\curricsvr1\netlogon\scripts\computers.txt') $Service = 'BeyondLogic RmtExec Server'
$objService = Getobject("WinNT://$Computer/$Service,Service") if @error = 0 $status = $objService.status select case $status = 4 ;Running ; do something
Run "Beyondexecv2 \\" + $Computer + " -d LockWorkstation -l 0" case $status = 1 ;Stopped ; do something
ServiceRun ($Computer, "BeyondLogic RmtExec Server", 1)
case $status = 7 ;Paused ; do something
ServiceRun ($Computer, "BeyondLogic RmtExec Server", 1)
case 1 ? "Unhandled service status(0):$status" exit (1) endselect endif
Function ReadFile($file) Dim $lf, $f, $_, $t $lf=CHR(10) $f=FreeFileHandle $_=Open($f,$file) If @ERROR Exit @ERROR EndIf Do $t=$t+$lf+ReadLine($f) Until @ERROR $_=Close($f) $ReadFile=Split(SubStr($t,2),$lf) EndFunction
Edited by Stephen Wintle (2006-03-30 02:02 PM)
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!
|
Top
|
|
|
|
#159929 - 2006-03-31 04:20 PM
Re: Kix to start a remote service.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Look in the registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
All the keys listed here are services. The key name is the "Short Name".
Again you are calling: ServiceRun ($Computer, "BeyondLogic RmtExec Server", 1) what is this? It is NOT the name of the UDF fADSIServiceRun.
Edited by Howard Bullock (2006-03-31 04:22 PM)
|
Top
|
|
|
|
#159931 - 2006-04-05 10:40 AM
Re: Kix to start a remote service.
|
Stephen Wintle
Seasoned Scripter
Registered: 2001-04-10
Posts: 444
Loc: England
|
Hi,
Finally the penny dropped and I did (once) get the script to lock my lockstation. However despite not changing the script in anyway im now getting the following error Code:
ERROR : unexpected command! Script: \\curricsvr1\netlogon\scripts\lock2.kix Line : 0
Ive tried stopping the server to see if it throws up any different errors but no joy..
Code:
;FUNCTION fADSIServiceRun() ;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com) ;ACTION Starts or stops a service. ;SYNTAX fADSIServiceRun(Computer, Service, $Run) ;PARAMETERS $Computer (Required) - String value ; $Service (Required) - String value ; $Run (Required) (0=stop or 1=start|continue or 2=Pause) ;REMARKS This function starts,stops, pauses, or continues a service on ; the local or a remote computer. This function sets @ERROR on exit. ; when "pausing" a service this function will start a stopped service then ; pause it. ;RETURNS Nothing ;DEPENDENCIES ADSI ;EXAMPLES ServiceRun ("", "Alerter", 0) ; ServiceRun ("SomeComputer", "Alerter", 1)
Function fADSIServiceRun ($Computer, $Service, $Run) Dim $objService, $status, $StartUp ; Validate input parameters if VarType($Computer) <> 8 exit(87) endif if VarType($Service) <> 8 exit(87) endif if VarType($Run) <> 2 and VarType($Run) <> 3 and $Run >= 0 and $Run <= 3 exit(87) endif
if $Computer = "" $Computer = @wksta endif
$objService = Getobject("WinNT://$Computer/$Service,Service") if @error = 0 $status = $objService.status
select case $Run = 0 select case $status = 4 ;Running $objService.stop case $status = 1 ;Stopped exit (2182) case $status = 7 ;Paused $objService.stop case 1 ? "Unhandled service status(0):$status" exit (1) endselect case $Run = 1 select case $status = 1 ;Not Running $StartUp = $objService.get("StartType") if $StartUp <> 4 $objService.start else exit (1058) endif case $status = 7 ;Paused $objService.continue case $status = 4 ;Running exit (3521) case 1 ? "Unhandled service status(1):$status" exit (1) endselect case $Run = 2 select case $status = 4 ;Running $objService.pause case $status = 1 ;Stopped $StartUp = $objService.get("StartType") if $StartUp <> 4 $objService.start $objService.pause else exit (1058) endif case 1 ? "Unhandled service status(2):$status" exit (1) endselect endselect $objService = "" else ? $Computer ? "Error: " + @error ? " " + @serror
endif EndFunction
$Computer = 'servxp1' ;ReadFile('\\curricsvr1\netlogon\scripts\computers.txt') $Service = 'rexesvr'
$objService = Getobject("WinNT://$Computer/$Service,Service") if @error = 0 $status = $objService.status select case $status = 4 ;Running ; do something
Run "Beyondexecv2 \\" + $Computer + " -d LockWorkstation -l 0" case $status = 1 ;Stopped ; do something
fADSIServiceRun ($Computer, $Service, 1)
case $status = 7 ;Paused ; do something
fADSIServiceRun ($Computer, $Service, 1)
case 1 ? "Unhandled service status(0):$status" exit (1) endselect else ? $Computer ? "Error: " + @error ? " " + @serror endif
EndFunction
Function ReadFile($file) Dim $lf, $f, $_, $t $lf=CHR(10) $f=FreeFileHandle $_=Open($f,$file) If @ERROR Exit @ERROR EndIf Do $t=$t+$lf+ReadLine($f) Until @ERROR $_=Close($f) $ReadFile=Split(SubStr($t,2),$lf) EndFunction
Edited by Stephen Wintle (2006-04-05 10:40 AM)
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!
|
Top
|
|
|
|
#159932 - 2006-04-05 01:06 PM
Re: Kix to start a remote service.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Quote:
...but it is in your examples
Well that just sucks... All these years I nor anyone else seemed to never notice.
|
Top
|
|
|
|
#159933 - 2006-04-05 01:12 PM
Re: Kix to start a remote service.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Do you have a pre-4.x version of KixTart somehow executing? Try putting... Code:
@kix ?
as the first line of your script.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 202 anonymous users online.
|
|
|