Sign in to follow this  
Followers 0
ame1011

Stopping Services.

12 posts in this topic

#1 ·  Posted (edited)

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]

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

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]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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).

Share this post


Link to post
Share on other sites

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

Hah!

Share this post


Link to post
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 ()'?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Thanks Valik. Looks like I got a bit of re-coding to do B)

Share this post


Link to post
Share on other sites

Thank you W0uter for showing me the error of my ways B)

If Function() does a better job than Call ("Function"), is there a reason to still have Call as a function?

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
Sign in to follow this  
Followers 0