Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

How to escape space in registry path?

by anaconda_wly (Scribe)
on Nov 20, 2012 at 12:04 UTC ( #1004702=perlquestion: print w/replies, xml ) Need Help??
anaconda_wly has asked for the wisdom of the Perl Monks concerning the following question:

How to escape space in registry path? I tried several ways but failed.

use Win32::TieRegistry( Delimiter => '/' ); $value = $Registry->{ "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Updates/W +indows Server 2003/" } ;

$value always empty. But for below is correct. Apparently, the "Windows Server 2003" is not correctly escaped. Anyone knows how to do? Thanks!

$value = $Registry->{ "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Updates/" +} ;

Replies are listed 'Best First'.
Re: How to escape space in registry path?
by marto (Archbishop) on Nov 20, 2012 at 13:02 UTC

    The examples you posted won't work, each lacks a string terminator (no closing "). The crude example below works for me where there is a space in the key name.

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Win32::TieRegistry( Delimiter => '/' ); my $value = $Registry->{ "HKEY_CURRENT_USER/Software/Microsoft/Windows +/CurrentVersion/Group Policy" } ; print Dumper $value;
      Thanks for your quick response. I double checked my code, I made mistake when paste code to the post, but not in my original code. I tried your keys, it works for me either. I tried many different keys, all works but all keys under "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Updates", including several keys like:"HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Updates/UpdateExeVolatile", no space in it; "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Updates/Windows Server 2003". I don't know why...I refreshed and didn't work. Apparently it's not related to the white space.
        I don't know why

        If you want to know why, then reporting $^E upon failure is the best next step.

        - tye        

Re: How to escape space in registry path?
by Lotus1 (Priest) on Nov 20, 2012 at 18:55 UTC

    After seeing similar problems in your previous question (Read registry error) I'm wondering did you check in regedit that the key exists? What is the OS that you are running this code on?

      Last time I run on Windows7 and can't access the "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft", I forget to mention in that post I had resolved after running the cmd.exe as administrator. That does have difference on Windows7 system. For Win7 I have to run something as administrator, otherwise reading some part in reg may be denied though I do login as administrator.

      This time I'm running on windows 2003 server. I just tried it on Win7 with administrator, but I'm still refused to access the keys under the "Updates", just the same as on win2003.

      I copied the keynames from regedit.exe by right click choosing "Copy Key Name". So I think they should be there. I also refreshed in it. I guess it may still be of some accessibility reason.

        As far as I remember, Windows started "virtualising" filesystem and registry access with Vista / 2003 Server, depending on flags in the EXE header, WOW64, user privileges, and perhaps some other factors. I.e. things are not were you see or search them, some code by Microsoft rewrites the filesystem and registry paths. It's all documented somewhere at, good luck searching ... :-(


        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1004702]
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-10-22 23:47 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (122 votes). Check out past polls.