Jump to content

Stopping Services.


ame1011
 Share

Recommended Posts

Forgive the new post, the last one got lost into oblivion.

I am using the following code to Stop services. Something is wrong and I can't quite put my finger on it.

$service = "InCD Helper"
if ServiceExists($service) Then
   RunWait(@ComSpec & ' /c Net Stop ' & $service,'',@SW_HIDE)
   MsgBox(0,"","Closed  " & $service)
endif
Edited by ame1011
[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

ah, I see.

Quick question though. Aboutt he service exists function. How would I use it to check for existing services.

If ServiceExists($service) then
Endif

or

If ServiceExists($service) NOT @error then
Endif

or...

Also, is there a way to get a list of Services?

Edited by ame1011
[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

Your first is the right method in your previous post. The function is setup with not @error return so 0 For False or 1 for True.

If condition Then

InCD Helper has a space and Comspec does not like spaces, so you need double quotes to pass the full string as one.

E.g.

$service = '"InCD Helper"'
if ServiceExists($service) Then
   RunWait(@ComSpec & ' /c Net Stop ' & $service,'',@SW_HIDE)
   MsgBox(0,"","Closed  " & $service)
endif

Give that a try. Notice that the strings double quotes are wrapped with single quotes to preserve the double quotes.

Edit: You also want a list of services? Type sc query at a command prompt to see a list.

Thanks Valuater for adding the link. It made it easier for me to find the function related to this case.

Edited by MHz
Link to comment
Share on other sites

This is how I did it. Hope it helps somewhat:

$StopSvcCommandLine = 'net stop "Indexing Service"'

Call("StopSvc")

Func StopSvc()

RunWait(@ComSpec & " /c " & $StopSvcCommandLine,"C:\WINDOWS\system32",@SW_HIDE)

EndFunc

Just remember that if you use @SW_HIDE and you are stopping lots of services, make sure you stop the services in the correct sequence (ie. don't try to stop a parent service without stopping the child ones first or the program will end up hanging).

Link to comment
Share on other sites

i want you to die ... it should be StopSvc()

B)

Gimme a break, I've only been using AutoIt for 2 weeks. I didn't even know a function could be referenced like that. Besides, Call is in the Help File and that's how I'm learning AutoIt.

Programmatically, what's the difference between 'Call("Function")' and 'Function ()'?

Link to comment
Share on other sites

you should read the manual better

Language Reference - User Functions

A function is a section of code that can be called from the script to perform a certain "function". There are two sorts of functions in AutoIt, inbuilt functions and user functions.

Inbuilt Functions

The full list of inbuilt functions is here and the notes on using them are here.

User Functions

User functions are declared using the Func...EndFunc statements.

Functions can accept parameters and return values as required.

Function names must start with either a letter or an underscore, and the remainder of the name can contain any combination of letters and numbers and underscores. Some valid function names are:

MyFunc

Func1

_My_Func1

Here is an example of using a function to double a number 5 times:

$val = 10  
For $i = 1 To 10
     $doubled = MyDouble($val)
     MsgBox(0, "", $val & " doubled is " & $doubled)
     $val = $doubled
Next

Exit


Func MyDouble($value)
     $value = $value * 2
     Return $value
EndFunc

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

B)

Gimme a break, I've only been using AutoIt for 2 weeks. I didn't even know a function could be referenced like that. Besides, Call is in the Help File and that's how I'm learning AutoIt.

Programmatically, what's the difference between 'Call("Function")' and 'Function ()'?

  • Doubles the overhead required for a function lookup.
  • Functions taking parameters are not supported.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...