Jump to content
Valnurat

Stop a service require an answer

Recommended Posts

Valnurat

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
JLogan3o13

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

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
JLogan3o13

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
Valnurat

:>

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
Juvigy
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
Valnurat

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
Juvigy

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
Valnurat

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
Juvigy

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

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

    • DynamicRookie
      By DynamicRookie
      Hey there!
       
      Is there a way to detect movement only for 1 specific window?

      HWnd is not really working, it still detects movement in all the windows within the region

      This is my script:
       
      ;Checksum actual HotKeySet("{f2}", 'exit_') MsgBox(0, '', '0') Beep(500, 2000) $Hwnd = WinActive('') while 1 $Checksum = PixelChecksum(211, 650, 1094, 914, 1, $Hwnd) If PixelChecksum(211, 650, 1094, 914, 1, $Hwnd) <> $Checksum Then For $i = 1 To 100 Beep(1000, 50) Next MsgBox(0, '', 'New message!', 1) EndIf WEnd Func exit_() Beep(500, 1000) Exit 0 EndFunc I just want to check whenever a message comes because the app i use doesn't give notifications properly.

      Any help is really appreciated!
    • PramodR
      By PramodR
      Can you please see whats wrong im doing in the below code? i can read few registry entry but not all for eg, i am able to get value of "Shell" Key from the registry path  but not AutoAdminLogon which has the value of "1", is there any change i have to do to read numeric values?
       Global  $shello = RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","Shell" )
       ConsoleWrite("This is Hello"& $shello)
      above command returns proper value , but same command with AutoAdminLogon returns null as shown in below ? infact registry has the value of 1.
       Global  $shello = RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AutoAdminLogon" )
       ConsoleWrite("This is Hello"& $shello)
    • Eminence
      By Eminence
      Hello,
      I've been searching on how to select the first row in my database which includes a time column based on the latest start_time date for today's date.
      This is my current code:
      Local $iCurrentDate = _Now() Local $sqlHandle = _dbOpen($sDbPath) Local $aResult, $iRows, $iCols _SQLite_GetTable2d($sqlHandle, "SELECT start_time FROM " & $srawDb & " ORDER BY datetime(start_time) DESC LIMIT 1", $aResult, $iRows, $iCols) _ArrayDisplay($aResult) _dbClose($sDbpath) What it does is it gets the first row entry in the database however it does not select the latest start_time entry in the database, it always select the first row. I've tried changing DESC to ASC to see if that will do it but the issue still remains. Any thoughts on this? Thanks in advance.
       
      *EDIT
      The date format in the database is by MM/DD/YYYY HH:MM:SS.
    • Trisha
      By Trisha
      Hello,
      I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
      FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
    • TrashBoat
      By TrashBoat
      hey i would like to know if its possible to take a string like this
      $string = "onethousandninehundredeightyfive" and convert it into:
      $string = "one thousand nine hundred eighty five" i have something going on here but its no use
      $string = "onethousandninehundredeightyfive" Global $array[9] = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] Global $array1[19] = ['onethousand', 'twothousand', 'threethousand', 'fourthousand', 'fivethousand', 'sixthousand', 'seventhousand', 'eightthousand', 'ninethousand','tenthousand','hundred', 'twohundred', 'threehundred', 'fourhundred', 'fivehundred', 'sixhundred', 'sevenhundred', 'eighthundred', 'ninehundred'] MsgBox(0, 0, AddSpaces($string)) Func AddSpaces($string) Local $finalStr $length = StringLen($string) For $x = 0 To $length Local $trim = StringTrimRight($string, $x) For $h = 0 To 18 If $trim = $array1[$h] Then $finalStr = $finalStr & " " & $trim $string = StringTrimLeft($string, $h) $length = StringLen($string) EndIf Next For $z = 0 To 8 If $trim = $array[$z] Then $finalStr = $finalStr & " " & $trim $string = StringTrimLeft($string, $z) $length = StringLen($string) EndIf Next Next Return $finalStr EndFunc ;==>AddSpaces  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.