Win32::TieRegistry Logon User Name

J

jairagoo

Hail All,
I am trying to write a script that looks at all my windows computers
within a subnet and return the "Computer Name and Logon on users". My
attempt below returns the computername appropriately but it doesn't
return the "Logon User Name". I physically look at the registry and see
the user's name there but this script does not return that value.
Someone please help ;-)

######OUTPUT########
10.2.4.29=> => COMPUTER5
10.2.4.30=> => COMPUTER0
10.2.4.31=> => COMPUTER6
10.2.4.32=> => COMPUTER9
10.2.4.33=> => COMPUTER4
10.2.4.35=> => COMPUTER2
#####################

#!c:\perl\bin\perl
use Win32::TieRegistry;

my @subnet =qw(4);
foreach $subnet (@subnet) {
for (my $i=1;$i <100;$i++){
$computer = qq(10.2.$subnet.$i);
$pinger=`ping -n 1 $computer`;
if($pinger=~ /Reply from/) {

$username=$Registry->{"\\\\$computer\\CUser\\Software\\Microsoft\\"
."Windows\\CurrentVersion\\Explorer\\\\Logon User Name"};
$computerName=$Registry->{"\\\\$computer\\LMachine\\SYSTEM\\"
."CurrentControlSet\\Control\\ComputerName\\ComputerName\\\\"
."ComputerName"};
print "$computer=> $username=> $computerName\n";
}
}
}

thank you.
Darth
 
B

Brian McCauley

I am trying to write a script that looks at all my windows computers
within a subnet and return the "Computer Name and Logon on users". My
attempt below returns the computername appropriately but it doesn't
return the "Logon User Name". I physically look at the registry and see
the user's name there but this script does not return that value.

The 'CUser' top level registry key is a link to the user profile
registry hive of the user that is looking at the registry.

AFAIK it can only be used for interrogating the local registry. Even if
it could be used on remote registries it would show you the content of
_your_ user profile registry hive on that box, not the registry hive of
the user sitting at the screen/keyboard.

You can traverse the 'HKEY_USERS' section of the registry to find out
all the users who currently have profiles loaded but I do not know how
to tell which (if any) have true interactive desktops.

Your problem has very little to do with Perl, if you need futher help I
suggest you try a newsgroup that deals with the Windows operating system.
 
D

darth

as a matter of completeness I submitt my code that would extract the
current logon users from the registry with Win32::TieRegistry. you can
use it to Interrogate all the computer in your subnet (if you have
Admin access to them, that is.)
any further suggestions would be appreciated.

###########CODE#########################
## Enjoy: Jai Ragoo
use Win32::TieRegistry( Delimiter=>"/", ArrayValues=>0 );
use Net::ping;

my @subnet =qw(4);

foreach $subnet (@subnet) {
for (my $i=1;$i <5;$i++){
my $computerName="",$ip="",,$username="";;
$ip = qq(192.168.$subnet.$i);
#$ip="venus"; ### you can also check nbt names or FQDN of your
clients
$p=Net::ping->new(tcp);
if($p->ping($ip)) {

if($computerName =
$Registry->{"//$ip/LMachine/SYSTEM/CurrentControlSet/"
."Control/ComputerName/ComputerName//ComputerName"})
{}else {print "can't connect get ComputerName $^E";}

print "$ip => $computerName logged on user(s):\n";

if ($userData=$Registry->{"//$ip/Users"}){
foreach $subKey ($userData->SubKeyNames)
{
if ($subKey=~/(\d+-\d+-\d+-\d+)_Classes/)
{
if
($username=$Registry->{"//$ip/Users/S-1-5-21-$1/Software/Microsoft/"
."Windows/CurrentVersion/Explorer//Logon User
Name"})
{ print "\t$username\n"; }
else {print "no user found";}
}
}
} # if ($userData=$Registry->{"//$ip/Users"}){
} #for (my $i=1;$i <5;$i++){
} #for (my $i=1;$i <5;$i++){
} # foreach $subnet (@subnet) {
#########END OF CODE#######
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top