spudw2k Posted July 12, 2013 Share Posted July 12, 2013 (edited) This information isn't strictly related to AutoIt--in fact the script was the easiest part--but I just finished an exercise that I hadn't had to do before but others may find useful so I wanted to share my findings and results. At my place of work we have a "Desktop Admin" group which has admin privs on desktops (who da thunk) but not servers. Our print server has daily hangups and our resolution is to restart the print spooler service. We have a 24hr support model and only Desktop Admins are filling the night shifts. If the print server or queue gets hung, they are were not able to restart the service. We are unable to grant them login or admin privs on the server so I tried another route. I learned that a Discrentionary Access Control List (DACL) can be applied to individual services. In addition to the Print Spooler service, at least status permission needed to be granted to the Service Control Manager service (scmanager). I followed the following links for instructions to grant permissions to the SID of the Desktop Admin group. http://networkadminkb.com/KB/a159/how-to-troubleshoot-access-to-sc-manager-other-object-access.aspx Here is the simple script I put together for the Desktop Admins to run in order to restart the service. expandcollapse popupMain() Func Main() ;Main Function $server = "PAXPS01" ;Host with Spooler Service ProgressOn("Restart Print Spooler Service", "", "", -1, -1, 3) ;UI Feedback - Initialize If _IsSpoolerRunning($server) Then ;If Spooler Service is Running then Restart _RestartSpooler($server) ;Restart Spooler Service Routine Function ElseIf _IsSpoolerStopped($server) Then ;Else If Spooler Service is Stopped then Start _StartSpooler($server) ;Start Spooler Service Function EndIf ProgressSet(100, "", "Print Spooler Restarted Successfully.") ;UI Feedback - Completed MsgBox(0, "Restart Print Spooler", "Complete") ;Alert Feedback - Completion EndFunc ;==>Main Func _AccessDenied() ;Access Denied MsgBox(0, "Restart Print Spooler", "Access Denied") ;Alert Feedback - Access Denied Error Exit ;Abort Script EndFunc ;==>_AccessDenied Func _GetSTDOut($pid) ;Get StdOut from Console Executable by Process ID Local $output ;Stdout String Variable While 1 ;Do While PID is Running $output &= StdoutRead($pid) ;Capture Stdout from PID If @error Then ExitLoop ;Exit Loop if Error Occurs (PID Terminated or Non-Existing) WEnd Return $output ;Return Stdout Captured from PID EndFunc ;==>_GetSTDOut Func _IsSpoolerRunning($server) ;Determine if Spooler Service is Running Return StringInStr(_RunSCCommand($server, "query", "Spooler"), "RUNNING") EndFunc ;==>_IsSpoolerRunning Func _IsSpoolerStopped($server) ;Determine if Spooler Service is Stopped Return StringInStr(_RunSCCommand($server, "query", "Spooler"), "STOPPED") EndFunc ;==>_IsSpoolerStopped Func _RestartSpooler($server) ;Restart Spooler Service Routine Function _StopSpooler($server) ;Send Stop Command to Spooler Service Do ;Loop Until Spooler Service is Stopped Sleep(1000) Until _IsSpoolerStopped($server) _StartSpooler($server) ;Send Start Command to Spooler Service Do ;Loop Until Spooler Service is Running Sleep(1000) Until _IsSpoolerRunning($server) EndFunc ;==>_RestartSpooler Func _RunSCCommand($server, $cmd, $service) ;Execute Service Control Command & Return Stdout $stdOut = _GetSTDOut(Run(@ComSpec & " /c sc.exe \\" & $server & " " & $cmd & " " & $service, @ScriptDir, @SW_HIDE, 0x8)) If StringInStr($stdOut, "Access is Denied.") Then _AccessDenied() ;Check for Access Denied string in Stdout Return $stdOut ;Return Stdout from SC Command EndFunc ;==>_RunSCCommand Func _StartSpooler($server) ;Send Start command to Spooler Service ProgressSet(50, "", "Starting Print Spooler Service") ;Set UI Feedback State (Starting) _RunSCCommand($server, "start", "Spooler") EndFunc ;==>_StartSpooler Func _StopSpooler($server) ;Send Stop command to Spooler Service ProgressSet(0, "", "Stopping Print Spooler Service") ;Set UI Feedback State (Stopping) _RunSCCommand($server, "stop", "Spooler") EndFunc ;==>_StopSpooler Edited May 13 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF 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