<?xml version="1.0" encoding="windows-1252"?>
<node id="90834" title="Generic Registry Editor" created="2001-06-22 19:19:18" updated="2005-08-15 05:20:40">
<type id="1748">
sourcecode</type>
<author id="85646">
ralfthewise</author>
<data>
<field name="doctext">
The code is in three parts.  Genericreg.pl, regentry.pm, and reglist.pm.

Genericreg.pl
&lt;CODE&gt;
##############################################################################
#  John McKee
#  6/01/2001
#
#  GenericReg Edits Version 1
#
#  Files:
#  1. Genericreg.pl
#  2. Regentry.pm
#  3. Reglist.pm
#
#  Standard Registry Edits 
#  1.  Command Prompt from Explorer
#  2.  Personalized Bitmap at Logon
#  3.  Don't Display Last User at Logon
#
#  Build Perl version 5.6.1
#
#  Contents Genericreg.pl:
#  1.  Gui
#  2.  6 Subfunctions for registry edits
#
##############################################################################

use Tk;
use Tk::Menubutton;
use Tk::Canvas;
use Win32::Registry;
use regentry;
use reglist;
my ($hkey,$SubKey);

$call_entry = regentry-&gt;new();
$call_list = reglist-&gt;new();

gui();

###################################################################################
#GUI 
###################################################################################
sub gui
{
	my $top = MainWindow-&gt;new();
	$top-&gt;title('Generic Registry Edits');

	
	#menubar frame widget
		$menu = $top-&gt;Frame(-relief=&gt;"raised", -borderwidth=&gt;2);
	#end menubar


	#pulldowns in menubar
		$menu_pulldown1 = $menu-&gt;Menubutton(-text=&gt;"File", -underline=&gt;0);
		$menu_pulldown2 = $menu-&gt;Menubutton(-text=&gt;"Custom", -underline=&gt;0);
	#end pulldowns

	
	#pulldown commands for file menu
	#	$menu_pulldown1-&gt;command(-label=&gt;"Open", -command=&gt;sub{open_choice()});
	#	$menu_pulldown1-&gt;separator();
		$menu_pulldown1-&gt;command(-label =&gt;"Exit", -command=&gt;sub{exit 0});
	#end pulldown commands for file menu


	#pulldown commands for the custom menu
		$menu_pulldown2-&gt;command(-label=&gt;"Create Custom Edits", -command=&gt;sub {$call_entry-&gt;Gui()});
		$menu_pulldown2-&gt;separator();
		$menu_pulldown2-&gt;command(-label=&gt;"List Custom Edits", -command=&gt;sub {$call_list-&gt;Gui()});
		$menu_pulldown2-&gt;separator();
		#$menu_pulldown2-&gt;command(-label=&gt;"Commit Changes from List", -command=&gt; sub{commit_changes()});
	#end pulldown commands for custom menu


	#Buttons
		$button1 =$top-&gt;Button(-text =&gt;"Command Prompt Open from Explorer", -foreground=&gt;"red", -command =&gt;sub{c_prompt()});
		$button2 =$top-&gt;Button(-text =&gt;"Don't Show Last User", -foreground=&gt;"red", -command =&gt; sub{last_user()});
		$button3 =$top-&gt;Button(-text =&gt;"Personalized Logon Bitmap", -foreground=&gt;"red", -command =&gt;sub{bitmap()});
		$button_undo_1 =$top-&gt;Button(-text =&gt;"Undo Prompt", -foreground=&gt;"blue", -command=&gt;sub{undo_c_prompt()});
		$button_undo_2 =$top-&gt;Button(-text =&gt;"Undo Last User", -foreground=&gt;"blue", -command=&gt;sub{undo_last_user()});
		$button_undo_3 =$top-&gt;Button(-text =&gt;"Undo Bitmap", -foreground=&gt;"blue", -command=&gt;sub{undo_bitmap()});
	#end Buttons
	
	
	#Label Area
		$label = $top-&gt;Label(-text =&gt; "Non-Critical Registry Edits", -background=&gt;"DarkSlateGray3", -relief=&gt;"groove", -width=&gt;"30", -height=&gt;"4", -font=&gt;"{Times New Roman} 12 {normal}");
	#end Label Area
	
		
	#text for info button
		$menu_popup = $menu-&gt;Button(-text=&gt;"Help", -underline=&gt;0, -relief=&gt;"flat",-command =&gt; sub
			{
				$newtop = $top-&gt;Toplevel();
				$newtop-&gt;title('Copyright Info');
				$copyright = $newtop-&gt;Button(-text=&gt;"Copyright Info",-command =&gt;sub {system "notepad copyright.txt"});#this button opens a notepad file with instructions
				$copyright-&gt;pack();
				$help = $newtop-&gt;Button(-text=&gt;"Help", -command=&gt; sub {system "notepad front_help.txt"});
				$help-&gt;pack();
				$canvas = $newtop-&gt;Canvas();
				$canvas-&gt;pack();
			});
	#end text for info button
	

	#packs
		$menu-&gt;pack(-side=&gt;'top', -fill=&gt;'x');
		$menu_pulldown1-&gt;pack(-side,'left');
		$menu_pulldown2-&gt;pack(-side,'left');
		$menu_popup-&gt;pack(-side,'right');
		$label-&gt;pack(-side=&gt;"top",-fill=&gt;"x");
		$frame1 =$top-&gt;Frame()-&gt;pack(-fill=&gt;"x",-pady=&gt;"2.5p");  #pack frames and pady 2.5 pixels
		$frame2 =$top-&gt;Frame()-&gt;pack(-fill=&gt;"x",-pady=&gt;"2.5p");  #  "
		$frame3 =$top-&gt;Frame()-&gt;pack(-fill=&gt;"x",-pady=&gt;"2.5p");  #  "
		$button1 =$frame1-&gt;Button(-text =&gt;"Command Prompt Open from Explorer", -foreground=&gt;"red", -command =&gt;sub{c_prompt()})-&gt;pack(-side=&gt;"left",-fill=&gt;"x");
		$button_undo_1 =$frame1-&gt;Button(-text =&gt;"Undo Prompt", -foreground=&gt;"blue", -command=&gt;sub{undo_c_prompt()})-&gt;pack(-side=&gt;"right",-fill=&gt;"x");
		$button2 =$frame2-&gt;Button(-text =&gt;"Don't Show Last User", -foreground=&gt;"red", -command =&gt; sub{last_user()})-&gt;pack(-side=&gt;"left",-fill=&gt;"x");
		$button_undo_2 =$frame2-&gt;Button(-text =&gt;"Undo Last User", -foreground=&gt;"blue", -command=&gt;sub{undo_last_user()})-&gt;pack(-side=&gt;"right",-fill=&gt;"x");
		$button3 =$frame3-&gt;Button(-text =&gt;"Personalized Logon Bitmap", -foreground=&gt;"red", -command =&gt;sub{bitmap()})-&gt;pack(-side=&gt;"left",-fill=&gt;"x");
		$entry1 = $frame3-&gt;Entry(-textvariable =&gt; \$location, -background=&gt;"DarkSlateGray3", -borderwidth=&gt;4)-&gt;pack(-side=&gt;"left");
		$button_undo_3 =$frame3-&gt;Button(-text =&gt;"Undo Bitmap", -foreground=&gt;"blue", -command=&gt;sub{undo_bitmap()})-&gt;pack(-side=&gt;"right",-fill=&gt;"x");
	#end packs
	MainLoop;
}
#End Gui
#**********************************************************************************


