How to find MS Office Product Key (CD Key) in C# with System.Management class -
i fond ms office version remotely providing ip address (within lan)
is possible find product key(cd key) ms office?
please suggest reference links or sample codes
below code working fine find whether ms office existing or not version
public list<string> readremoteregistryusingwmi(string machinename, string username, string pswd) { list<string> programs = new list<string>(); // string programs = string.empty; connectionoptions connectionoptions = new connectionoptions(); connectionoptions.authentication = authenticationlevel.connect; connectionoptions.impersonation = impersonationlevel.impersonate; connectionoptions.authentication = system.management.authenticationlevel.packetprivacy; connectionoptions.enableprivileges = true; connectionoptions.locale = "ms_409"; connectionoptions.username = username; connectionoptions.password = pswd; managementscope scope = new managementscope("\\\\" + machinename + "\\root\\cimv2", connectionoptions); scope.connect(); string softwareregloc = @"software\microsoft\windows\currentversion\uninstall"; managementclass registry = new managementclass(scope, new managementpath("stdregprov"), null); // select * win32_displayconfiguration //to find ms office version managementbaseobject inparams = registry.getmethodparameters("enumvalues"); //getstringvalue; enumvalues //enumkey(actual) // managementbaseobject inparams1 = registry. inparams["hdefkey"] = 0x80000002;//hkey_local_machine inparams["ssubkeyname"] = softwareregloc; // read registry key names managementbaseobject outparams = registry.invokemethod("enumkey", inparams, null); string[] programguids = outparams["snames"] string[]; foreach (string subkeyname in programguids) { inparams = registry.getmethodparameters("getstringvalue"); inparams["hdefkey"] = 0x80000002;//hkey_local_machine inparams["ssubkeyname"] = softwareregloc + @"\" + subkeyname; inparams["svaluename"] = "displayname"; // read registry value outparams = registry.invokemethod("getstringvalue", inparams, null); if (outparams.properties["svalue"].value != null) { string softwarename = outparams.properties["svalue"].value.tostring(); if ((softwarename.contains("microsoft office")) && ((softwarename.contains("95") || softwarename.contains("97") || softwarename.contains("2000") || softwarename.contains("2002") || softwarename.contains("2003") || softwarename.contains("2007") || softwarename.contains("2010") || softwarename.contains("2013")))) { programs.add(softwarename); // programs=softwarename.tostring(); break; } } } return programs; }
Comments
Post a Comment