Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Win32 registry wierdness

by Necos (Friar)
on Sep 19, 2005 at 20:50 UTC ( [id://493300]=perlquestion: print w/replies, xml ) Need Help??

Necos has asked for the wisdom of the Perl Monks concerning the following question:

For starters, I've been using Win32::Registry for a long time. I know people use Win32::TieRegistry now, but I don't believe this to be the root of my problem.

I have some code that fails with "Access is denied" printed in the portions when I print out the Win32 error message. Here's the code I've tested (it works on NT4, so I think this problem is specific to 2000 and higher).
if ( $HKEY_CURRENT_USER->Create('Software\\Policies\\Microsoft\\Intern +et Explorer\\Restrictions', $IE6 ) ) { print "Created IE restrictions!\n"; if ( $IE6->SetValueEx("NoBrowserOptions", 0 , REG_DWORD, 1) ) { print "Disabled browser options\n"; } else { print "Browser options still enabled.\n"; print $^E,$/; } if ( $IE6->SetValueEx("NoBrowserBars", 0 , REG_DWORD, 1) ) { print "Disable changes to browser bars\n"; print $^E,$/; } else { print "Browser bars can be altered still\n"; print $^E,$/; } if ( $IE6->SetValueEx("NoFavorites" , 0 , REG_DWORD, 1) ) { print "Disabled favorites menu\n"; print $^E,$/; } else { print "Favorites menu still enabled\n"; print $^E,$/; } $IE6->Close() && print "Done here!\n"; } else { #print $^E,$/; if ( $HKEY_CURRENT_USER->Create('Software\\Policies\\Microsoft\\In +ternet Explorer', $IE7) ) { print "We have now enabled the restrictions.\n"; if ( $IE7->Create('Restrictions', $IE8) ) { print "Also good!\n"; if ( $IE8->SetValueEx("NoBrowserOptions", 0, R +EG_DWORD, 1) ) { print "Disabled browser options.\n"; } else { print "Browser options not disabled\n" +; print $^E,$/; } if ( $IE8->SetValueEx("NoBrowserBars", 0, REG_ +DWORD, 1) ) { print "Disable changes to browser bars +.\n"; } else { print "Browser bars still can be chang +ed\n"; print $^E,$/; } if ( $IE8->SetValueEx("NoFavorites", 0 , REG_D +WORD, 1) ) { print "Disabled favorites menu.\n"; } else { print "Favorites menu not disabled\n"; print $^E,$/; } $IE8->Close() && print "Restrictions set.\n"; } else { print "Restriction creation failed\n"; print $^E,$/; } $IE7->Close && print "Restriction setup complete.\n"; } else { print "Key creation failed\n"; print $^E,$/; } }

Basically, what this code does is disable some options in Internet Explorer. While I was writing this code, I noticed that the keys don't always exist by default, so they may need to be created. The Create method will do an Open if the key already exists, or create it and then open if it doesn't. I have some other code that modifies some values in the registry that works just fine (it's also in the same script), so there appears to be a problem with creating the key if it does not already exist.

I've been searching google, as well as hitting IRC for days now trying to figure out why I'm getting these errors. Since they code is working on HKEY_CURRENT_USER, there should be no restriction on what keys I can create or modify (since I can modify with no problem). Any help would be appreciated.

Edit: g0n - Added readmore tags

Theodore Charles III
Network Administrator
Los Angeles Senior High
email->secon_kun@hotmail.com
perl -e "map{print++$_}split//,Mdbnr;"

Replies are listed 'Best First'.
Re: Win32 registry wierdness
by randyk (Parson) on Sep 20, 2005 at 03:55 UTC
    Does the user running the script have permission to create keys within HKEY_CURRENT_USER/Software/Policies/Microsoft/Internet Explorer/Restrictions? On XP, if I log in as a user which has such permission (as determined by using regedit to create the keys directly), then the script successfully creates the keys, but if I log in as another user with insufficient permission to create such keys using regedit, then the script fails with the access denied error.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-28 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found