I fond the MS Office Version remotely by Providing IP Address (within the LAN)
Is it possible to find Product Key(CD Key) for MS Office?
Please suggest any Reference Links or sample codes
Below code is working fine to find whether MS Office is existing or not with 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 * from 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"] as 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;
}
User contributions licensed under CC BY-SA 3.0