RichE Posted July 7, 2011 Share Posted July 7, 2011 Hi all, Now I know that AutoIT isn't multithreaded per say, but could this idea work..? I've wrote a script to connect to workstations (from an exported list) and restart 3 services wait for stopped state and then restart them, and wait for running state and move onto the next, would it be possible to run say 3 side by side just to speed things up a bit as it takes 2 mins to stop one service and 40secs to restart it so if you've quite a few workstations in the list it takes quite a while. just tell me if I'm barking up the wrong tree with my thinking. expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.5.6 (beta) Author: Richard Easton Script Function: RM Service Host restarted. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <string.au3> #include <IE.au3> _IEErrorHandlerRegister() $errors = 0 $error_log = @ScriptDir & "\Error_logs\" DirCreate($error_log) GUICreate("RM Service Host Restarter v2", 700, 500, -1, -1) GUICtrlCreateTab(5, 5, 695, 450) GUICtrlCreateTabItem("RM Service Host") GUICtrlCreateGroup("Target Details", 15, 30, 417, 45) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") ;individual workstation ;multiple workstations GUICtrlCreateLabel("Workstation List", 20, 48, 96, 17) $Workstation_List = GUICtrlCreateInput("Workstation_List", 112, 44, 273, 21) $wlist = GUICtrlCreateButton("...", 392, 42, 25, 23, $WS_GROUP) ;progress stuff GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("Progress", 15, 75, 417, 65) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") ;infor labels GUICtrlCreateLabel("Current Location:", 20, 91, 121, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $lblCL = GUICtrlCreateLabel("None Selected", 122, 91, 100, 17) GUICtrlCreateLabel("Workstation:", 240, 91, 121, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $lblCW = GUICtrlCreateLabel("None Selected", 315, 91, 80, 17) GUICtrlCreateLabel("Workstation: ", 20, 115, 72, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $currentnumber = GUICtrlCreateLabel("0", 94, 115, 30, 17) GUICtrlCreateLabel("of", 129, 115, 15, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $oftotal = GUICtrlCreateLabel("0", 152, 115, 30, 17) ;admin credentials GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("Credential", 15, 140, 417, 95) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlCreateLabel("Username:", 20, 160, 80, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $admin = GUICtrlCreateInput(@UserName, 112, 156, 273, 21) GUICtrlCreateLabel("Password:", 20, 182, 80, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $pass = GUICtrlCreateInput("", 112, 178, 273, 21, $ES_PASSWORD) GUICtrlCreateLabel("Domain:", 20, 205, 80, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Domain = GUICtrlCreateInput("", 112, 201, 273, 21) GUICtrlCreateGroup("Process Info", 15, 262, 675, 183) $processInfo = GUICtrlCreateList("", 20, 278, 665, 158, BitOR($WS_BORDER, $WS_VSCROLL)) GUICtrlSetFont(-1, 8, 100, 0, "verdana") GUICtrlSetColor($processInfo, 0xefefef) GUICtrlSetBkColor($processInfo, 0x0a0a0a) GUICtrlCreateGroup("Errors Info", 440, 30, 250, 235) $errorinfo = GUICtrlCreateList("", 450, 45, 230, 213, BitOR($WS_BORDER, $WS_VSCROLL)) GUICtrlSetFont(-1, 6, 100, 0, "verdana") GUICtrlSetColor($errorinfo, 0xff0000) GUICtrlSetBkColor($errorinfo, 0x0a0a0a) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateLabel("Restart Errors: ", 20, 242, 98, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $error_count = GUICtrlCreateLabel($errors, 119, 243, 50, 17) $elogs = GUICtrlCreateButton("Error Logs", 331, 238, 100, 25) $go = GUICtrlCreateButton("Process", 15, 460, 153, 25, $WS_GROUP) $exit = GUICtrlCreateButton("Exit", 530, 460, 161, 25, $WS_GROUP) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $exit MsgBox(64, "Thank you", "Thanks for using RM Service Host Restarter, written by Richard Easton 2011.", 5) Exit Case $elogs ShellExecute("explorer.exe", "", $error_log) Case $go If GUICtrlRead($Workstation_List) = "" Or GUICtrlRead($Workstation_List) = "Workstation_List" Or GUICtrlRead($admin) = "" Or GUICtrlRead($pass) = "" Or GUICtrlRead($Domain) = "" Then MsgBox(48, "Warning!", "No .CSV file selected or one of the credentials are missing!", 10) Else $path = GUICtrlRead($Workstation_List) $line_count = _FileCountLines($path) For $l = 2 To $line_count $input = FileReadLine($path, $l) $data = StringSplit($input, ",") $var = Ping($data[1], 500) If $var Then GUICtrlSetData($processInfo, "Process started on " & $data[1], "") GUICtrlSetData($processInfo, "======================================", $processInfo) GUICtrlSetData($lblCW, $data[1], "") GUICtrlSetData($currentnumber, $l - 1, "") If @error Then ExitLoop ;WMI Method. $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator") If Not IsObj($objSWbemLocator) Then EndIf $objSWbemServices = $objSWbemLocator.ConnectServer($data[1], "root\cimv2", GUICtrlRead($Domain) & "\" & GUICtrlRead($admin), GUICtrlRead($pass)) If Not IsObj($objSWbemServices) Then EndIf $objSWbemServices.Security_.ImpersonationLevel = 3 $RMSHItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name ='RM Service Host'") If IsObj($RMSHItems) Then For $objItem In $RMSHItems ;is service host running..? If $objItem.State() = "Running" Then GUICtrlSetData($processInfo, "stopping " & $objItem.name & " on " & $data[1], $processInfo) ;Stop RM Service Host. $RMSHErrors = $objItem.StopService() ;do RM Service host have it's dependancies running If $RMSHErrors = 3 Then GUICtrlSetData($processInfo, "Dependecies running on " & $data[1], $processInfo) GUICtrlSetData($processInfo, "Stopping Dependecies on " & $data[1], $processInfo) ;stop dependancies (start code here) ; RMtutorll code start . $rmtItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name = 'RMTutorll'") If IsObj($rmtItems) Then For $objItem In $rmtItems If $objItem.State() = "Running" Then $err_return = $objItem.StopService("RMTutorll") $t = 1 Do ;check state of service $rmtItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name = 'RMTutorll'") For $objItem In $rmtItems $state = $objItem.state("RMTutorll") ConsoleWrite("Waited " & $t & " secs " & $objItem.name & " is " & $state) $t = $t + 1 Sleep(1000) Next Until $state = "Stopped" ConsoleWrite($objItem.name & " is " & $state) GUICtrlSetData($processInfo, $objItem.name & " has entered a " & $objItem.State() & " State", $processInfo) Else GUICtrlSetData($processInfo, $objItem.name & " is already in a " & $objItem.State() & " State", $processInfo) EndIf Next EndIf ;rmtutorll code stop. ; RM Desktop Agent code start . $dasItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name = 'DAService'") If IsObj($dasItems) Then For $objItem In $dasItems If $objItem.State() = "Running" Then $err_return = $objItem.StopService("DAService") $t = 1 Do ;check state of service $dasItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name = 'DAService'") For $objItem In $dasItems $state = $objItem.state("DAService") ConsoleWrite("Waited " & $t & " secs " & $objItem.name & " is " & $state) $t = $t + 1 Sleep(1000) Next Until $state = "Stopped" ConsoleWrite($objItem.name & " is " & $state) GUICtrlSetData($processInfo, $objItem.name & " has entered a " & $objItem.State() & " State", $processInfo) Else GUICtrlSetData($processInfo, $objItem.name & " is already in a " & $objItem.State() & " State", $processInfo) EndIf Next EndIf ;RM Desktop Agent code stop. ;stop dependancies (stop code here) ;Try and stop RM Service Host again. $RMSHItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name ='RM Service Host'") If IsObj($RMSHItems) Then For $objItem In $RMSHItems ;is service host running..? If $objItem.State() = "Running" Then GUICtrlSetData($processInfo, "retrying to stop " & $objItem.name & " on " & $data[1], $processInfo) ;Stop RM Service Host. $RMSHErrors = $objItem.StopService("RM Service Host") $t = 1 Do ;check state of service $RMSHItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name ='RM Service Host'") For $objItem In $RMSHItems $state = $objItem.state("RM Service Host") ConsoleWrite("Waited " & $t & " secs " & $objItem.name & " is " & $state) $t = $t + 1 Sleep(1000) Next Until $state = "Stopped" ConsoleWrite($objItem.name & " is " & $state) GUICtrlSetData($processInfo, $objItem.name & " has entered a " & $objItem.State() & " State", $processInfo) Else ConsoleWrite($objItem.name & " is " & $state) GUICtrlSetData($processInfo, $objItem.name & " has entered a " & $objItem.State() & " State", $processInfo) EndIf Next EndIf Else $t = 1 Do ;check state of service $RMSHItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name ='RM Service Host'") For $objItem In $RMSHItems $state = $objItem.state ConsoleWrite("Waited " & $t & " secs " & $objItem.name & " is " & $state) $t = $t + 1 Sleep(1000) Next Until $state = "Stopped" ConsoleWrite($objItem.name & " is " & $state) GUICtrlSetData($processInfo, $objItem.name & " has entered a " & $objItem.State() & " State", $processInfo) EndIf Else ;RM Service Host is Already Stopped. GUICtrlSetData($processInfo, $objItem.name & " is in a " & $objItem.State() & " State", $processInfo) EndIf ;double check SH has stopped and restart it. If $objItem.state = "Stopped" Then GUICtrlSetData($processInfo, "Restarting " & $objItem.name & " on " & $data[1], $processInfo) $objItem.StartService() $t = 1 Do ;check state of service $RMSHItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name ='RM Service Host'") For $objItem In $RMSHItems $state = $objItem.state("RM Service Host") ConsoleWrite("Waited " & $t & " secs " & $objItem.name & " is " & $state) $t = $t + 1 Sleep(1000) Next Until $state = "Running" Or $state = "Started" ConsoleWrite($objItem.name & " is " & $state) GUICtrlSetData($processInfo, $objItem.name & " Restarted ok.", $processInfo) EndIf ;Service Host end code ;restart dependant services ; RMtutorll code start . $rmtItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name = 'RMTutorll'") If IsObj($rmtItems) Then For $objItem In $rmtItems If $objItem.State() = "Stopped" Then $err_return = $objItem.StartService("RMTutorll") $t = 1 Do ;check state of service $rmtItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name = 'RMTutorll'") For $objItem In $rmtItems $state = $objItem.state("RMTutorll") ConsoleWrite("Waited " & $t & " secs " & $objItem.name & " is " & $state) $t = $t + 1 Sleep(1000) Next Until $state = "Running" Or $state = "Started" ConsoleWrite($objItem.name & " is " & $state) GUICtrlSetData($processInfo, $objItem.name & " Restarted ok.", $processInfo) EndIf Next EndIf ;rmtutorll code stop. ;restart RM Desktop Agent. $DAItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name = 'DAService'") If IsObj($DAItems) Then For $objItem In $DAItems If $objItem.State() = "Stopped" Then $err_return = $objItem.StartService("DAService") $t = 1 Do ;check state of service $DAItems = $objSWbemServices.ExecQuery("select * from Win32_Service Where Name = 'DAService'") For $objItem In $DAItems $state = $objItem.state("DAService") ConsoleWrite("Waited " & $t & " secs " & $objItem.name & " is " & $state) $t = $t + 1 Sleep(1000) Next Until $state = "Running" Or $state = "Started" ConsoleWrite($objItem.name & " is " & $state) GUICtrlSetData($processInfo, $objItem.name & " Restarted ok.", $processInfo) GUICtrlSetData($processInfo, "Process Completed on " & $data[1], $processInfo) Sleep(300) GUICtrlSetData($processInfo, "", "") EndIf Next EndIf Next EndIf Else $errors = $errors + 1 GUICtrlSetData($error_count, $errors, "") _FileWriteLog($error_log & "\Servicehost.log", $data[1] & " is not responding to a ping request") GUICtrlSetData($errorinfo, $data[1] & " is not responding to a ping request", $errorinfo) EndIf Next EndIf ;alert user if there are errors If $error_count > 0 Then _FileWriteLog($error_log & "\Servicehost.log", "Completed with errors, error logs are located in the " & $error_log & " directory") MsgBox(48, "Profile Remover", "Completed with errors, error logs are located in the " & $error_log & " directory") Else _FileWriteLog($error_log & "\Servicehost.log", "Completed Successfully") MsgBox(48, "Profile Remover", "Completed Successfully") EndIf Case $wlist $list = FileOpenDialog("Select CSV list of workstations", @ScriptDir, "CSV (*.csv)", 1 + 2) GUICtrlSetData($Workstation_List, $list, "") $line_count = _FileCountLines($list) GUICtrlSetData($oftotal, $line_count - 1, "") EndSwitch WEnd Regards RichE RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
MvGulik Posted July 7, 2011 Share Posted July 7, 2011 Why would you need it as a separated exe-process?(think its possible, but fail to see the underlying need.)I mean, if you don't (have to) wait for this "restart 3 services wait for stopped state and then restart them" process to fully finish per server. You can/could speed things up by using/keeping a data-log of the state that a workstation is in*1, that way you could do them virtually all at the same time from one exe-process.... Or I'm I missing something? ...*1) in relation to your target "restart 3 services wait for stopped state and then restart them" process. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
RichE Posted July 7, 2011 Author Share Posted July 7, 2011 Why would you need it as a separated exe-process?(think its possible, but fail to see the underlying need.)I mean, if you don't (have to) wait for this "restart 3 services wait for stopped state and then restart them" process to fully finish per server. You can/could speed things up by using/keeping a data-log of the state that a workstation is in*1, that way you could do them virtually all at the same time from one exe-process.... Or I'm I missing something? ...*1) in relation to your target "restart 3 services wait for stopped state and then restart them" process.you hit the nail write on the head, I would like to run the all at the same time, using a datalog maybe the way ahead RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
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