#147494 - 2005-09-11 06:20 AM
WMI Service state
|
RickB
Fresh Scripter
Registered: 2005-04-21
Posts: 11
Loc: Atlanta, Ga.
|
Can someone tell me, what I'm doing wrong? Have tried changing the variable for $computer name - it does work when an explict computer name is used, But I would like to check 50 plus servers... and not do it manually.
Thanks for your advice!
;--------------------------------------------- code Break=on $LogFile = '090805.log' Call 'C:\KixScripts\UDF\NetView.udf' IF RedirectOutput($LogFile,1) = 0 for each $computer in NetView $xQuery = WMIService("SpntSvc","query","$computer") $xMode = WMIService("SpntSvc","startmode","$computer") $computer + $xQuery + $xMode ? next endif
function WMIService($service,optional $action,optional $startmode,optional $computer) Dim $wmi,$svc,$services,$sm,$st if not $computer $computer=@wksta endif $wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer") $services=$wmi.ExecQuery("Select * from Win32_Service where name = '$service'") if not @error for each $svc in $services If instr("AUTOMATIC,MANUAL,DISABLED",$startmode) $ = $svc.ChangeStartMode($startmode) endif if $svc.State <> $action select case $action = "START" $ = $svc.StartService() case $action = "STOP" $ = $svc.StopService() case $action = "PAUSE" $ = $svc.PauseService() case $action = "RESUME" $ = $svc.ResumeService() endselect endif next $wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer") $services=$wmi.ExecQuery("Select * from Win32_Service where name = '$service'") for each $svc in $services $sm=$svc.StartMode $st=$svc.State $WMIService = "$st $sm" next $wmi=0 else exit 2 endif endfunction
|
|
Top
|
|
|
|
#147496 - 2005-09-11 06:21 PM
Re: WMI Service state
|
RickB
Fresh Scripter
Registered: 2005-04-21
Posts: 11
Loc: Atlanta, Ga.
|
Have tried without quotes, still not working...
------------------------------------------------ repostCode:
Break=on $LogFile = '090805.log' Call 'C:\KixScripts\UDF\NetView.udf' IF RedirectOutput($LogFile,1) = 0 for each $computer in NetView $xQuery = WMIService("SpntSvc","query","$computer") $xMode = WMIService("SpntSvc","startmode","$computer") $computer + $xQuery + $xMode ? next endif
; ; function WMIService($service,optional $action,optional $startmode,optional $computer) Dim $wmi,$svc,$services,$sm,$st
if not $computer $computer=@wksta endif $wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer") $services=$wmi.ExecQuery("Select * from Win32_Service where name = '$service'") if not @error for each $svc in $services If instr("AUTOMATIC,MANUAL,DISABLED",$startmode) $ = $svc.ChangeStartMode($startmode) endif if $svc.State <> $action select case $action = "START" $ = $svc.StartService() case $action = "STOP" $ = $svc.StopService() case $action = "PAUSE" $ = $svc.PauseService() case $action = "RESUME" $ = $svc.ResumeService() endselect endif next
$wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer") $services=$wmi.ExecQuery("Select * from Win32_Service where name = '$service'") for each $svc in $services $sm=$svc.StartMode $st=$svc.State $WMIService = "$st $sm" next $wmi=0 else exit 2 endif
endfunction
|
|
Top
|
|
|
|
#147498 - 2005-09-11 08:27 PM
Re: WMI Service state
|
RickB
Fresh Scripter
Registered: 2005-04-21
Posts: 11
Loc: Atlanta, Ga.
|
Code:
function netview(optional $domain) dim $array[255] dim $redim $redim = 255 dim $i $i = 0 dim $j $j = 0 dim $tempfile $tempfile = "%temp%\netview.tmp" if $domain $domain = "/domain:$domain" endif if exist("$tempfile") del "$tempfile" endif shell '%comspec% /c net view $domain >"$tempfile"' if @error = 0 if open(10,$tempfile) = 0 for $j = 1 to 5 $line = readline(10) ; skip headings next while @error = 0 $array[$i] = rtrim(substr($line,3,instr($line," ")-1)) $i=$i+1 if $i = $redim $redim=$redim*2 redim preserve $array[$redim] endif $line = readline(10) loop $=close(10) del "$tempfile" if $i redim preserve $array[$i-4] $netview = $array exit @error endif endif endif $netview = 0 exit @error endfunction
|
|
Top
|
|
|
|
#147499 - 2005-09-11 08:48 PM
Re: WMI Service state
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Between these two lines:
Code:
IF RedirectOutput($LogFile,1) = 0 for each $computer in NetView
put this
Code:
IF RedirectOutput($LogFile,1) = 0
$computers = NetView() ?"Count=" UBound($computers)
for each $computer in $computers
-Shawn
|
|
Top
|
|
|
|
#147501 - 2005-09-11 09:32 PM
Re: WMI Service state
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
ok, try this then - between these two lines:
Code:
for each $computer in NetView $xQuery = WMIService("SpntSvc","query","$computer")
put this:
Code:
for each $computer in NetView $computer = substr($computer,3) $xQuery = WMIService("SpntSvc","query","$computer")
This strips-off those double whack-whacks from the hostname ...
-Shawn
|
|
Top
|
|
|
|
#147502 - 2005-09-11 09:35 PM
Re: WMI Service state
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
plus, take off those double-quotes before the no-vars-in-string police haul your butt over ;0)
Code:
$xQuery = WMIService("SpntSvc","query",$computer)
|
|
Top
|
|
|
|
#147504 - 2005-09-11 11:48 PM
Re: WMI Service state
|
RickB
Fresh Scripter
Registered: 2005-04-21
Posts: 11
Loc: Atlanta, Ga.
|
oops "OUTPUT empty", the VAR quotes are gone and Admin Rights to all PC's. Could it be the "//" in the UDF, before $computer...
Quote:
$wmi=getobject("winmgmts:{impersonationlevel=impersonate}!//$computer")
Code:
$xQuery = WMIService("SpntSvc","query",$computer) $xMode = WMIService("SpntSvc","startmode",$computer)
Edited by RickB (2005-09-12 04:40 AM)
|
|
Top
|
|
|
|
#147505 - 2005-09-12 06:03 AM
Re: WMI Service state
|
RickB
Fresh Scripter
Registered: 2005-04-21
Posts: 11
Loc: Atlanta, Ga.
|
located another UDF for the Service status... "fnWMIService" Thanks for all the input!
Code:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=83246
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2870 anonymous users online.
|
|
|