softworkz has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks! Before we image our machines we copy the C:\Documents and Settings folder onto the network and after the new image is complete we manually copy the C:\Documents and Settings folder back onto the machine. This way users can still have their settings etc... I know I can write a script to do the copying for me but I think it would be easier to find a way to tie it into when the user logs in for the first time on the new imaged machine. Where I'm stuck is how to get the user name when they log in so the script can go and look on the network to see if the user has a C:\Documents and Settings\userfolder to copy onto the new imaged machine. Any advice? Thanks!!

Replies are listed 'Best First'.
Re: win32 get login name
by jlongino (Parson) on Jan 09, 2002 at 20:59 UTC
    I believe:
    use Win32; $login = Win32::LoginName;
    will do what you want. For more detailed information, you can also use this snippet from Learning Perl on Win32 Systems (co-authored by our own merlyn):
    use Win32::NetAdmin; $user = Win32::LoginName; # grab the name of the current user Win32::NetAdmin::UserGetAttributes("", $username, $password, $passwordage, $privilege, $homedir, $comment, $flags, $scriptpath); print "The homedir for $username is $homedir\n";
    HTH,

    --Jim

    Update: Glad it works for you, although cut/paste may have caused you to drop a semicolon after your "my $profile" statement, but otherwise works for me!

      Thanks Jim!!
      Here's what I have so far, getting the book :)
      #!/usr/bin/perl -w use strict; use Win32; my $username = Win32::LoginName(); my $path = "u:\\profiler\\$username"; my $profile = "C:\\Documents and Settings\\$username" stat($path); exit if !-e _; # exit if the profile is not found system ("xcopy /i $path $profile");