Changing Service types using a script

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a script that changes the service type from disabled to automatic for
a given service. My test service is "themes" but it has the same behavior
regardless of which service you chose.

My script is as follows...

$Key = "HKLM\SYSTEM\CurrentControlSet\Services\"
$ServiceState = ReadValue ($key + "Themes", "Start")
?" themes: " + $ServiceState
If $ServiceState <> "2"
WriteValue ($key + "Themes", "Start", "2", "REG_DWORD")
EndIF

This script does as it should.. that is it will change the type from
disabled to Automatic. The problem is that you cannot start the service
afterwards, it believes it is still disabled and gives a 1058 error "service
is disabled". I have checked and the registry has a "2" listed where it
should.

The script simply changes the registry value from 4 to 2 under "start". If I
do a regedit and manually change the value from 4 to 2 it works. If I open up
the Service tool and go to properties and change the value from "disabled" to
"automatic" it works as well. It only fails if I use any kind of script to
change it from 4 to 2.

Also at the same time I get an Event ID 10005 in the system log...

DCOM got error "The service cannot be started, either because it is disabled
or because it has no enabled devices associated with it. " attempting to
start the service AeXNSClient with arguments "-Service" in order to run the
server:
{9EB55EF4-BD5A-4149-B42F-8CD8A6755B2D}

Any ideas what is wrong... I have seen others use this exact same script and
they have no issues.
 
Please note...
In the DCOM error I posted I was working with the AeXHSClient service and
not Themes. But the behavior remains the same regardless which service I am
working with.
 
In microsoft.public.win2000.registry
=?Utf-8?B?cGF0X3NtaXRoMTk2OQ==?= said:
Please note...
In the DCOM error I posted I was working with the AeXHSClient
service and not Themes. But the behavior remains the same
regardless which service I am working with.

Purely speculative but I am assuming that since your script bypasses
service control manager that the system is not made aware of the
changes adequately. I suggest using the SC.exe tool or equivalent
tools or API functions to alter a service's configuration.
 
Mark V...
You are absolutely correct. I used a new script that used a WMI interface
and it worked great. Thanks for your help.
 
Back
Top