?
Solved

PowerShell Error "OpenRemoteBaseKey" on Remote Window XP system

Posted on 2010-09-03
14
Medium Priority
?
4,400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses

770 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