Win32::TieRegistry Logon User Name

Discussion in 'Perl Misc' started by jairagoo@gmail.com, Mar 9, 2005.

  1. Guest

    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
    , Mar 9, 2005
    #1
    1. Advertising

  2. wrote:

    > 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.
    Brian McCauley, Mar 9, 2005
    #2
    1. Advertising

  3. darth Guest

    thank you very much for enlightening me!
    darth, Mar 9, 2005
    #3
  4. darth Guest

    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#######
    darth, Mar 10, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kjell Kristiansson
    Replies:
    0
    Views:
    281
    Kjell Kristiansson
    Nov 30, 2005
  2. January Weiner

    Win32::TieRegistry

    January Weiner, Mar 3, 2006, in forum: Perl Misc
    Replies:
    5
    Views:
    120
    January Weiner
    Mar 6, 2006
  3. Replies:
    6
    Views:
    214
    Paul Lalli
    Jun 1, 2006
  4. MoshiachNow
    Replies:
    0
    Views:
    90
    MoshiachNow
    Nov 21, 2006
  5. Cosmic Cruizer

    Getting permissions using Win32::TieRegistry

    Cosmic Cruizer, Mar 9, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    155
    Cosmic Cruizer
    Mar 17, 2008
Loading...

Share This Page