Click here to Skip to main content
16,017,986 members
Home / Discussions / C#
   

C#

 
GeneralRe: Forgot to mention ... Pin
Giorgi Dalakishvili16-Aug-07 1:38
mentorGiorgi Dalakishvili16-Aug-07 1:38 
GeneralRe: Forgot to mention ... Pin
J4amieC16-Aug-07 3:27
J4amieC16-Aug-07 3:27 
GeneralAdditional thoughts Pin
Urs Enzler16-Aug-07 3:39
Urs Enzler16-Aug-07 3:39 
AnswerRe: Declaring Global variables in .cs file Pin
User 167325216-Aug-07 14:36
User 167325216-Aug-07 14:36 
QuestionRetrieving the installed softwares in WMI [modified] Pin
toink toink16-Aug-07 1:02
toink toink16-Aug-07 1:02 
AnswerRe: Retrieving the installed softwares in WMI Pin
Harkamal Singh16-Aug-07 1:53
Harkamal Singh16-Aug-07 1:53 
GeneralRe: Retrieving the installed softwares in WMI Pin
Scott Dorman16-Aug-07 3:50
professionalScott Dorman16-Aug-07 3:50 
AnswerRe: Retrieving the installed softwares in WMI Pin
Scott Dorman16-Aug-07 3:49
professionalScott Dorman16-Aug-07 3:49 
Using WMI isn't the simplest thing to do from managed code. If you search Google, you'll find a lot of information. Here is sample code from a message[^] in the microsft.public.dotnet.framework.wmi newsgroup:
C#
const uint HKEY_LOCAL_MACHINE = unchecked((uint)0x80000002);
ManagementClass wmiRegistry = new ManagementClass("root/default", "StdRegProv", null);
 
//Enumerate subkeys
string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
object[] methodArgs = new object[] {HKEY_LOCAL_MACHINE, keyPath, null};
uint returnValue = (uint)wmiRegistry.InvokeMethod("EnumKey", methodArgs);
Console.WriteLine("Executing EnumKey() returns: {0}", returnValue);

if (null != methodArgs[2])
{
   string[] subKeys = methodArgs[2] as String[];
 
   if (subKeys == null) return;
 
   ManagementBaseObject inParam = wmiRegistry.GetMethodParameters("GetStringValue");
   inParam["hDefKey"] = HKEY_LOCAL_MACHINE;
   string keyName = "";
 
   foreach(string subKey in subKeys)
   {
      //Display application name
      keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + subKey;
      keyName = "DisplayName";
      inParam["sSubKeyName"] = keyPath;
      inParam["sValueName"] = keyName;
      ManagementBaseObject outParam = wmiRegistry.InvokeMethod("GetStringValue", inParam, null);
 
      if ((uint)outParam["ReturnValue"] == 0)
         Console.WriteLine(outParam["sValue"]);
   }
}
This is essentially just enumerating over the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ registry key, so you can use the normal .NET registry classes to do the same thing without WMI.

Using the Win32_Product class, you would want to do something like this:
C#
ManagementObjectSearcher products = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
 
foreach (ManagementObject product in products.Get())
{
   Console.WriteLine("Software name: {0}", product.Name);
   Console.WriteLine("Install date: {0}", product.InstallDate);
   ...
}
The properties you list aren't all included in the Win32_Product[^] class, so you will probably need to do additional queries against other objects to get all of the information.

-----------------------------
In just two days, tomorrow will be yesterday.

http://geekswithblogs.net/sdorman

GeneralRe: Retrieving the installed softwares in WMI Pin
toink toink23-Aug-07 0:47
toink toink23-Aug-07 0:47 
GeneralRe: Retrieving the installed softwares in WMI Pin
Scott Dorman23-Aug-07 3:06
professionalScott Dorman23-Aug-07 3:06 
QuestionDataGridView Pin
nasambur16-Aug-07 0:56
nasambur16-Aug-07 0:56 
AnswerRe: DataGridView Pin
Rocky#16-Aug-07 1:27
Rocky#16-Aug-07 1:27 
GeneralRe: DataGridView Pin
nasambur16-Aug-07 1:45
nasambur16-Aug-07 1:45 
GeneralRe: DataGridView Pin
Rocky#16-Aug-07 1:55
Rocky#16-Aug-07 1:55 
QuestionHow My C# code read Excel file and save all data to SQL server2000? Pin
shafikshafik16-Aug-07 0:41
shafikshafik16-Aug-07 0:41 
AnswerRe: How My C# code read Excel file and save data it to SQL server2000? Pin
Giorgi Dalakishvili16-Aug-07 0:43
mentorGiorgi Dalakishvili16-Aug-07 0:43 
GeneralRe: How My C# code read Excel file and save data it to SQL server2000? Pin
shafikshafik16-Aug-07 1:13
shafikshafik16-Aug-07 1:13 
GeneralRe: How My C# code read Excel file and save data it to SQL server2000? Pin
pmarfleet16-Aug-07 1:21
pmarfleet16-Aug-07 1:21 
GeneralRe: How My C# code read Excel file and save data it to SQL server2000? Pin
Giorgi Dalakishvili16-Aug-07 1:23
mentorGiorgi Dalakishvili16-Aug-07 1:23 
Questionadd application at startup Pin
Naveed72716-Aug-07 0:37
Naveed72716-Aug-07 0:37 
AnswerRe: add application at startup Pin
Giorgi Dalakishvili16-Aug-07 0:42
mentorGiorgi Dalakishvili16-Aug-07 0:42 
AnswerRe: add application at startup Pin
Harkamal Singh16-Aug-07 4:56
Harkamal Singh16-Aug-07 4:56 
QuestionInserting text and image in word document Pin
praveen pandey16-Aug-07 0:34
praveen pandey16-Aug-07 0:34 
QuestionHow can i make call using modem and recive call via modem Pin
Naveed72716-Aug-07 0:33
Naveed72716-Aug-07 0:33 
AnswerRe: How can i make call using modem and recive call via modem Pin
pbraun16-Aug-07 6:43
pbraun16-Aug-07 6:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.