#	Standard edits, utilizing the Perl module Win32::Registry.
#	The custom edits in regentry.pm create/utilize *.reg files,
#		(Standard formating of *.reg files).


sub c_prompt
{
	###################################################################################
	#Command Prompt from Windows Explorer Right Click
	###################################################################################
		my $Register = "Directory\\Shell";
		$HKEY_CLASSES_ROOT-&gt;Open($Register,$hkey)|| die $!;
		$hkey-&gt;SetValue("CommandPrompt",REG_SZ,"Command Prompt Here");
		$hkey-&gt;Close();

		my $Register2 = "Directory\\Shell\\CommandPrompt";
		my $commandp = "cmd.exe /k cd %1";
		$HKEY_CLASSES_ROOT-&gt;Open($Register2,$hkey)||die $!;
		$hkey-&gt;SetValue("command",REG_SZ,$commandp);
		$hkey-&gt;Close();
	#**********************************************************************************
}

sub last_user
{
	###################################################################################
	#Don't Display Last User Name
	###################################################################################
		my $Register3 = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon";
		undef $garbage;
		$HKEY_LOCAL_MACHINE-&gt;Open($Register3,$hkey)||die $!;
		$hkey-&gt;SetValueEx("DontDisplayLastUserName",$garbage,REG_SZ,"1");
		$hkey-&gt;Close();
	#**********************************************************************************
}

