#!/Perl


print "Hello, World...\n";
use strict;
use warnings;
use Win32::Registry;
##use Win32::Registry::File;
##$reg = new Win32::Registry::File('system.reg');
##if ($reg->exists(['system', 'path'])) {
##	print $reg->get(['system', 'path']) . "\n";
##} else {
##	print "reg [system, path] does not exist ...\n";
##}
	# $oldpath = $reg->put(['system', 'path', 'C:\\windows']);
    # if ($reg->exists(['system', 'path'])) ...
    # $reg->delete(['system', 'path']);
    # $reg->save;
## HKEY_CLASSES_ROOT
## HKEY_CURRENT_CONFIG
my $Hkey = HKEY_CURRENT_USER;
## HKEY_LOCAL_MACHINE
## HKEY_PERFORMANCE_DATA
## HKEY_PERFORMANCE_NLSTEXT
## HKEY_PERFORMANCE_TEXT
## HKEY_USERS
my $File = 'File'; # numbered 1 - 16
my $FCnt = 1;
my %KHash = ();
my %K2Hash = ();

##my $Subkey = "Software\\ES-Computing\\EditPlus 2\\Recent File List\\File1";
##my $Subkey = "Software";
##my $Subkey = 'Software\ES-Computing';
##my $Subkey = 'Software\ES-Computing\EditPlus 2';
my $Subkey = 'Software\ES-Computing\EditPlus 2\Recent File List';
my $Reserved = NULL;
my $Sam = KEY_READ;
## KEY_WRITE
## KEY_EXECUTE
## KEY_ALL_ACCESS
my $CurrVer = '';
my $EPList;
my $p = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion';
$HKEY_LOCAL_MACHINE->Open($p, $CurrVer) || die "Open $!";
my @keys = keys %{$CurrVer};
%KHash = %{$CurrVer};
my @k2 = keys %KHash;
my $cnt = scalar @k2;
my $key = '';
my $val = '';
my $class = '';
my $subs = '';
my $vals = '';
my $listref;
print "Version: [$p] ... " . scalar @keys . " ($cnt) key(s) ...\n";
foreach my $k (keys %{$CurrVer}) {
	my $v = ${%{$CurrVer}}{$k};
	print "k=[$k] v=[$v] ...\n";
}
foreach $key (keys %KHash) {
	$val = $KHash{$key};
	print "[$key] = [$val]\n";
}
# REG_SZ		String data
# REG_DWORD		Unsigned four-byte integer
# REG_MULTI_SZ	Multiple strings delimited with NULL
# REG_EXPAND_SZ	Strings that expand (e.g., based on environment variables)
# REG_BINARY	Binary data (no particular format is assumed)
# $parent->Open(keyname, $key)
my $var = '';
$HKEY_CURRENT_USER->Open($Subkey, $EPList) or die "Open $!";
###$EPList->GetKeys($listref);
## $EPList->GetValues($EPList)
$EPList->QueryKey($class, $subs, $vals);
print "Class=[$class], Subs=[$subs] vals=[$vals] \n";
##foreach $key (keys %{$listref}) {
##	print "key=$key\n";
##}
for (my $i = 1; $i < 3; $i++) {
	my $name = $File . $i;
	my $kvar = 'default';
	$EPList->QueryValue($name, $kvar);
	print "$i [$name] = [$kvar] \n";
}

@keys = keys %{$EPList};
%K2Hash = %{$EPList};
@k2 = keys %K2Hash;
$cnt = scalar @k2;
print "HKEY_CURRENT_USER:[$Subkey] ... " . scalar @keys . " ($cnt) key(s) ...\n";
foreach $key (keys %K2Hash) {
	$val = $K2Hash{$key};
	print "[$key] = [$val]\n";
}

my $RegHandle = 0;
Win32::Registry::RegOpenKeyEx($Hkey, $Subkey, $Reserved, $Sam, $RegHandle);
if ($RegHandle) {
	print "Got reg handle ...\n";
	Win32::Registry::RegCloseKey($RegHandle);
} else {
	print "Openning HKEY_CURRENT_USER/$Subkey FAILED!\n";
}

# QueryValue( (out)$value,(out)$type, $name ) 
# (out)$value Value of var $name 
# (out)$type Type of var $name 
# $name Name of value to query. 
# Sets $value, and $type for the specific name value in the current key.
