Valnurat

Stop a service require an answer

12 posts in this topic

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.

Share this post


Link to post
Share on other sites

@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

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Eh, you're using WMI to stop WMI...let's think about that one for a second :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

:>

I'm sorry for being stupid, but then I don't know how.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

I found out I can do this:

#RequireAdmin
RunWait(@ComSpec & " /c " & 'net stop ' & '"' & "Windows Management Instrumentation" &'" /y', "", @SW_SHOW)

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Are you sure WMI is responsible for locking the folder for deletion ? What is the full path ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

@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)

 

 

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

  • Similar Content

    • Trisha
      By Trisha
      I tried (using AutoIt) to automate a scenario where i  have to open IE with specific URL on my extranet(Xen Desktop or Citrix ) ,from there i need to download  file and then through WinSCP; I  have to move that file to another location that can be access from my Local system using VMWare.
      I did as far as the above step. Now i want to navigate from my extranet to my local desktop system. But i am not able to move  from there.Mouse click is also not working.Please find the below screenshot highlighted in YELLOW.
       


    • bbk4163
      By bbk4163
      Hi, 
      I am getting "array variable has incorrect number of subscripts dimension range exceeded" error while executing exe. Not sure what is wrong here. 
      #include <MsgBoxConstants.au3> SelectWindowBasedOnTitle() Func SelectWindowBasedOnTitle()     $winList = WinList()     $wTitle = CheckWindows($winList)    IF $wTitle == "Choose File to Upload" Then             IE()    ElseIf $wTitle == "Open" Then             Chrome()    Else             FireFox()    EndIf EndFunc Func CheckWindows($aArray)     For $i = 1 To Ubound($aArray) - 1         If WinActive($aArray[$i][1]) Then $wTitle= $aArray[$i][0] ;MsgBox(0, "Window Check", $aArray[$i][0] & " is active.")     Next     Return $wTitle EndFunc Func Example()     $wText = WinGetText("[ACTIVE]") EndFunc Func IE()     ControlFocus("Choose File to Upload","","Edit1")     ControlSetText("Choose File to Upload","","Edit1",$CmdLine[1])     ControlClick("Choose File to Upload","","Button1") EndFunc Func Chrome()     ControlFocus("Open","","Edit1")     ControlSetText("Open","","Edit1",$CmdLine[1])     ControlClick("Open","","Button1") EndFunc Func FireFox()     ControlFocus("File Upload","","Edit1")     ControlSetText("File Upload","","Edit1",$CmdLine[1])     ControlClick("File Upload","","Button1") EndFunc  
    • TheWizEd
      By TheWizEd
      How do I work with 2D arrays.  I've tried this but get errors.
      Local $aTest[4][4] = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
      ;$aTest[0][] = [10,11,12]  ; Error at []
      Local $sTest = ""
      For $i = 0 To UBound($aTest)-1
        Local $aExtract = _ArrayExtract($aTest,$i,$i)
        $sTest = $sTest & MyTest($aExtract)
      Next
      Func MyTest($aTemp)
        _ArrayDisplay($aTemp)
        ; Error at    v $aTemp
        Return String($aTemp[0]) & " - " & String($aTemp[1]) & " - " & String($aTemp[2]) & @CRLF
      EndFunc
       
       
    • Valnurat
      By Valnurat
      Hi.
      If I use this code:
       
      #include <IE.au3> #include <MsgBoxConstants.au3> Local $sServiceTAG = "9S1Y3J2" Local $oIE = _IECreate("http://www.dell.com/support/home/uk/en/ukbsdt1/product-support/servicetag/" & $sServiceTAG & "/warranty?ref=captchasuccess",Default,0,0) _IELoadWait($oIE) Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If StringStripWS($oTd.innertext, 7) = "NBD ProSupport" Then $sShipdate = StringStripWS($oTd.NextElementSibling.InnerText, 7) ExitLoop EndIf Next _IEQuit($oIE) MsgBox($MB_SYSTEMMODAL, "Warranty", $sShipdate) My messagebox is empty, but if I use the link first:
      http://www.dell.com/support/home/uk/en/ukbsdt1/product-support/servicetag/9S1Y3J2/warranty?ref=captchasuccess
      and then use my code I get results.
      Can someone help so I don't need to use the link first.
    • Valnurat
      By Valnurat
      Hi.
      I have this:
      november 08, 2015
      How can I convert it to:
      08/03/2015
      I don't see any convert option from month name to a number.
      Thank  you