Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Win32::Registry not working

by samwyse (Scribe)
on Nov 19, 2012 at 23:26 UTC ( #1004634=perlquestion: print w/ replies, xml ) Need Help??
samwyse has asked for the wisdom of the Perl Monks concerning the following question:

I have a laptop running WinXP and non-clustered server running Wndows 2008 R2 Enterprise (64-bit). Both are running ActiveState Perl, v5.12.4 on the laptop; v5.8.something on the server. (Sorry I can't be more precise, I failed to capture that data when I was on the server and can't re-connect to it right now.) On my laptop, the following runs just fine, showing the keys under each path:
my $hKey; foreach my $path ("SOFTWARE", "SOFTWARE\\Microsoft", "SOFTWARE\\Microsoft\\Microsoft SQL Server", "SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names",) { warn "path = $path\n"; $::HKEY_LOCAL_MACHINE->Open($path, $hKey) or die $^E; my @array; $hKey->GetKeys(\@array); warn join(', ', @array), "\n"; }
On the server, the first three paths work, but the third one doesn't show an Instance Names key and the last path returns a "not found" error. If I fire up regedit or regedt32, then all of the paths are present, but there are differences in the displayed sub-keys; the most notable is that the Instance Names key exists but the script shows, for example, the ActiveState key under the top level SOFTWARE path, but regedit doesn't; furthermore, using regedit's Find function doesn't find an ActiveState key anywhere. I can't figure out what's going on. Can anyone please help?

UPDATE: Re-writing to use Win32::TieRegistry did nothing. Upgrading the server to use ActiveState Perl 5.16.1, however, fixed everything.

Comment on Win32::Registry not working
Download Code
Re: Win32::Registry not working
by Athanasius (Prior) on Nov 20, 2012 at 03:15 UTC

    From Win32::Registry:

    NOTE: This module provides a very klunky interface to access the Windows registry, and is not currently being developed actively. It only exists for backward compatibility with old code that uses it. For more powerful and flexible ways to access the registry, use Win32::TieRegistry.

    Have you tried using Win32::TieRegistry instead?

    Athanasius <°(((><contra mundum

      I had the same problem after switching to Win32::TieRegistry. I get this on the server:
      D:\>perl -V Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread [...] D:\>test.pl path SOFTWARE\Microsoft\Microsoft SQL Server subkeys: values: 100\, 90\, DACFramework\, DACProjectSystem\, RefCount\, Servic +es\, SharedManagementObjects\, SqlPubWiz\, TSqlLanguageService\ Can't read SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names key: + The system could not find the environment option that was entered
      However, running regedit and exporting the registry gives me this:
      Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance N +ames] [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance N +ames\OLAP] "MSSQLSERVER"="MSAS10_50.MSSQLSERVER" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance N +ames\RS] "MSSQLSERVER"="MSRS10_50.MSSQLSERVER" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance N +ames\SQL] "MSSQLSERVER"="MSSQL10_50.MSSQLSERVER"
      Upgrading to ActiveState Perl 5.16.1 (the most current version), fixed everything. Curiously, the archname above says "x86" but i downloaded and installed the 64-bit version. I'm now wondering if the 32-bit and 64-bit versions of the Win32 registry APIs see different things.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1004634]
Approved by muba
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-07-12 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (240 votes), past polls