sub bitmap 
{
	###################################################################################
	#Change Logon Bitmap
	###################################################################################
		my $Register4 = ".DEFAULT\\Control Panel\\Desktop";
		my $bitmap_path = "$location";						# replace '?' with path to desired .bmp.  Use entry box.
		my $LogonBitmap = $bitmap_path;		
		$HKEY_USERS-&gt;Open($Register4,$hkey)||die $!;
		$hkey-&gt;SetValueEx("Wallpaper",$garbage,REG_SZ,$LogonBitmap);
	#**********************************************************************************
}

sub undo_c_prompt
{
	###################################################################################
	#Undo Command Prompt from Explorer
	###################################################################################
		$register6="Directory\\Shell\\CommandPrompt";
		$HKEY_CLASSES_ROOT-&gt;Open($register6,$hkey)||die $!;
		$hkey-&gt;DeleteKey ("Command");
		$hkey-&gt;Close();
		$register6="Directory\\Shell";
		$HKEY_CLASSES_ROOT-&gt;Open($register6,$hkey)||die $!;
		$hkey-&gt;DeleteKey ("CommandPrompt");
		$hkey-&gt;Close();
	#**********************************************************************************
}

sub undo_last_user
{
	###################################################################################
	#Undo Show Last User
	###################################################################################
		$register7="Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon";
		$HKEY_LOCAL_MACHINE-&gt;Open($register7,$hkey)||die $!;
		$hkey-&gt;DeleteValue ("DontDisplayLastUserName");
		$hkey-&gt;Close();
	#**********************************************************************************
}

sub undo_bitmap
{
	###################################################################################
	#Undo Logon Bitmap
	###################################################################################
		$register8=".DEFAULT\\Control Panel\\Desktop";
		$HKEY_USERS-&gt;Open($register8,$hkey)||die $!;
		$hkey-&gt;DeleteValue ("Wallpaper");
		$hkey-&gt;Close();
	#**********************************************************************************
}

&lt;/CODE&gt;

regentry.pm
&lt;CODE&gt;
##############################################################################
#John McKee
#regentry.pm
#
#
#  This is an extension program to genericreg.pl
#  1.   This is a GUI which allows the user to 
#		create a set of custom registry edits
#		and save those edits to a file.
#
#	Unresolved Issues
#	1.  In-Depth Help File
#	2.  Clear all entry boxes when a new radiobutton is pushed
#
##############################################################################

package regentry;
use Tk;
use Tk::Menubutton;
use Tk::Canvas;
use Tk::Entry;
use Tk::Radiobutton;

#Constructor
sub new
{
	bless{};
}
#end constructor

