Sign in to follow this  
Followers 0
Diana (Cda)

Restart printer spooler?

4 posts in this topic

I searched the forum and came up with a starting point which I was able to finetune to get the following script which starts up services.msc:

RunWait(@ComSpec & ' /c start services.msc', '', @SW_MAXIMIZE)
WinWait($windowTitle)
WinSetState($windowTitle, "", @SW_MAXIMIZE)

Is there any means by which AI can just restart the print spooler altogether so that the entire process is automated? I must be missing vocabulary again because I haven't been able to find anything via searching the forum or the help files that I have.

Thanks.

Share this post


Link to post
Share on other sites



It should be much easier to do directly rather than automating the Services GUI. Take a look here.

http://www.autoitscript.com/forum/index.php?showtopic=5388&st=0&p=35572&hl=service&fromsearch=1&#entry35572


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

It should be much easier to do directly rather than automating the Services GUI. Take a look here.

http://www.autoitscript.com/forum/index.php?showtopic=5388&st=0&p=35572&hl=service&fromsearch=1&#entry35572

This appears to work.

Global $STANDARD_RIGHTS_REQUIRED = 0x000F0000
Global $SC_MANAGER_CONNECT = 0x0001
Global $SC_MANAGER_CREATE_SERVICE = 0x0002
Global $SC_MANAGER_ENUMERATE_SERVICE = 0x0004
Global $SC_MANAGER_LOCK = 0x0008
Global $SC_MANAGER_QUERY_LOCK_STATUS = 0x0010
Global $SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020

Global $SC_MANAGER_ALL_ACCESS = BitOR($STANDARD_RIGHTS_REQUIRED, _
$SC_MANAGER_CONNECT, _
$SC_MANAGER_CREATE_SERVICE, _
$SC_MANAGER_ENUMERATE_SERVICE, _
$SC_MANAGER_LOCK, _
$SC_MANAGER_QUERY_LOCK_STATUS, _
$SC_MANAGER_MODIFY_BOOT_CONFIG)

Global $SERVICE_QUERY_CONFIG = 0x0001
Global $SERVICE_CHANGE_CONFIG = 0x0002
Global $SERVICE_QUERY_STATUS = 0x0004
Global $SERVICE_ENUMERATE_DEPENDENTS = 0x0008
Global $SERVICE_START = 0x0010
Global $SERVICE_STOP = 0x0020
Global $SERVICE_PAUSE_CONTINUE = 0x0040
Global $SERVICE_INTERROGATE = 0x0080
Global $SERVICE_USER_DEFINED_CONTROL = 0x0100

Global $SERVICE_ALL_ACCESS = BitOR($STANDARD_RIGHTS_REQUIRED, _
$SERVICE_QUERY_CONFIG, _
$SERVICE_CHANGE_CONFIG, _
$SERVICE_QUERY_STATUS, _
$SERVICE_ENUMERATE_DEPENDENTS, _
$SERVICE_START, _
$SERVICE_STOP, _
$SERVICE_PAUSE_CONTINUE, _
$SERVICE_INTERROGATE, _
$SERVICE_USER_DEFINED_CONTROL)

Global $SERVICE_CONTROL_STOP = 0x00000001
Global $SERVICE_CONTROL_INTERROGATE = 0x00000004

#RequireAdmin
_StopService("Spooler")
Sleep(500)
_StartService("Spooler")

;===============================================================================
;
; Description: Starts a service
; Syntax: _StartService($sServiceName)
; Parameter(s): $sServiceName - Name of service to start
; Requirement(s): None
; Return Value(s): On Success - Sets @error = 0
; On Failure - Sets:
; @error = 1056: Already running
; @error = 1060: Service does not exist
; Author(s): SumTingWong
; Documented by: Misja
;
;===============================================================================
Func _StartService($sServiceName)
Local $arRet
Local $hSC
Local $hService
Local $lError = -1

$arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
"str", "", _
"str", "ServicesActive", _
"long", $SC_MANAGER_CONNECT)
If $arRet[0] = 0 Then
$arRet = DllCall("kernel32.dll", "long", "GetLastError")
$lError = $arRet[0]
Else
$hSC = $arRet[0]
$arRet = DllCall("advapi32.dll", "long", "OpenService", _
"long", $hSC, _
"str", $sServiceName, _
"long", $SERVICE_START)
If $arRet[0] = 0 Then
$arRet = DllCall("kernel32.dll", "long", "GetLastError")
$lError = $arRet[0]
Else
$hService = $arRet[0]
$arRet = DllCall("advapi32.dll", "int", "StartService", _
"long", $hService, _
"long", 0, _
"str", "")
If $arRet[0] = 0 Then
$arRet = DllCall("kernel32.dll", "long", "GetLastError")
$lError = $arRet[0]
EndIf
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)
EndIf
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
EndIf
If $lError <> -1 Then SetError($lError)
EndFunc


;===============================================================================
;
; Description: Stops a service
; Syntax: _StopService($sServiceName)
; Parameter(s): $sServiceName - Name of service to stop
; Requirement(s): None
; Return Value(s): On Success - Sets:
; @error = 0
; On Failure - Sets:
; @error = 1062: Already stopped
; @error = 1060: Service does not exist
; Author(s): SumTingWong
; Documented by: Misja
;
;===============================================================================
Func _StopService($sServiceName)
Local $arRet
Local $hSC
Local $hService
Local $lError = -1

$arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
"str", "", _
"str", "ServicesActive", _
"long", $SC_MANAGER_CONNECT)
If $arRet[0] = 0 Then
$arRet = DllCall("kernel32.dll", "long", "GetLastError")
$lError = $arRet[0]
Else
$hSC = $arRet[0]
$arRet = DllCall("advapi32.dll", "long", "OpenService", _
"long", $hSC, _
"str", $sServiceName, _
"long", $SERVICE_STOP)
If $arRet[0] = 0 Then
$arRet = DllCall("kernel32.dll", "long", "GetLastError")
$lError = $arRet[0]
Else
$hService = $arRet[0]
$arRet = DllCall("advapi32.dll", "int", "ControlService", _
"long", $hService, _
"long", $SERVICE_CONTROL_STOP, _
"str", "")
If $arRet[0] = 0 Then
$arRet = DllCall("kernel32.dll", "long", "GetLastError")
$lError = $arRet[0]
EndIf
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)
EndIf
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
EndIf
If $lError <> -1 Then SetError($lError)
EndFunc

;===============================================================================
;
; Description: Checks to see if a service is installed
; Syntax: _ServiceExists($sServiceName)
; Parameter(s): $sServiceName - Name of service to check
; Requirement(s): None
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; Author(s): SumTingWong
; Documented by: Misja
;
;===============================================================================
Func _ServiceExists($sServiceName)
Local $arRet
Local $hSC
Local $bExist = 0

$arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
"str", "", _
"str", "ServicesActive", _
"long", $SC_MANAGER_CONNECT)
If $arRet[0] <> 0 Then
$hSC = $arRet[0]
$arRet = DllCall("advapi32.dll", "long", "OpenService", _
"long", $hSC, _
"str", $sServiceName, _
"long", $SERVICE_INTERROGATE)
If $arRet[0] <> 0 Then
$bExist = 1
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $arRet[0])
EndIf
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
EndIf
Return $bExist
EndFunc

;===============================================================================
;
; Description: Checks to see if a service is running
; Syntax: _ServiceRunning($sServiceName)
; Parameter(s): $sServiceName - Name of service to check
; Requirement(s): None
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; Author(s): SumTingWong
; Documented by: Misja
;
;===============================================================================
Func _ServiceRunning($sServiceName)
Local $arRet
Local $hSC
Local $hService
Local $bRunning = 0

$arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
"str", "", _
"str", "ServicesActive", _
"long", $SC_MANAGER_CONNECT)
If $arRet[0] <> 0 Then
$hSC = $arRet[0]
$arRet = DllCall("advapi32.dll", "long", "OpenService", _
"long", $hSC, _
"str", $sServiceName, _
"long", $SERVICE_INTERROGATE)
If $arRet[0] <> 0 Then
$hService = $arRet[0]
$arRet = DllCall("advapi32.dll", "int", "ControlService", _
"long", $hService, _
"long", $SERVICE_CONTROL_INTERROGATE, _
"str", "")
$bRunning = $arRet[0]
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)
EndIf
DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
EndIf
Return $bRunning
EndFunc

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0