473,583 Members | 4,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use "ServiceControl ler.MachineName Property "

hello,
i'm try to research the way to open a remote machine's to collect the
services and processes. i have the local data collection running but i can
not figure out what MSDN or the C# help file is stating how to use
"servicecollect er.machinename" to get the remote server's data.

there is no samples on using framework to do this but loads of WMI.

can someone share any sample / snippet on using framework with C# 2005 to
get the remote server's services and or processes?
Feb 20 '07 #1
7 8611
"auldh" <au***@discussi ons.microsoft.c omwrote in message
news:4F******** *************** ***********@mic rosoft.com...
hello,
i'm try to research the way to open a remote machine's to collect the
services and processes. i have the local data collection running but i can
not figure out what MSDN or the C# help file is stating how to use
"servicecollect er.machinename" to get the remote server's data.

there is no samples on using framework to do this but loads of WMI.

can someone share any sample / snippet on using framework with C# 2005 to
get the remote server's services and or processes?


Don't know what docs you are looking at, but the ".NET Framework Class Library" in MSDN is
where to start, there is the static ServiceControll er.GetServices Method that takes the
machine name (a string) you want to get a list of services from.
Note however that this requires you to run in the account of an admin on the remote system.

Willy.
Feb 20 '07 #2
thanks Willy that was easy.
i was reading the "ServiceControl ler Members" and found
the "machinenam e" properties.
"Willy Denoyette [MVP]" wrote:
"auldh" <au***@discussi ons.microsoft.c omwrote in message
news:4F******** *************** ***********@mic rosoft.com...
hello,
i'm try to research the way to open a remote machine's to collect the
services and processes. i have the local data collection running but i can
not figure out what MSDN or the C# help file is stating how to use
"servicecollect er.machinename" to get the remote server's data.

there is no samples on using framework to do this but loads of WMI.

can someone share any sample / snippet on using framework with C# 2005 to
get the remote server's services and or processes?

Don't know what docs you are looking at, but the ".NET Framework Class Library" in MSDN is
where to start, there is the static ServiceControll er.GetServices Method that takes the
machine name (a string) you want to get a list of services from.
Note however that this requires you to run in the account of an admin on the remote system.

Willy.
Feb 20 '07 #3
is there no way via framework to see the "startname" property of the service?
do i still have to call the "WMI"?
if so do i have to use:
System.Manageme nt.ManagementSc ope < to the remote machine\\root\\ cimv2
System.Manageme ntObject wmiService;
wmiService = new ManagementObjec t("Win32_Servic e.Name='" +
sServices.Servi ceName + "'");

in order to get the "startname" ?

i'm trying to get the details from both local and remote machines services.

"auldh" wrote:
thanks Willy that was easy.
i was reading the "ServiceControl ler Members" and found
the "machinenam e" properties.
"Willy Denoyette [MVP]" wrote:
"auldh" <au***@discussi ons.microsoft.c omwrote in message
news:4F******** *************** ***********@mic rosoft.com...
hello,
i'm try to research the way to open a remote machine's to collect the
services and processes. i have the local data collection running but i can
not figure out what MSDN or the C# help file is stating how to use
"servicecollect er.machinename" to get the remote server's data.
>
there is no samples on using framework to do this but loads of WMI.
>
can someone share any sample / snippet on using framework with C# 2005 to
get the remote server's services and or processes?


Don't know what docs you are looking at, but the ".NET Framework Class Library" in MSDN is
where to start, there is the static ServiceControll er.GetServices Method that takes the
machine name (a string) you want to get a list of services from.
Note however that this requires you to run in the account of an admin on the remote system.

Willy.

Feb 20 '07 #4
"auldh" <au***@discussi ons.microsoft.c omwrote in message
news:FE******** *************** ***********@mic rosoft.com...
is there no way via framework to see the "startname" property of the service?
do i still have to call the "WMI"?
System.Manageme nt is part of the framework isn't it?

if so do i have to use:
System.Manageme nt.ManagementSc ope < to the remote machine\\root\\ cimv2
System.Manageme ntObject wmiService;
wmiService = new ManagementObjec t("Win32_Servic e.Name='" +
sServices.Servi ceName + "'");

in order to get the "startname" ?

i'm trying to get the details from both local and remote machines services.
You can get all properties you are interested in by using a WQL query like so:

