Solved

PowerShell Error "OpenRemoteBaseKey" on Remote Window XP system

Posted on 2010-09-03
14
4,153 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

839 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