gcue Posted September 3, 2008 Posted September 3, 2008 i check a service on a local machine and depending on what the status is different actions occur. if the service is "pending start" it means that an ini file is corrupt, after replacing it i want to run the check again.. any ideas? expandcollapse popup$file = ("c:\temp\ns.txt") RunWait(@ComSpec & ' /c netsvc "client32" \\' & GUICtrlRead($asset) & ' /query >' & $file) $line = FileReadLine($file, 1) ;FileDelete($file) $ns = StringTrimLeft($line,11) $ns2 = StringTrimRight($ns,14) ;EndFunc MsgBox(0,"",$ns2) $errorcount = 0 If $ns2="pending start" Then Msgbox(0, "Netsupport Buddy", "Netsupport INI is corrupt on " & GUICtrlRead($asset) & @CRLF & _ "Will try to fix INI...") RunWait(@ComSpec & ' /c pskill.exe \\' & GUICtrlRead($asset) & ' client32.exe') FileCopy("cni.dll", "\\" & GUICtrlRead($asset) & "\c$\program files\netsupport manager\client32.ini", 1) RunWait(@ComSpec & ' /c netsvc.exe "client32" \\' & GUICtrlRead($asset) & ' /start') RunWait(@ComSpec & ' /c netsvc "client32" \\' & GUICtrlRead($asset) & ' /query >' & $file) $errorcount = +1 ;check EndIf If $ns2="stopped" Then Msgbox(0, "Netsupport Buddy", "Service is stopped on " & GUICtrlRead($asset)) RunWait(@ComSpec & ' /c netsvc "client32" \\' & GUICtrlRead($asset) & ' /start >' & $file) $line = FileReadLine($file, 1) FileDelete($file) If $line = "Error code 1058" Then MsgBox(0,"Netsupport Buddy", "Client32 service is disabled on " & GUICtrlRead($asset)) Return EndIf ;check ;if "error code 1058" then service is disabled - then msgbox service was disabled else if not error code the service is set to manual EndIf If $ns2="running" Then Msgbox(0, "Netsupport Buddy", "Service is running on " & GUICtrlRead($asset)) EndIf
Kerros Posted September 3, 2008 Posted September 3, 2008 I would use a loop with a function and a select statement... Something like this: expandcollapse popupLocal $state = '' While $state <> 'running' $file = ("c:\temp\ns.txt") RunWait(@ComSpec & ' /c netsvc "client32" \\' & GUICtrlRead($asset) & ' /query >' & $file) $line = FileReadLine($file, 1) ;FileDelete($file) $ns = StringTrimLeft($line,11) $ns2 = StringTrimRight($ns,14) ;EndFunc $state = States() Sleep(1000); give it some time to restart if needed WEnd Func States() Select Case $ns2="pending start" Msgbox(0, "Netsupport Buddy", "Netsupport INI is corrupt on " & GUICtrlRead($asset) & @CRLF & _ "Will try to fix INI...") RunWait(@ComSpec & ' /c pskill.exe \\' & GUICtrlRead($asset) & ' client32.exe') FileCopy("cni.dll", "\\" & GUICtrlRead($asset) & "\c$\program files\netsupport manager\client32.ini", 1) RunWait(@ComSpec & ' /c netsvc.exe "client32" \\' & GUICtrlRead($asset) & ' /start') RunWait(@ComSpec & ' /c netsvc "client32" \\' & GUICtrlRead($asset) & ' /query >' & $file) $errorcount = +1 Case $ns2="stopped" Msgbox(0, "Netsupport Buddy", "Service is stopped on " & GUICtrlRead($asset)) RunWait(@ComSpec & ' /c netsvc "client32" \\' & GUICtrlRead($asset) & ' /start >' & $file) $line = FileReadLine($file, 1) FileDelete($file) If $line = "Error code 1058" Then MsgBox(0,"Netsupport Buddy", "Client32 service is disabled on " & GUICtrlRead($asset)) ;Return <----- I'm not sure why this return was included as a function wasn't included in your sample code EndIf Case $ns2="running" Msgbox(0, "Netsupport Buddy", "Service is running on " & GUICtrlRead($asset)) EndSelect Return $ns2 EndFunc Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.
gcue Posted September 3, 2008 Author Posted September 3, 2008 looks like a good idea! ill try it - thanks =)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now