Page 2 of 2 <12
Topic Options
#159934 - 2006-04-05 01:58 PM Re: Kix to start a remote service.
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Try this (you had a endfunction lying around... )
Code:

$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



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

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


And just a sidenote - It's much easier to read something when you call a function first, and then have the functions (last or in different file)
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#159935 - 2006-04-05 03:07 PM Re: Kix to start a remote service.
Stephen Wintle Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 444
Loc: England
Many thanks for pointers,

When I run the script with my array enabled, it comes with the following error Code:
ERROR : Error in expression: this type of array not supported in expressions.
Script: \\curricsvr1\netlogon\scripts\lock2.kix
Line : 29



Code changes:

Code:
 $Computer = 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 Shutdown -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

_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!

Top
#159936 - 2006-04-05 03:20 PM Re: Kix to start a remote service.
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You need to split up the $computer var.
If I understand right it now contains a array of computers and not just one computer.
Doing a For Each Next on $computer and doing all the stuff inside this loop might work. Can’t test it myself.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 2 of 2 <12


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

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

Generated in 0.094 seconds in which 0.014 seconds were spent on a total of 13 queries. Zlib compression enabled.

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