Solved

PowerShell Error "OpenRemoteBaseKey" on Remote Window XP system

Posted on 2010-09-03
14
4,298 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

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.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

726 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