Valnurat Posted April 12, 2016 Posted April 12, 2016 Hi, If I run this: RunWait(@ComSpec & " /c " & 'net stop ' & '"' & "Windows Management Instrumentation" &'"', "", @SW_SHOW) I get a question if it is ok to closed other services. I would like to send the letter "y" and the "Enter". How can this be done? Or is there another way to stop a service? Yours sincerely Kenneth.
Moderators JLogan3o13 Posted April 12, 2016 Moderators Posted April 12, 2016 @Valnurat you can use WMI to stop/start the service. I would suggest searching the forum for ScriptOMatic. Here is an example snippet you should be able to modify to your needs: #RequireAdmin #include <MsgBoxConstants.au3> $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $oServiceList = $oWMI.ExecQuery("Select * from Win32_Service where DisplayName='Windows Search'") For $sService in $oServiceList MsgBox($MB_OK, "", $sService.Name) $sService.StopService() Next "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Valnurat Posted April 12, 2016 Author Posted April 12, 2016 Thank you for the hint. I tried it, but the service will not stop. #RequireAdmin #include <MsgBoxConstants.au3> $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $oServiceList = $oWMI.ExecQuery("Select * from Win32_Service where DisplayName='Windows Management Instrumentation'") For $sService in $oServiceList ; MsgBox($MB_OK, "", $sService.Name) $sService.StopService() Next Yours sincerely Kenneth.
Moderators JLogan3o13 Posted April 12, 2016 Moderators Posted April 12, 2016 Eh, you're using WMI to stop WMI...let's think about that one for a second "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Valnurat Posted April 13, 2016 Author Posted April 13, 2016 I'm sorry for being stupid, but then I don't know how. Yours sincerely Kenneth.
Valnurat Posted April 13, 2016 Author Posted April 13, 2016 I found out I can do this: #RequireAdmin RunWait(@ComSpec & " /c " & 'net stop ' & '"' & "Windows Management Instrumentation" &'" /y', "", @SW_SHOW) Yours sincerely Kenneth.
Juvigy Posted April 13, 2016 Posted April 13, 2016 39 minutes ago, Valnurat said: I'm sorry for being stupid, but then I don't know how. What Logan means is that you tried to stop the WMI service in your example , using WMI . Try with WMI to stop another service and it should work.
Valnurat Posted April 13, 2016 Author Posted April 13, 2016 Yes, I get it now, but I need to stop WMI service so I can delete a folder that it used by SMS. Yours sincerely Kenneth.
Juvigy Posted April 13, 2016 Posted April 13, 2016 Are you sure WMI is responsible for locking the folder for deletion ? What is the full path ?
Valnurat Posted April 13, 2016 Author Posted April 13, 2016 If we have problems with SCCM we has a procedure to stop WMI. We can't delete C:\Windows\system32\wbem\Repository because it is locked. Services as "SMS Agent Host" are depending of WMI. I think SMS Agent Host is locking the folder we should delete. Yours sincerely Kenneth.
Juvigy Posted April 13, 2016 Posted April 13, 2016 Yes , this is a WMI folder. So you cant use the WMI to stop the service = stop it with the : #RequireAdmin RunWait(@ComSpec & " /c " & 'net stop ' & '"' & "Windows Management Instrumentation" &'" /y', "", @SW_SHOW)
AutoBert Posted April 13, 2016 Posted April 13, 2016 @Juvigy: 5 hours ago, Valnurat said: I found out I can do this: #RequireAdmin RunWait(@ComSpec & " /c " & 'net stop ' & '"' & "Windows Management Instrumentation" &'" /y', "", @SW_SHOW)
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