string serviceName = "Spooler";
SelectQuery query = new SelectQuery("se lect StartName, Status from Win32_Service where
Name ='" + serviceName + "'");
using(Managemen tObjectSearcher searcher = new ManagementObjec tSearcher(query ))
{
foreach (ManagementObje ct mo in searcher.Get()) {
Console.WriteLi ne("{0} - {1} ", mo["StartName"], mo["Status"]);
}
}

Sure, to connect to a remote system, you'll need to specify a ManagementScope and
appropriate ConnectionOptio ns. Also, you need to take care of when connecting to a remote
machine is that you specify a user account with appropriate rights to query the WMI
namespace.

Willy.

Feb 21 '07 #5
yes Willy it is.
it is just that using System.Manageme nt does not collect all the field of WMI.
i was just hoping to use FrameWork over WMI.

i do have another problem. i figured how to get to the remote machine and
start the data collection but it runs then stops when reading the "DNS"
service and the error in VS C# 2005 does not tell me what the problem is. it
is very generic message stating "Get general help for this exception" when i
do a ManagementObjec t.wm.Get();
public string[] getXprServices( bool oRunning)
{
///once all the service is collected return the full array to
display to monitor.
///the way to get the detail i want requires that i call both
the framework
///and the wmi.

//for debug only!!
string strmachine = "server2";
ConnectionOptio ns options = new ConnectionOptio ns();
options.Usernam e = "usera";
options.Passwor d = "downriver" ;
options.Authori ty = "ntdlmdomain:my domain";

ServiceControll er[] xprServices;
xprServices = ServiceControll er.GetServices( strmachine);
string[,] aServices = new string[xprServices.Len gth + 1, 5];
int iElement = 1; //the service number incrementor
aServices[0, 0] = "Service Name";
aServices[0, 1] = "Display Name";
aServices[0, 2] = "Status";
aServices[0, 3] = "Log on As";
aServices[0, 4] = "# of Dependencies";
foreach (ServiceControl ler sServices in xprServices)
{
if (oRunning) //only collect the running services
{
if (sServices.Stat us == ServiceControll erStatus.Runnin g)
{
aServices[iElement, 0] = sServices.Servi ceName;
aServices[iElement, 1] = sServices.Displ ayName;
aServices[iElement, 2] = sServices.Statu s.ToString();
ManagementObjec t wmiService;
wmiService = new
ManagementObjec t("Win32_Servic e.Name='" + sServices.Servi ceName + "'");
wmiService.Get( );
aServices[iElement, 3] =
wmiService["StartName"].ToString();
aServices[iElement, 4] =
sServices.Servi cesDependedOn.L ength.ToString( );
}
}
else //all services
{
aServices[iElement, 0] = sServices.Servi ceName;
aServices[iElement, 1] = sServices.Displ ayName;
aServices[iElement, 2] = sServices.Statu s.ToString();

ManagementScope scope = new ManagementScope ("\\\\" +
strmachine + "\\root\\cimv2" , options);
//scope.Connect() ;
ManagementObjec t wmiService;
wmiService = new ManagementObjec t("Win32_Servic e.Name='"
+ sServices.Servi ceName + "'");
wmiService.Get( ); <<<< dies here!!!
aServices[iElement, 3] =
wmiService["StartName"].ToString();
//aServices[iElement, 3] = "";
aServices[iElement, 4] =
sServices.Servi cesDependedOn.L ength.ToString( );
}
iElement++;
}//foreach(Service Controller sServices in xprServices)
formatoutput fout = new formatoutput();
string[] saServices = fout.multiArray Format(aService s);
return (saServices);
}//public string[] getXprServices( )

"Willy Denoyette [MVP]" wrote:
"auldh" <au***@discussi ons.microsoft.c omwrote in message
news:FE******** *************** ***********@mic rosoft.com...
is there no way via framework to see the "startname" property of the service?
do i still have to call the "WMI"?

System.Manageme nt is part of the framework isn't it?

if so do i have to use:
System.Manageme nt.ManagementSc ope < to the remote machine\\root\\ cimv2
System.Manageme ntObject wmiService;
wmiService = new ManagementObjec t("Win32_Servic e.Name='" +
sServices.Servi ceName + "'");

in order to get the "startname" ?

i'm trying to get the details from both local and remote machines services.

You can get all properties you are interested in by using a WQL query like so:

string serviceName = "Spooler";
SelectQuery query = new SelectQuery("se lect StartName, Status from Win32_Service where
Name ='" + serviceName + "'");
using(Managemen tObjectSearcher searcher = new ManagementObjec tSearcher(query ))
{
foreach (ManagementObje ct mo in searcher.Get()) {
Console.WriteLi ne("{0} - {1} ", mo["StartName"], mo["Status"]);
}
}

Sure, to connect to a remote system, you'll need to specify a ManagementScope and
appropriate ConnectionOptio ns. Also, you need to take care of when connecting to a remote
machine is that you specify a user account with appropriate rights to query the WMI
namespace.

Willy.

Feb 21 '07 #6
"auldh" <au***@discussi ons.microsoft.c omwrote in message
news:0B******** *************** ***********@mic rosoft.com...
yes Willy it is.
it is just that using System.Manageme nt does not collect all the field of WMI.
i was just hoping to use FrameWork over WMI.
Sure it does, System.Manageme nt is a thin layer over WMI, what fields do you think are not
collected?
i do have another problem. i figured how to get to the remote machine and
start the data collection but it runs then stops when reading the "DNS"
service and the error in VS C# 2005 does not tell me what the problem is. it
is very generic message stating "Get general help for this exception" when i
do a ManagementObjec t.wm.Get();
If you have problems with a single service, run wbemtest.exe and try to find out what's
wrong.

Willy.

Feb 22 '07 #7
i'm not having luck running "wbemtest.e xe" i'm able to get to the machine and
all.
i would use WMI solely but i would like to collect the "ServicesDepend edOn"
and maybe other objects in the "servicecontrol ler" set.

when i review the exception box that comes up it states that it is a wrong
cast? but this was successful when ran through the local machine. could it be
a timeout? i'm not sure what to do at this point. i provided the function in
my previous attachment. it runs well on the local machine with out a problem
but only when a remote machine is called....

lost...
"Willy Denoyette [MVP]" wrote:
"auldh" <au***@discussi ons.microsoft.c omwrote in message
news:0B******** *************** ***********@mic rosoft.com...
yes Willy it is.
it is just that using System.Manageme nt does not collect all the field of WMI.
i was just hoping to use FrameWork over WMI.

Sure it does, System.Manageme nt is a thin layer over WMI, what fields do you think are not
collected?
i do have another problem. i figured how to get to the remote machine and
start the data collection but it runs then stops when reading the "DNS"
service and the error in VS C# 2005 does not tell me what the problem is. it
is very generic message stating "Get general help for this exception" when i
do a ManagementObjec t.wm.Get();

If you have problems with a single service, run wbemtest.exe and try to find out what's
wrong.

Willy.

Feb 23 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2466
by: Mark Hannon | last post by:
I have been researching the "disabled" property for form data and wanted to know: - Does the disabled property supress the form item from being submitted? - Can the disabled property be applied when the submit button is pressed? I am designing a PayPal order page that will have 4 items, each with a 3-character text box where the customer...
1
16428
by: Dr. J | last post by:
I have an application that opens a socket and connects to another application listening over a port. The problem I am encountering is that when the listening application is closed my application cannot detect it to take appropriate action. I am using "Connected" property of the Socket class, but it seems this property does not reflect the...
1
2349
by: charliewest | last post by:
Using the .Net Compact Framework, how is it possible to override the SelectImageIndex property? I am trying to achieve the following: That when a user selects a node, or child-node, that the image does not change. By default, the TreeView control selects the image in the ImageList at position 0. Thanks,
3
1659
by: Gary | last post by:
Hi, In the program below, C = A+B, and the aim is to delay the calculation of C until the user asks for C. The boolean mUTD (UpToDate) is used indicate when Calc() must be run to make the C = A+B calculation before C is returned to user. When the Driver program at bottom is run, the behavior is very strange, the debug statement "in...
8
14262
by: Don Wash | last post by:
Hi There! I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView. We used to have "Key" property in TreeView node object in VB6. What is the equivalent of "Key" property of TreeView node in VB.NET? Has the property name "Key" has been changed to something else?...
15
12529
by: simonoficina | last post by:
Hello all! I am a vb.net beginner in Spain. When I use VB6 ,the button object has a property called "default" that can set this button like press "ENTER" key. But in the VB.net I can't find this property. Where is it? Or mabye change the other thing,No?Thanks ! Simon
3
6086
by: cmsimmers | last post by:
I'm trying to display the available space on a disk drive. This could be tricky if the user choose a drive on which they are limited to a quota. The "FreeSpace" property returns the total number of bytes on the disk, which could be significantly larger than the space actually available to the user. I found documentation referring to VB...
3
2837
by: Bob Cohen \(106531\) | last post by:
I want to define some metadata using custom attributes to apply to properties in various classes. The properties return values that are classes themselves. I want to retrieve the attribute information in the classes from which the fields/properties are derived, but I can't figure out how to get them. I seem to be stuck since the...
0
2069
by: kartikmpatel | last post by:
I have set "AutoEllipsis" property on for my checkbox(winform). My application is working with multiple languages. Particular with Chinese language, I have some issues. Here are some observation on XP 32bit : 1) AutoEllipsis property set + Chinese Language Pack installed & Set = working well ( it displays, text of checkbox) 2)...
0
7825
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8179
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7933
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5700
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5372
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3816
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1155
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.