youtuber Posted January 13, 2023 Share Posted January 13, 2023 DPS Service can't get status to "Stopped" return value is always 1 #RequireAdmin If @OSVersion = "WIN_10" Then $sStatus = _CheckService("DPS") If $sStatus = 1 Then MsgBox(0, "", "Status1 : " & $sStatus) RunWait(@ComSpec & " /c " & 'net stop DPS', "", @SW_HIDE) MsgBox(0, "", "Status2 : " & $sStatus) RunWait(@ComSpec & " /c " & 'net start DPS', "", @SW_HIDE) Else RunWait(@ComSpec & " /c " & 'net start DPS', "", @SW_HIDE) EndIf EndIf Func _CheckService($s_ServiceName) Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_Service WHERE Name = "' & $s_ServiceName & '"') If Not IsObj($colItems) Then Exit MsgBox(0, "", "Not an object : DPS", 5) If Not $colItems.count Then Return 0 ; Service not found For $oItem In $colItems If $oItem.State = "Running" Then Return 1 If $oItem.State = "Stopped" Then Return 2 If $oItem.State = "Not Installed" Then Return 3 Next EndFunc ;==>_CheckService Link to comment Share on other sites More sharing options...
ioa747 Posted January 13, 2023 Share Posted January 13, 2023 (edited) Edition Windows 10 Pro Version 22H2 OS build 19045.2486 Status1=1 Status2=1 what does it mean? Edited January 13, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Danp2 Posted January 13, 2023 Share Posted January 13, 2023 You aren't retrieving the updated status following the "net stop DPS" command. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted January 13, 2023 Share Posted January 13, 2023 Have you tried to use the methods of the WMI object ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
youtuber Posted January 18, 2023 Author Share Posted January 18, 2023 I couldn't answer because of my busy work, now I tried again with different scenarios, my problem still continues. Stops the service after Script Ends. expandcollapse popup#RequireAdmin $oShell = ObjCreate("shell.application") If @OSVersion = "WIN_10" Then $sStatus = _CheckService("DPS") If $sStatus = 1 Then $oShell.ServiceStop("DPS", False) MsgBox(0, "$oShell.ServiceStop", $sStatus) ;or _StopService("DPS") MsgBox(0, "_StopService", $sStatus) ;or RunWait(@ComSpec & " /c " & 'net stop DPS', "", @SW_HIDE) MsgBox(0, "RunWait net stop", $sStatus) Else MsgBox(0, "", "Status 2 And 3" & $sStatus) RunWait(@ComSpec & " /c " & 'net start DPS', "", @SW_HIDE) EndIf EndIf Func _CheckService($CheckServiceServiceName) Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_Service WHERE Name = "' & $CheckServiceServiceName & '"') If Not IsObj($colItems) Then Exit MsgBox(0, "", "Not an object : DPS", 5) If Not $colItems.count Then Return 0 ; Service not found For $oItem In $colItems If $oItem.State = "Running" Then Return 1 If $oItem.State = "Stopped" Then Return 2 If $oItem.State = "Not Installed" Then Return 3 Next EndFunc Func _StopService($StopServiceName) Local $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Local $oServiceList = $oWMI.ExecQuery('SELECT * FROM Win32_Service WHERE Name = "' & $StopServiceName & '"') For $sService In $oServiceList $sService.StopService() Next EndFunc Link to comment Share on other sites More sharing options...
Danp2 Posted January 18, 2023 Share Posted January 18, 2023 @youtuberWhat part of the following did you not understand? 🤨 Quote You aren't retrieving the updated status following the "net stop DPS" command. FWIW, this simplified example works as I would expect -- #RequireAdmin $sStatus = _CheckService("DPS") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sStatus = ' & $sStatus & @CRLF & '>Error code: ' & @error & @CRLF) RunWait(@ComSpec & " /c " & 'net stop DPS') ; Recheck status <== This is the step you are missing $sStatus = _CheckService("DPS") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sStatus = ' & $sStatus & @CRLF & '>Error code: ' & @error & @CRLF) Func _CheckService($CheckServiceServiceName) Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_Service WHERE Name = "' & $CheckServiceServiceName & '"') If Not IsObj($colItems) Then Exit MsgBox(0, "", "Not an object : DPS", 5) If Not $colItems.count Then Return 0 ; Service not found For $oItem In $colItems If $oItem.State = "Running" Then Return 1 If $oItem.State = "Stopped" Then Return 2 If $oItem.State = "Not Installed" Then Return 3 If $oItem.State = "Stop Pending" Then Return 4 Next EndFunc youtuber 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
youtuber Posted January 18, 2023 Author Share Posted January 18, 2023 @Danp2 Thanks but... Earlier I have seen a code snippet that checks service status without recursively checking or checking from the loop. But I don't remember under which topic I found those codes. I guess it was something like this. Local Static $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE name = "' & $CheckServiceServiceName & '" and state = 'Running'") Link to comment Share on other sites More sharing options...
Danp2 Posted January 18, 2023 Share Posted January 18, 2023 @youtuberThat may be, but the code you posted previously isn't doing that. Thus the reason I mentioned that you need to retrieve the updated status. 🙂 Latest Webdriver UDF Release Webdriver Wiki FAQs 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