By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,953 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,953 IT Pros & Developers. It's quick & easy.

Changing the startup type on a remote system

P: n/a
I am trying to write a little utility and it needs to check the startup type
of a given service on a remote machine and, if it is disabled, set it to
manual. I have found out how to do this on the local machine using
ServiceInstaller.StartType, but I cannot seem to find a way to specify the
name of a remote machine to perform this action upon.

I know that ServiceController will allow me to talk to a remote system and
start/stop services, but it lacks the methods and properties I need for
StartupType.

I'm pretty new to .NET, so It's quite likely I'm simply looking in the wrong
place, but a day of Googling has left me without an answer. If someone could
point me in the correct direction to solve this, I would be most grateful.
If this is the wrong group, that would also be helpful info.

If anyone has suggestions on good reference manuals with a strong lean
towards system and networking programming, I'd like to hear about them.

TIA,

ne.
Apr 6 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,

You may find following example code useful for your purpose:

#Extend ServiceController class to change the StartupType of Windows
Services - The Code Project - System Programming
http://www.codeproject.com/cs/system...controller.asp

Please let me know if this works for you. Thanks.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 9 '07 #2

P: n/a

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:jR**************@TK2MSFTNGHUB02.phx.gbl...
Hi,

You may find following example code useful for your purpose:

#Extend ServiceController class to change the StartupType of Windows
Services - The Code Project - System Programming
http://www.codeproject.com/cs/system...controller.asp
This does do what I'm looking for, but it still seems to leave me with the
problem of specifying the target system. This example seems to be operating
on the local system & I haven't been able to spot a property to specify a
remote system name. Maybe I'm missing it?
Apr 9 '07 #3

P: n/a

"NetworkElf" <ne********@nospam.nospamwrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...
>
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:jR**************@TK2MSFTNGHUB02.phx.gbl...
>Hi,

You may find following example code useful for your purpose:

#Extend ServiceController class to change the StartupType of Windows
Services - The Code Project - System Programming
http://www.codeproject.com/cs/system...controller.asp

This does do what I'm looking for, but it still seems to leave me with the
problem of specifying the target system. This example seems to be
operating on the local system & I haven't been able to spot a property to
specify a remote system name. Maybe I'm missing it?
OK, I'm thinking something like this:

dim myObject as Management.Object

myObject.CreateObjRef()
However, I'm uncertain where to go from there. Could anyone point me to an
example showing how this is used to connect to a remote system?

Thank you.
Apr 9 '07 #4

P: n/a
Hi,

Sorry about the confusion, yes the example code is not completely correct
since it always used a local WMI object path to query the service. We need
to modify it using following code:

1) Add a private property WmiPath:

private string WmiPath
{
get {
return "\\\\" + this.MachineName + "\\root\\cimv2:Win32_Service.Name='"
+ this.ServiceName + "'";
}
}
2) Modify the properties Description, StartupType to use this WmiPath
property to pass to the ManagementPath constructor.
By the way, the code is changing the service startup type using WMI, you
can find more information here:

#Win32_Service
http://msdn2.microsoft.com/en-us/library/aa394418.aspx
Hope this helps.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 10 '07 #5

P: n/a

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:aj**************@TK2MSFTNGHUB02.phx.gbl...

Thank you, Walter. I'll see what I can do with this after I've had time to
read the link you included.

I'm curious though, is there a reason for not including the startup type
property in ServiceController? I'm sure there's a reason, but, being new to
..NET, it eludes me.

Thank you for your help.
Apr 10 '07 #6

P: n/a
Hi,

The startup type isn't usually changed during execution of an application
that uses the service, it is not part of the ServiceController. On ther
other hand, WMI is designed to do such job and .NET has support of WMI
(such as the above code is using ManagementPath to change the Win32_Service
object).
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 11 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.