PC Review


Reply
Thread Tools Rate Thread

How to change the Startup Mode of a Service?

 
 
FB's .NET Dev PC
Guest
Posts: n/a
 
      27th Oct 2004
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")


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      28th Oct 2004
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")



 
Reply With Quote
 
 
 
 
Alex Clark
Guest
Posts: n/a
 
      28th Oct 2004
The -f switch on XP forces hung apps to end immediately, alternatively you
could use a Win API method specifically designed to shut down the system
(not sure what it will be called but do a quick MSDN search and you'll find
it, probably in Advapi.dll) --- this would probably have a flag that you
could specify to force a system shutdown.

Cheers,
Alex Clark


> 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")
>




 
Reply With Quote
 
FB's .NET Dev PC
Guest
Posts: n/a
 
      29th Oct 2004
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")
>
>
>



 
Reply With Quote
 
FB's .NET Dev PC
Guest
Posts: n/a
 
      29th Oct 2004
Many thanks, Alex.

I found this one

BOOL InitiateSystemShutdown(
LPTSTR lpMachineName,
LPTSTR lpMessage,
DWORD dwTimeout,
BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown
);

which takes a Force Apps Closed parameter.


"Alex Clark" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The -f switch on XP forces hung apps to end immediately, alternatively you
> could use a Win API method specifically designed to shut down the system
> (not sure what it will be called but do a quick MSDN search and you'll
> find it, probably in Advapi.dll) --- this would probably have a flag that
> you could specify to force a system shutdown.
>
> Cheers,
> Alex Clark
>
>
>> 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")
>>

>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Crashes in Normal Mode, Safe Mode With Networking mode butnot Safe Mode bhoi Windows XP Help 0 15th Aug 2011 10:05 PM
XP Startup problems in Normal Mode and Safe Mode =?Utf-8?B?aG9vZ2xhbmQ5MQ==?= Windows XP Help 0 27th Mar 2005 12:39 AM
Failure to show desktop and startbar at startup in normal mode and safe mode Simon Chung Windows XP Help 1 26th Mar 2005 10:06 AM
need to restart XP in Safe Mode but there is no prompt for MS DOS or Safe mode mode on startup menu - HELP! =?Utf-8?B?U29ubmljYm9vbXM=?= Windows XP Basics 3 1st Jun 2004 03:20 PM
XP startup in normal mode vs. (original) mode Eric Boucher Windows XP Logo 0 23rd Sep 2003 09:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:59 PM.