Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32 registry delete 1

Status
Not open for further replies.

bluegroper

Technical User
Dec 12, 2002
407
AU
Hi perl folks
I've been challenged by a small Windoze registry problem.
Specifically, I need to delete an entire branch, ie a single key together with all the values and subkeys of that single key, and values of those subkeys. No exceptions, and no questions asked.
I've looked at all the modules I can find, including Win32::TieRegistry, but they all refuse to delete branches with existing subkeys.
So I made the following code. You can tell that I'm new to perl. I'm glad to say that it works, BUT, can somebuddy show me a better way to write this stuff. All those hex codes are tedious, and make the perl code impossible to read.
Thx for the clues.
Code:
#! /perl -w
# RegFix.pl for Win32
 
#           SYNOPSIS
#           Deletes some pesky registry entries with sub-keys

#           COMPILER DIRECTIVES
#
use strict; use diagnostics;
use English; 
use Win32;

#	VARIABLES
#
my $Debug = 0;                # 1 is debug mode, no update of registry
my $TempRegFile = "$ENV{TEMP}\\TempReg.reg";
my $RegString;

#	SANITY CHECKS
#
open (REGFILE, ">$TempRegFile") or die "Cannot open $TempRegFile : $! \n";

#	MAIN
#

# Create a .reg file
$RegString = "\xFF\xFE\x57\x00\x69\x00\x6E\x00\x64\x00\x6F\x00\x77\x00\x73\x00";
$RegString = "$RegString"."\x20\x00\x52\x00\x65\x00\x67\x00\x69\x00\x73\x00\x74\x00\x72\x00";
$RegString = "$RegString"."\x79\x00\x20\x00\x45\x00\x64\x00\x69\x00\x74\x00\x6F\x00\x72\x00";
$RegString = "$RegString"."\x20\x00\x56\x00\x65\x00\x72\x00\x73\x00\x69\x00\x6F\x00\x6E\x00";
$RegString = "$RegString"."\x20\x00\x35\x00\x2E\x00\x30\x00\x30\x00\x0D\x00\x0A\x00\x0D\x00";
$RegString = "$RegString"."\x0A\x00\x5B\x00\x2D\x00\x48\x00\x4B\x00\x45\x00\x59\x00\x5F\x00";
$RegString = "$RegString"."\x43\x00\x55\x00\x52\x00\x52\x00\x45\x00\x4E\x00\x54\x00\x5F\x00";
$RegString = "$RegString"."\x55\x00\x53\x00\x45\x00\x52\x00\x5C\x00\x53\x00\x6F\x00\x66\x00";
$RegString = "$RegString"."\x74\x00\x77\x00\x61\x00\x72\x00\x65\x00\x5C\x00\x53\x00\x6F\x00";
$RegString = "$RegString"."\x66\x00\x74\x00\x77\x00\x61\x00\x72\x00\x65\x00\x5F\x00\x74\x00";
$RegString = "$RegString"."\x6F\x00\x5F\x00\x64\x00\x65\x00\x6C\x00\x65\x00\x74\x00\x65\x00";
$RegString = "$RegString"."\x5D\x00\x0D\x00\x0A\x00\x0D\x00\x0A";
print REGFILE "$RegString";
close REGFILE;

# Now fix the registry
system "Regedit.exe \/s $TempRegFile > nul: \n" if ($Debug == 0);

exit 0;

And I'm still wondering why the "
Code:
" tags don't work as intended.
 
I'm still wondering why the "[ignore]
Code:
[/ignore]" tags don't work as intended.
Make sure you have a check next to Process TGML below the box where you type your posts.

No help with the Registry problem, I'm afraid.

 
Make sure you have a check next to Process TGML below the box where you type your posts.
Excellent. Thx for solving that little problem. I give you a star.
I wish there was a way to make it check that box by default.

 
Thanks for the star. That box is always checked for me, but I don't remember ever setting that as default. If I did, it was so long ago that I don't remember how or where I did it. Maybe someone else knows?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top