I'm making a little program to check some specifications of the CPU, like RAM, CPU name, Speed, etc., but my knowledge is basic, and im using powershell in Visual Studio with C#, so im using this method to bring the OS name, at the moment, it works, but specifically in a pc, it doesn't work, it brings a null value. I have tested it on so many other pc's, and it's working, but i have no idea why on that pc doesn't. This is my method:
public String RtrOS()
{
String OS = "";
PowerShell powershellCommand = PowerShell.Create();
powershellCommand.AddScript("(Get-WmiObject Win32_OperatingSystem).Version");
Collection<PSObject> results = powershellCommand.Invoke();
foreach (var result in results)
{
OS = result.ToString();
}
}
So, what i need it's to know if my method it's fine, and if it possible to do it in another way more efficient. This isn't the full method, i use another to return the name with a validation checking the number of the version that this method returns. The problem is, that for some reason, in only a pc it isn't working.