Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PowerShell Error "OpenRemoteBaseKey" on Remote Window XP system

Posted on 2010-09-03
14
Medium Priority
?
4,523 Views
Last Modified: 2012-05-10
I'm getting this error when I attempt to run code to access the registery on a Windows XP machine (with admin creditals):

PS Y:\> .\get-instprogv1.ps1 <computer name> <output file>
Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found.
"
At Y:\Get-InstProgv1.ps1:36 char:62
+     $registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey <<<< ($hkey, $computer);
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
 
You cannot call a method on a null-valued expression.
At Y:\Get-InstProgv1.ps1:38 char:44
+         $reg_uninstall_key = $registry.OpenSubKey <<<< ($reg_uninstall_path);
    + CategoryInfo          : InvalidOperation: (OpenSubKey:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The code looks like this:

 
param($strComputer,$outFile)

#The purpose of this program is to run against a specific system to
#pick out the LITTERAL appliation name and version name in order to 
#fill out the AppListv2010.csv file.  That file is used to determine 
#installation status of the applications provided in the list, but it
#MUST be exactly copied from the resulting text file.
#
#This application searches both the 32bit and 64bit registry nodes for software.

If (($strComputer -eq $null) -or ($outFile -eq $null))
	{Write-Host "Please enter a computer and path:filename.txt"
	 Write-Host "ex. Get-IntalledPrograms.ps1 1310-A c:\1310-A.txt"
	 exit
	}
ElseIF ((Test-Connection -Computername $strComputer -quiet) -ne $True)	
	{
	Write-Host "Unable to connect to $strComputer"
	exit
	}

function Get-InstalledPrograms($computer = '.') { 

$programs_installed = @{};
$error_action = 'Stop';
$reg_uninstall_paths = @('Software\Microsoft\Windows'`
	+ '\CurrentVersion\Uninstall');

$reg_uninstall_paths += @('Software\Wow6432Node\Microsoft'`
	+ '\Windows\CurrentVersion\Uninstall');
	$hkey = 'LocalMachine';
	
	$registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hkey, $computer);
	foreach ($reg_uninstall_path in $reg_uninstall_paths) {
		$reg_uninstall_key = $registry.OpenSubKey($reg_uninstall_path);
		if ($reg_uninstall_key -eq $null) {
			continue;
		}
		$key_names = $reg_uninstall_key.GetSubKeyNames();
		foreach ($key_name in $key_names) {
			$key_properties = $reg_uninstall_key.OpenSubKey($key_name);
			$name = $key_properties.GetValue('DisplayName');
			$version = $key_properties.GetValue('DisplayVersion');
			if ($name -ne $null) {
				$programs_installed.$name = $version;
			}
			$key_properties.close();
		}
		$reg_uninstall_key.close();
	}
	$registry.close();
	
	$reg_uninstall_paths = @('Software\Microsoft\Installer\Products');
	$hkey = 'CurrentUser';

	$registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hkey, $computer);
	foreach ($reg_uninstall_path in $reg_uninstall_paths) {
		$reg_uninstall_key = $registry.OpenSubKey($reg_uninstall_path);
		if ($reg_uninstall_key -eq $null) {
			continue;
		}
		$key_names = $reg_uninstall_key.GetSubKeyNames();
		foreach ($key_name in $key_names) {
			$key_properties = $reg_uninstall_key.OpenSubKey($key_name);
			$name = $key_properties.GetValue('ProductName');
			$version = $key_properties.GetValue('DisplayVersion');
			if ($name -ne $null) {
				$programs_installed.$name = $version;
			}
			$key_properties.close();
		}
		$reg_uninstall_key.close();
	}
	$registry.close();
	
	
return $programs_installed;
} 

Get-InstalledPrograms $strComputer | Format-List | Out-File $outFile

Open in new window


Why would this work on some machines, and not others.... I can PING all of the systems, weather is runs or not...

Update:  I'm getting "Access Denied" errors when attempting remote computer management...
0
Comment
Question by:gerhardub
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
14 Comments
 
LVL 1

Author Comment

by:gerhardub
ID: 33621277
Anyone?
0
 
LVL 1

Author Comment

by:gerhardub
ID: 33649021
So I take it no one has a clue to this one?

GB
0
 
LVL 22

Expert Comment

by:Adam Leinss
ID: 33665767
If you can't remote manage a computer, check the local administrators group on the remote PC to make sure your account is listed (or are in the group(s) listed).
Also make sure the Remote Registry and Server services are running on the remote PC.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 1

Author Comment

by:gerhardub
ID: 33666523
Yepper, I've got all of those rights, and the services are running.
0
 
LVL 22

Expert Comment

by:Adam Leinss
ID: 33666545
The only other thing I can think if is if remote connections are being treated as guest connections, see http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_21392654.html on how to check that on the remote PC.
0
 
LVL 1

Author Comment

by:gerhardub
ID: 33704355
I still have yet as to look into this last comment, which will be done on Monday!
0
 
LVL 1

Author Comment

by:gerhardub
ID: 33888782
That doesn't appear to be the issue....
0
 
LVL 22

Accepted Solution

by:
Adam Leinss earned 2000 total points
ID: 33888857
I have no further ideas.  If the firewall is off, remote registry is on and you have admin rights on the box you are launching the script from and admin rights on the box you are targeting, it should work.
0
 
LVL 1

Author Closing Comment

by:gerhardub
ID: 34055168
It would have been helpful to have a remote registry GPO pointer... but that DID end up being the issue.

0
 
LVL 22

Expert Comment

by:Adam Leinss
ID: 34055193
Remote Registry is just a service, are you saying that a GPO was turning it off?
0
 
LVL 1

Author Comment

by:gerhardub
ID: 34058159
It wasn't defined in the AD policies, so basically, it was a matter of a few systems had it turned off, and Windows 7 machines had it off by default.
0
 
LVL 22

Expert Comment

by:Adam Leinss
ID: 34058203
Understood.  I always flip those on when I build an image.  I can see it being turned off in 7 due to security hardening, but I would have thought it comes out of the box turned on on XP.
0
 
LVL 1

Author Comment

by:gerhardub
ID: 34058525
Yeah, that's what stumped me... it was only a few systems... not all of them. (XP wise)

7, they're were one of two that would have it on, and all of the other had is off.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question