473,789 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

13 New Member
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 28090
Ramk
61 New Member
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 Recognized Expert Contributor
@pnalla
Inaddition to WMI you can also look at ServiceControll er 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 New Member
did you try adding:
options.Imperso nation = ImpersonationLe vel.Impersonate ;
just after:
ConnectionOptio ns connection = new ConnectionOptio ns();

?
Feb 4 '10 #4

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

Similar topics

1
1852
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. I'm using DTS on a central server to bring the data back. The DTS package has it's own schedule and all works well. But now I want to "on demand" runs the service on a particular machine to
3
5739
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 connect to the database over ODBC on unix i did this: on db2 console: catalog tcpip node archiv remote PC1 server DB2_db2inst1
1
19983
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, all is ok. The WebService run correctly.. but if I try to call the Webservice from a SmartDeviceApplication the program crash and the debug message is:
3
4093
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 the list of componenet services, i know we can get the list of windows services, but i dont know how to get the list of Component services ?
1
16410
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 the user paul (pw:paul123) on the computer A in the domain ABC. This application should stop / start a service, which is running on computer B (in workgroup ABCWG (NOT IN DOMAIN ABC)). On the computer B I have a user administrator (pw: adminTest)...
3
11855
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 start/stop the service, it gives me "Cannot open Service Control Manager on computer 'xxx.xxx.xxx.xxx'. This operation might require other privileges." error. Helpfull info: - I am an admin on all 3 PCs - web app is using "Windows" authentication...
1
1860
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 the same thing to a VMWare image accessable over the same network thats running MS Windows Server 2003 R2 SP2 . I want to be able to stop and start remotely tthe COM+ services. Can anyone get me started on this, i have not been able to find any
2
10931
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 suggest me.... thanks prasad
2
10400
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
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2906
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.