sub Gui
{
	#Gui, Title, and Warning Label
	$top = MainWindow-&gt;new();
	$top-&gt;title('Custom Registry Edits');
	$label = $top-&gt;Label(-text =&gt; "REALLY!\n  Don't do this unless you know\n what you're doing or willing\n to suffer the chaos that\n can ensue from monkeying\n with the all mighty registry hive!", -background=&gt;"DarkSlateGray3", -relief=&gt;"groove", -width=&gt;"32", -height=&gt;"6", -font=&gt;"{Times New Roman} 12 {normal}")-&gt;pack();
	#end Gui, Title, and Warning Label

	#RadioButtons for desired registry hive
	$top-&gt;Radiobutton (-text =&gt; "HKEY_CLASSES_ROOT", -variable=&gt;\$regkey, -value=&gt;"HKEY_CLASSES_ROOT", -activeforeground=&gt;"blue")-&gt;pack();
	$top-&gt;Radiobutton (-text =&gt; "HKEY_CURRENT_USER", -variable=&gt;\$regkey, -value=&gt;"HKEY_CURRENT_USER", -activeforeground=&gt;"blue")-&gt;pack();
	$top-&gt;Radiobutton (-text =&gt; "HKEY_LOCAL_MACHINE", -variable=&gt;\$regkey, -value=&gt;"HKEY_LOCAL_MACHINE", -activeforeground=&gt;"blue")-&gt;pack();
	$top-&gt;Radiobutton (-text =&gt; "HKEY_USERS", -variable=&gt;\$regkey, -value=&gt;"HKEY_USERS", -activeforeground=&gt;"blue")-&gt;pack();
	$top-&gt;Radiobutton (-text =&gt; "HKEY_CURRENT_CONFIG", -variable=&gt;\$regkey, -value=&gt;"HKEY_CURRENT_CONFIG", -activeforeground=&gt;"blue")-&gt;pack();
	$top-&gt;Radiobutton (-text =&gt; "HKEY_DYN_DATA", -variable=&gt;\$regkey, -value=&gt;"HKEY_DYN_DATA", -activeforeground=&gt;"blue")-&gt;pack();
	#end RadioButtons for desired registry hive


	#Labels for Custom Edits
	$regedit = "Enter the registry hive you wish to edit:";
	$create_key = "Enter name of key to create/edit:";
	$create_value = "Enter name of value to create/edit:";
	$memo ="Name for this change:";
	#end Labels


	#Separate Frames for better look
	$frame4 =$top-&gt;Frame()-&gt;pack();
	$frame1 =$top-&gt;Frame()-&gt;pack();
	$frame2 =$top-&gt;Frame()-&gt;pack();
	$frame3 =$top-&gt;Frame()-&gt;pack();
	#end Frames
	
	
	#Label and Entry Boxes with packing
	$label1 = $frame1-&gt;Label(-textvariable =&gt; \$regedit)-&gt;pack(-side=&gt;"left");
	$entry1 = $frame1-&gt;Entry(-textvariable =&gt; \$text)-&gt;pack(-side=&gt;"left");
	$label2 = $frame2-&gt;Label(-textvariable =&gt; \$create_key)-&gt;pack(-side=&gt;"left");
	$entry2 = $frame2-&gt;Entry(-textvariable =&gt; \$text2)-&gt;pack(-side=&gt;"left");
	$label3 = $frame3-&gt;Label(-textvariable =&gt; \$create_value)-&gt;pack(-side=&gt;"left");
	$entry3 = $frame3-&gt;Entry(-textvariable =&gt; \$text3)-&gt;pack(-side=&gt;"left");
	$label4 = $frame4-&gt;Label(-textvariable =&gt; \$memo)-&gt;pack(-side=&gt;"left");
	$entry4 = $frame4-&gt;Entry(-textvariable =&gt; \$name)-&gt;pack(-side=&gt;"left");
	#end Label and Entry Boxes

	#Buttons Save, Close, Help
	#Note: Save button also clears entry boxes
	$top-&gt;Button(-text=&gt;"Save RegEdits to a File", -foreground=&gt;"blue", -command=&gt;sub{save(),$entry1-&gt;delete( 0, 'end' ),$entry2-&gt;delete( 0, 'end' ),$entry3-&gt;delete( 0, 'end' ),$entry4-&gt;delete( 0, 'end' )})-&gt;pack(); #sub to save selections 
	$top-&gt;Button(-text=&gt;"Close", -foreground=&gt;"blue", -command=&gt; sub {$top-&gt;destroy()})-&gt;pack();
	$top-&gt;Button(-text=&gt;"Help (Don't be afraid to use this)", -foreground=&gt;"white", -background=&gt;"red", -command=&gt;sub {system "notepad regentry_hlp.txt"})-&gt;pack();
	#end Buttons
	
	MainLoop;
}
#End Gui
#*****************************************************************************


	##########################################################################
	#Filehandler for the custom edits
	#Creates *.reg files based on the name &amp; values given in the entry gui
	##########################################################################
		sub save ()
		{
			open (FD, "&gt;$name.reg")||die "Unable to open storage file";
			print FD "REGEDIT4\n\n[$regkey\\$text]\n\"$text2\"=\"$text3\"\n";
			close (FD);
		}
	#*************************************************************************

	return 1;
&lt;/CODE&gt;


