Changing the startup type on a remote system

N

NetworkElf

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.
 
W

Walter Wang [MSFT]

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/extendservicecontroller.asp

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

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================

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

NetworkElf

Walter Wang said:
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/extendservicecontroller.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?
 
N

NetworkElf

NetworkElf said:
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.
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
N

NetworkElf

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.
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top