Solved

PowerShell Error "OpenRemoteBaseKey" on Remote Window XP system

Posted on 2010-09-03
14
4,214 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
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…

697 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