and finally reglist.pm
&lt;CODE&gt;
##############################################################################
#John McKee
#reglist.pm
#
#
#  This is an extension program to genericreg.pl
#  1.   This creates a listbox from *.reg's in pwd,
#		which were created by the user via
#		custom registy edits.
#  2.	It lists the name of the regstry edits that
#		the user requires and allows that user
#		to select more than one, if so desired.
#		And allow the user to delete edits no
#		longer required
#
##############################################################################

package reglist;
use Tk;

#Constructor
sub new
{
	bless{};
}
#end Constructor

sub Gui
{
	undef(@selections);
	my $top = MainWindow-&gt;new();
	$top-&gt;title('Listing of Custom Registry Edits');

	#Listbox widget
	$listbox = $top-&gt;ScrlListbox(-label=&gt;"Custom Edits", -height=&gt;6, -selectmode =&gt;"extended", -background=&gt;"DarkSlateGray3");
	#end listbox widget
	
	#Buttons (Exit, Delete, and Select)
	$exitbutton = $top-&gt;Button(-text =&gt;"Exit", -command=&gt;sub {$top-&gt;destroy()});
	$deletebutton = $top-&gt;Button(-text=&gt;"Delete", -command=&gt;\&amp;del_selection);
	$selectbutton = $top-&gt;Button(-text=&gt;"Select", -command=&gt;\&amp;proc_selection);
	$okbutton = $top-&gt;Button(-text=&gt;"Commit Changes", -command=&gt;\&amp;commit_changes);
	#end buttons

	#Sunken Selection Frame	
	$frame = $top-&gt;Frame(-relief =&gt;"ridge", -relief=&gt;"raised", -borderwidth =&gt;4, -background=&gt;"DarkSlateGray4");
	$label = $frame-&gt;Label(-text =&gt;"Selected: ",-background=&gt;"DarkSlateGray3");
	$entry = $frame-&gt;Label(-textvariable =&gt; \$seltext, -relief=&gt;"sunken", -background=&gt;"white");
	#end Frame

	#packs
	$listbox-&gt;pack(-fill=&gt;"both", -expand=&gt;"yes");
	$exitbutton-&gt;pack(-side=&gt;"left");
	$selectbutton-&gt;pack(-side=&gt;"left");
	$deletebutton-&gt;pack(-side=&gt;"right");
	$okbutton-&gt;pack(-side=&gt;"right");
	$frame-&gt;pack(-side=&gt;"right", -anchor=&gt;"se",-expand=&gt;"yes",-fill=&gt;"x");
	$label-&gt;pack(-side=&gt;"left");
	$entry-&gt;pack(-side=&gt;"left");
	#end packs	
		
	
	##########################################################################
	#  Gets all *.reg files from pwd an insert into listbox
	##########################################################################
		open (FD, "dir /B *.reg |") || die "Unable to read";
		while (&lt;FD&gt;)
		{
			chop;										#Cut newline
			$listbox-&gt;insert("end","$_");				#pull *.reg's into listbox
		}
		close (FD);
	#*************************************************************************
	
	$seltext=proc_selection();

MainLoop;
}

sub proc_selection
{
	##########################################################################
	#	Store the selections the user makes
	##########################################################################
		$seltext=join(', ',$listbox-&gt;Getselected);  
		push (@selections,$listbox-&gt;Getselected);	#stored in @selections
	#*************************************************************************
}

sub del_selection
{
	##########################################################################
	#	Deletes selected Registry edits
	##########################################################################
		$del_choice = $listbox-&gt;get('active');		#gets highlighted selection(s)
		$listbox-&gt;delete('active');					#deletes from listbox
		system ("erase $del_choice");				#deletes from directory
	#*************************************************************************
}

sub commit_changes
{
	##########################################################################
	#	Reads selection list from the list box and commits those changes
	#	to the registry after the user hits the commit changes button
	##########################################################################
		foreach (@selections)
		{
			system ($_);							#uses crackjack $_ to run
		}											#each *.reg selected
	#*************************************************************************
}

return 1;
&lt;/CODE&gt;
</field>
<field name="codedescription">
The is a gui driven registry editor for network admins.  It allows admins to create standard registry edits for workstation builds, maintenance, etc.</field>
<field name="codecategory">
NT Admin, GUI Programming</field>
<field name="codeauthor">
John McKee
ralfthewise@hotmail.com</field>
</data>
</node>
