in reply to Win32::TieRegistry and Vista

My first guess would be that you aren't using $^E fast enough and its value is getting overwritten before you report it. This can happen quite quickly. However, if your code is exactly as written, then you are copying the string value of $^E to be part of the string you pass to croak() very quickly, so that seems unlikely. Just in case the unlikely isn't impossible, you might instead add the following code and replace your use of $^E with regLastError():

use Win32API::Registry qw( regLastError KEY_READ );

(which also means that you can use KEY_READ() without having to prepend the lengthy Win32::TieRegistry:: to it.) regLastError() doesn't get overwritten by random Perl actions unlike $^E does.

More likely, Vista disables remote access to the Registry. Can you remotely access the Registry from regedt32/regedit ? I have vague memories of having to turn on this access but I don't recall the details at this time. Hmm, actually that was probably for an old system... but I wouldn't be surprised if something similar were required for Vista as MicroSoft has been disabling a growing number of features in the name of security. This is supported by this item turned up by google: http://www.tabletquestions.com/windows-vista/10066-unable-access-hklm-registry-key-remotely.html

Just to throw out some other ideas that occurred to me but that likely aren't the problem...

Another consideration is the credentials used to connect to the system. Using a command like "net use \\pcname /user:domain\username *" (enter your password when prompted) before running your script can resolve some security issues, especially if you have a more privileged login for use on that machine than the one you are currently using.

I'd also consider looking at the "advanced" privileges associated with your username on that system. I rather expect that Vista doesn't give admins access to remotely access the registry by default. The tools used to control these individual privleges have been shifting so I doubt what works in Vista is what I've used (and I'd have to go look up what I use anyway). But I'd expect that this problem would give a cleared "permission denied" type of error reason.

- tye        

Replies are listed 'Best First'.
Re^2: Win32::TieRegistry and Vista (stabs)
by Shade (Novice) on Jan 23, 2007 at 18:51 UTC
    I added the reference to Win32API::Registry and updated the connect call:
    my $remKey= $Registry->Connect( $pc, $regKeyName, { Access=>Win32::TieRegistry::KEY_READ() } ) or Carp::croak("!! Couldn't connect to $pc or can't open reg key ($r +egKeyName).\n". "!! - Is File and Printer Sharing enabled?\n". Win32API::Registry::regLastError(). "\n");

    Please forgive the package names in the code. This is actually part of my first Perl program (tm), and I applied a package name to my code, so I've been fully qualifying variables from config files, etc.)

    I'm now getting a more explicable error message, Access is denied. I tried using regedit to connect remotely to the Vista box, and was denied access, so this appears to be the root cause, and gives me a quick reality check.

    I will reply once I figure out how to fix the permission issue.

    --- Update 1/23, 13:26 ---

    On the Vista box, I started the Remote Registry Service and set it to Automatic. Now I can connect to the Vista registry remotely, using regedit; however...

    I only have access to HKEY_USERS/ and its subkeys. Frustratingly, HKEY_LOCAL_MACHINE is visible, but presents the following error when I try to access it, Cannot open HKEY_LOCAL_MACHINE: Error while opening key. I've tried tweaking various local security policy settings. I guess this is more of a Windows question at this point. I will try pursuing it further on a Windows forum.