469,926 Members | 1,818 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Connecting to WMI on a Remote Computer using C#

13
Hi,
I am Connecting ti remote computer using C# WMI through the following code.But i t gives Some error "INVALID PARAMETERS" plse suggest me any modification in the code.
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.             }
Thanks
Prasad
Dec 8 '08 #1
1 22789
PRR
750 Expert 512MB
Connect To remote PC
There are certain issues regarding WMI connection to remote Pcs ...
Issues
Also a firewall may block remote WMI calls...
Also check this thread wmi
Dec 8 '08 #2

Post your reply

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

Similar topics

1 post views Thread by Jim Bayers | last post: by
3 posts views Thread by Frank Schumacher | last post: by
reply views Thread by Suresh | last post: by
reply views Thread by Zebadunc | last post: by
3 posts views Thread by Me LK | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.