7 Replies - 1229 Views - Last Post: 11 May 2010 - 02:48 PM Rate Topic: -----

#1 blank_program   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 292
  • Joined: 22-July 09

Seeking advice for best way to do this

Posted 10 May 2010 - 04:43 PM

What I am plannign to do is make a program thatw ill read services from a text file and disable and stop them. However I am not sure whatt he best way to read them would be.

I would have one name service name per line in a text file and I would separate I think with a comma then possibly semicolon for end line.
So it could look like:
Adaptive Brightness,Disabled;
Windows Update,Manual;
etc...



However I would need sections for XP, Vista/7 so I would use headers.

And should I embed the text file?

I am NOT looking for code. Just advice.

This post has been edited by blank_program: 10 May 2010 - 04:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Seeking advice for best way to do this

#2 demausdauth   User is offline

  • D.I.C Addict
  • member icon

Reputation: 190
  • View blog
  • Posts: 692
  • Joined: 03-February 10

Re: Seeking advice for best way to do this

Posted 11 May 2010 - 05:57 AM

Why not consider application or user settings?
Was This Post Helpful? 1
  • +
  • -

#3 blank_program   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 292
  • Joined: 22-July 09

Re: Seeking advice for best way to do this

Posted 11 May 2010 - 08:19 AM

It would have nothing to do with my program. My program is there to automate the process of changing alot of the Windows services.

Also, I couldn't seem to find anything via Google on changing the startup type of the service programmatically. Any advice?
Was This Post Helpful? 0
  • +
  • -

#4 demausdauth   User is offline

  • D.I.C Addict
  • member icon

Reputation: 190
  • View blog
  • Posts: 692
  • Joined: 03-February 10

Re: Seeking advice for best way to do this

Posted 11 May 2010 - 08:53 AM

If I understand correctly, your file read is basically an ini file, sorta. Anyways, in that case I think I might go with an xml file.

<SettingFile>
    <OSType type="XP">
        <GroupingLevel>
            <Setting key="Adaptive Brightness" value="Enabled" /> 
            <Setting key="Windows Update" value="Manual" />
        </GroupingLevel>    
    </OSType>
    <OSType type="Vista">
        <GroupingLevel>
            <Setting key="Adaptive Brightness" value="Enabled" /> 
            <Setting key="Windows Update" value="Manual" />
        </GroupingLevel>
    </OSType>
</SettingFile>


As to programmatically changing the startup type of a service, I found quite a few articles and code addressing the issue with local and remote systems.

Try Here

or

Here
Was This Post Helpful? 0
  • +
  • -

#5 blank_program   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 292
  • Joined: 22-July 09

Re: Seeking advice for best way to do this

Posted 11 May 2010 - 01:35 PM

I checked on Google and really didn't find any good way that was understandable for service type.
Was This Post Helpful? 0
  • +
  • -

#6 MentalFloss   User is offline

  • .
  • member icon

Reputation: 613
  • View blog
  • Posts: 1,581
  • Joined: 02-September 09

Re: Seeking advice for best way to do this

Posted 11 May 2010 - 02:06 PM

http://msdn.microsof...controller.aspx

You create a service controller by passing in the name of the service you want to manipulate (this string would be stored in your configuration file).

Then you manipulate it:

http://msdn.microsof...er_methods.aspx

You want to learn to use the MSDN my friend. The world can be yours.

EDIT:

As for actually managing the config file, there are so many ways. For starters though, you should figure out how to get all services on the machine. With that collection, you serialize it to the config file. Then, maybe there's a config UI that lets you enable/disable/restart/stop/whatever the given service. Perhaps that piece allows you to save the setting to the config file. I dunno. It's all very contextual.

This post has been edited by MentalFloss: 11 May 2010 - 02:09 PM

Was This Post Helpful? 0
  • +
  • -

#7 blank_program   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 292
  • Joined: 22-July 09

Re: Seeking advice for best way to do this

Posted 11 May 2010 - 02:18 PM

ServiceController doesn't allow yu to change the startup type of the service. You can get the type but not set it.
Was This Post Helpful? 0
  • +
  • -

#8 MentalFloss   User is offline

  • .
  • member icon

Reputation: 613
  • View blog
  • Posts: 1,581
  • Joined: 02-September 09

Re: Seeking advice for best way to do this

Posted 11 May 2010 - 02:48 PM

Quote

ServiceController doesn't allow yu to change the startup type of the service. You can get the type but not set it.


Bummer... then maybe you want to invoke the "SC" console command?

DESCRIPTION:
        SC is a command line program used for communicating with the
        Service Control Manager and services.
USAGE:
        sc <server> [command] [service name] <option1> <option2>...


        The option <server> has the form "\\ServerName"
        Further help on commands can be obtained by typing: "sc [command]"
        Commands:
          query-----------Queries the status for a service, or
                          enumerates the status for types of services.
          queryex---------Queries the extended status for a service, or
                          enumerates the status for types of services.
          start-----------Starts a service.
          pause-----------Sends a PAUSE control request to a service.
          interrogate-----Sends an INTERROGATE control request to a service.
          continue--------Sends a CONTINUE control request to a service.
          stop------------Sends a STOP request to a service.
          config----------Changes the configuration of a service (persistent).
          description-----Changes the description of a service.
          failure---------Changes the actions taken by a service upon failure.
          failureflag-----Changes the failure actions flag of a service.
          sidtype---------Changes the service SID type of a service.
          privs-----------Changes the required privileges of a service.
          qc--------------Queries the configuration information for a service.
          qdescription----Queries the description for a service.
          qfailure--------Queries the actions taken by a service upon failure.
          qfailureflag----Queries the failure actions flag of a service.
          qsidtype--------Queries the service SID type of a service.
          qprivs----------Queries the required privileges of a service.
          delete----------Deletes a service (from the registry).
          create----------Creates a service. (adds it to the registry).
          control---------Sends a control to a service.
          sdshow----------Displays a service's security descriptor.
          sdset-----------Sets a service's security descriptor.
          showsid---------Displays the service SID string corresponding to an ar
bitrary name.
          GetDisplayName--Gets the DisplayName for a service.
          GetKeyName------Gets the ServiceKeyName for a service.
          EnumDepend------Enumerates Service Dependencies.

        The following commands don't require a service name:
        sc <server> <command> <option>
          boot------------(ok | bad) Indicates whether the last boot should
                          be saved as the last-known-good boot configuration
          Lock------------Locks the Service Database
          QueryLock-------Queries the LockStatus for the SCManager Database
EXAMPLE:
        sc start MyService



Then again, that might not be the best way either.

Hmm...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1