0

Looking at other articles and even this StackOverflow question, I still can't get this to work. The machine is contactable on the network but still produces an IO error.

The is the code I'm using:

var environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "gm-1015").OpenSubKey("Environment");
TextBox1.Text = environmentKey.ToString();

When I try to run it, I get:

System.IO.IOException: 'The network path was not found.

Which from Microsoft's website indicates that the machine is not accessible.

Am I missing something?

Community
  • 1
  • 1
I.T Delinquent
  • 2,305
  • 2
  • 16
  • 33

1 Answers1

0

Came to the conclusion that the remote registry service wasn't enabled or turned on for the remote computer. Instead of enabling it which would open another door into the computer for any intruders, I use the below code:

PowerShell ps = PowerShell.Create()
    .AddCommand("Invoke-Command")
    .AddParameter("ComputerName", SearcherClass.CurrentComputer)
    .AddParameter("Scriptblock", ScriptBlock.Create("Get-Tpm | Select-Object -ExpandProperty TPMPresent"));

This starts a new PowerShell instance and runs the Invoke-Command to eventually run the Get-Tpm command which ultimately returns the TPMPresent property

This is the actual code block that I used to evaluate and return a usable result to my form:

public static string GetTPM()
{
    string output = "N/A";
    try
    {
        PowerShell ps = PowerShell.Create()
            .AddCommand("Invoke-Command")
            .AddParameter("ComputerName", SearcherClass.CurrentComputer)
            .AddParameter("Scriptblock", ScriptBlock.Create("Get-Tpm | Select-Object -ExpandProperty TPMPresent"));

        foreach(PSObject i in ps.Invoke())
        {
            output = i.BaseObject.ToString();
        }
        if (output == "True")
        {
            output = "Present";
        }
        else
        {
            output = "None";
        }
        return output;
    }
    catch
    {
        return "Failed";
    }
}
I.T Delinquent
  • 2,305
  • 2
  • 16
  • 33