Thanks, Ken!
In case anyone is interested, the WMI class uses these API calls, which you
can also call directly. The CONSTs of interest are defined in WINSVC.H.
Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA"
_
(ByVal lpMachineName As String, _
ByVal lpDatabaseName As String, _
ByVal dwDesiredAccess As Integer) _
As Integer
Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" _
(ByVal hSCManager As Integer, _
ByVal lpServiceName As String, _
ByVal dwDesiredAccess As Integer) _
As Integer
Declare Function ChangeServiceConfig Lib "advapi32.dll" Alias
"ChangeServiceConfigA" _
(ByVal hService As Integer, _
ByVal dwServiceType As Integer, _
ByVal dwStartType As Integer, _
ByVal dwErrorControl As Integer, _
ByVal lpBinaryPathName As String, _
ByVal lpLoadOrderGroup As String, _
ByRef lpdwTagId As Integer, _
ByVal lpDependencies As String, _
ByVal lpServiceStartName As String, _
ByVal lpPassword As String, _
ByVal lpDisplayName As String) _
As Integer
"Ken Tucker [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> Invoke the win32_service wmi classes changestartmode method.
>
> http://msdn.microsoft.com/library/de...32_service.asp
>
> Ken
> ------------------
> "FB's .NET Dev PC" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> On one PC, I have several services, all of which need to run, some of
> which
> I am writing, and some of which (such as SQL server) I am not writing.
>
> My overall goal is to have a restartable, stable system. One of my
> services
> is a "system monitor" which controls the startup of the other services I
> am
> writing, based on the SQL server having started.
>
> I am using WMI to monitor services, and
> System.ServiceProcess.ServiceController to start and stop them. This
> works.
>
> What I need to do, if all other conditions fail to resolve problems, is
> set
> my System Monitor to "Manual" startup from the "Automatic" which I set as
> a
> ServiceStartMode in the installer.
>
> How can I change the start mode of a service from within that service (or
> any other service, for that matter)?
>
> Thanks
> Fred Bourdelier
> Tucson AZ
>
>
> PS I use the code below to reboot the computer - this only works if no
> service or app is hung. Is there a way to force a reboot through hanging
> programs?
> System.Diagnostics.Process.Start("shutdown", "-s -t 00")
> System.Diagnostics.Process.Start("shutdown", "-r -t 00")
>
> System.Diagnostics.Process.Start("shutdown", "-l -t 00")
>
>
>