473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to Connect the remote PC Using C# For Start/Stop the Windows Services

13
Hi,
I am Connecting ti remote computer using C# WMI through the following code.But i t gives Some error "INVALID PARAMETERS" at scop.Connet
Is there any procedure to coonect to rempte pc with authentication and start and stop the remote pc Windows services.

plse suggest me any modification in the code and tell mw the other code . Its Urgent.

Expand|Select|Wrap|Line Numbers
  1. try 
  2.             { 
  3.                 ConnectionOptions connection = new ConnectionOptions(); 
  4.                 connection.Username = userNameBox.Text; 
  5.                 connection.Password = passwordBox.Text; 
  6.                 connection.Authority = "ntlmdomain:DOMAIN"; 
  7.  
  8.                 ManagementScope scope = new ManagementScope( 
  9.                     "\\\\FullComputerName\\root\\CIMV2", connection); 
  10.                 scope.Connect(); 
  11.  
  12.                 ObjectQuery query= new ObjectQuery( 
  13.                     "SELECT * FROM Win32_Service");  
  14.  
  15.                 ManagementObjectSearcher searcher =  
  16.                     new ManagementObjectSearcher(scope, query); 
  17.  
  18.                 foreach (ManagementObject queryObj in searcher.Get()) 
  19.                 { 
  20.                     Console.WriteLine("-----------------------------------"); 
  21.                     Console.WriteLine("Win32_Service instance"); 
  22.                     Console.WriteLine("-----------------------------------"); 
  23.                     Console.WriteLine("Caption: {0}", queryObj["Caption"]); 
  24.                     Console.WriteLine("Description: {0}", queryObj["Description"]); 
  25.                     Console.WriteLine("Name: {0}", queryObj["Name"]); 
  26.                     Console.WriteLine("PathName: {0}", queryObj["PathName"]); 
  27.                     Console.WriteLine("State: {0}", queryObj["State"]); 
  28.                     Console.WriteLine("Status: {0}", queryObj["Status"]); 
  29.                 } 
  30.                 Close(); 
  31.             } 
  32.             catch(ManagementException err) 
  33.             { 
  34.                 MessageBox.Show("An error occured while querying for WMI data: " 
  35.                     + err.Message); 
  36.             } 
  37.  
Thanks
Prasad.
Dec 11 '08 #1
3 27868
Ramk
61
Before going to the problem, I want to remind you that, do wrap your code snippets around the [code] tags.

To use WMI, windows firewall should be disabled on the remote pc.

I got this output(omitted the entire output)...
Expand|Select|Wrap|Line Numbers
  1. -----------------------------------\nWin32_Service instance-----------------------------------Caption: Alerter
  2. Description: Notifies selected users and computers
  3. of administrative alerts. If the service is stopped, programs that use administrative alerts will not receive them. If this service is disabled,
  4. any services that explicitly depend on it will fail to start.
  5. Name: Alerter
  6. PathName: C:\\WINDOWS\\system32\\svchost.exe -k LocalService
  7. State: Running
  8. Status: OK
With firewall enabled, you may receive the following message
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
Dec 11 '08 #2
PRR
750 Expert 512MB
@pnalla
Inaddition to WMI you can also look at ServiceController Class. You need to specify Machine name and service name for remote pcs..
For WMI to work on remote pcs.. specially for admin tasks, there are certain issues... do check the links posted here
WMI Remote
Also check this implementation on MSDN start stop services
Dec 11 '08 #3
zaurb
1
did you try adding:
options.Impersonation = ImpersonationLevel.Impersonate;
just after:
ConnectionOptions connection = new ConnectionOptions();

?
Feb 4 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: LP | last post by:
Hello All, I have a windows service on several remote machines that gather data and load it to SQL 2000. The service on the remote machine runs at a desirable frequency and gathers the data. ...
3
by: Fabian Knopf | last post by:
Hi friends, i have a unix machine PC1 where a database is running ( IBM DB2 V8.1 ) . Then i have another machine PC2 i installed there also ( IBM DB2 V8.1 ). On PC2 i installed unixODBC. To...
1
by: Antonello Calabrò | last post by:
Hi all, I created a webservice that execute a sql query on demand. If I try to execute the query from the WebForm, all is ok. If I try to execute the query from a normal Windows Application,...
3
by: SenthilVel | last post by:
Hi I want to list the available "Component Services " (COM+) in a machine . i am trying to get the list of Componenet services in a machine using windows forms in dotnet , how can i retrive...
1
by: schaf | last post by:
Hi all! I'm still trying to start/stop a service on a remote computer. (I promiss that's the last new post because of this problem from my side) My situation: I've an application running under...
3
by: Goran Djuranovic | last post by:
Hi all, I have a web app running on a local PC that can start and stop windows service on a remote machine, but only when I browse to it locally. If I browse to it from my other PC and try to...
1
by: Peted | last post by:
Hello. Im using vs2008 c# and XP sp3 I wanted to learn how to use c# to control remotely COM+ Applications under Component services of another desktop on the same network runnung XPsp3 and do...
2
by: pnalla | last post by:
hi, I can aceess ths windows services on remote machine. but i can not start and stop the services.it gives some error message like " can not open 'service name' on comuter 'machine name'. Please...
2
by: pnalla | last post by:
How to access windows services on remote machine using C#.please give me some example code.also how to start/stop service on remote machine .please give me some example code. thanks prasad
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.