Jump to content

Changing How A Known Service Starts

Recommended Posts

Hi all

this is something that i was asked to include into a program i run to remove unnecessary statups

They want me to also turn the related services to start only when needed as well as the services are still running and taking resources.

Now i had a look here

And thought that would be a good start but it errors with Const errors for e.g.

C:\Users\J\Desktop\Services\Services.au3(59,37) : ERROR: $READ_CONTROL previously declared as a 'Const'.
Global Const $READ_CONTROL = 0x20000
C:\Users\J\Desktop\Services\Services.au3(60,34) : ERROR: $WRITE_DAC previously declared as a 'Const'.
Global Const $WRITE_DAC = 0x40000
C:\Users\J\Desktop\Services\Services.au3(61,36) : ERROR: $WRITE_OWNER previously declared as a 'Const'.
Global Const $WRITE_OWNER = 0x80000
C:\Users\J\Desktop\Services\Services.au3(66,25) : ERROR: $STANDARD_RIGHTS_REQUIRED previously declared as a 'Const'.
          $WRITE_OWNER )

I am only interested in changing a service and im trying with this

_Service_Change(  "AdobeARMservice", $SERVICE_NO_CHANGE, $SERVICE_DEMAND_START )

which if i read it right is AdobeARMservice, No change to service type, just change to demand start only

Any thoughts where im going wrong?

And or is there a simpler way to do this? as i will have more than one service to mod

Link to post
Share on other sites

If you look at post #63 in that thread you linked, it will tell you why you're getting the errors, and how to fix it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

Blow me down i sat and read a load of it but more near the start

Cheers BrewManNH good catch and it worked fine

One other question

Is this the easiest way to do this?

Link to post
Share on other sites

Is there any problem with using the good old sc.exe?

sc config "servicename" start= demand

Not come across that one, does it need run or runwait etc? to call it?

Link to post
Share on other sites

I prefer Shellexecute if no stdout or piping is needed

ShellExecuteWait('sc.exe', 'config "servicename" start= demand')

PS: ShellExecuteWait return 0 on success here

PS2: the space behind = is wanted

Edited by JFX
Link to post
Share on other sites

Thx for that JFX

Because i have more than item to change i decided to try and use an array.

I have this so far, it runs but it doesn't make any changes, anyone know why?

; =======================================================
Global $aPathKeys[3] = [2, "AdobeARMservice", "Nero BackItUp Scheduler 4.0"]
; =======================================================
For $g = 1 To $aPathKeys[0]
  If @OSVersion = "WIN_7" Then
   ShellExecuteWait('sc.exe', 'config $aPathKeys[$g] start= demand', "", "", @SW_HIDE)

Ive checked with _ArrayDisplay($aPathKeys) after the @OSVersion line and the array of 2 items definatly exists


Getting a little further with this

   ShellExecuteWait('sc.exe', 'config ' & $aPathKeys[$g] & ' start= demand', "", "", @SW_HIDE)

For some reason the _ArrayDisplay windows opens twice, is it not reading them into 1 array?

Only problem it changes the first entry of the array and leaves the second one unchanged, how do i get it to change both?

Edited by Chimaera
Link to post
Share on other sites

No wonder i get confused

How come the "" around the array items doesnt cover the ones you added?

Is it because in the sc params it has to exist within the line?

Its working now anyway thx for the pointers

Edited by Chimaera
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...