code_junkie

find a Particular product present in a remote system or not

Nov 12th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public void uninstall4(string targetServer, string product,string guid , string version)
  2. {
  3. //Connect to Server
  4. System.Management.ConnectionOptions connoptions = new System.Management.ConnectionOptions();
  5. connoptions.Impersonation = System.Management.ImpersonationLevel.Impersonate;
  6. connoptions.Timeout = new TimeSpan(0, 0, 10); // 10 seconds
  7. System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\" + targetServer + @"rootcimv2", connoptions);
  8. scope.Connect();
  9.  
  10. string q = "select * from Win32_Product where name = '" + product + "' and IdentifyingNumber='"+guid+"' and version = '"+version+"'";
  11.  
  12. System.Management.SelectQuery query = new System.Management.SelectQuery(q);
  13.  
  14. System.Management.EnumerationOptions options = new System.Management.EnumerationOptions();
  15. options.EnumerateDeep = false;
  16. options.ReturnImmediately = false;
  17. options.DirectRead = true;
  18.  
  19. using (System.Management.ManagementObjectSearcher searcher
  20. = new System.Management.ManagementObjectSearcher(scope, query, options))
  21. {
  22. using (System.Management.ManagementObjectCollection moc = searcher.Get())
  23. {
  24. if(moc == null || moc.Count == 0)
  25. {
  26. throw new Exception("product Not Found");
  27. }
  28.  
  29. }
  30. }
  31.  
  32. }
Add Comment
Please, Sign In to add comment