in reply to Re: Renaming User Accounts
in thread Renaming User Accounts

# rename_user.pl # # use win32; use Win32::AdminMisc; use Win32::NetAdmin; # Define variables $PDC = "MDCRES02"; $Domain = "SILVER"; open (LOG, ">c:\\scripts\\namelog.txt") or die "Could not open permslo +g.txt log file\n"; open (ERROR,">c:\\scripts\\errorusers.txt") or die "count not open err +orusers.txt log file\n"; print LOG "==> opening file namelog.txt\n"; print LOG "==> opening file errorusers.txt\n"; if (open (LIST,"c:\\scripts\\dupaccounts.csv")) { print LOG "==> opening file dupaccounts.csv\n"; while (chomp($list = <LIST>)) { split_input_file(); renameuseraccount(); } }else{ system(cls); $error = " ? Could not open dupaccounts.csv"; print $error; } # ############################## SUBROUTINES #################### +##################### # Split input file # Use the split function to extract user info sub split_input_file { ($Tit_UserAccount, $Sil_UserAccount) = split(/,/,$list); } sub renameuseraccount { system(cls); if (Win32::NetAdmin::UsersExist($PDC,$Sil_UserAccount)) { + print "==> User $Sil_UserAccount exist\n"; print LOG "==> User $Sil_UserAccount exist\n"; if (Win32::AdminMisc::RenameUser($Domain, $Sil_UserAccount +, $Tit_UserAccount)) { print LOG "==> Renamed $Sil_UserAccount to $Tit_UserAc +count\n"; print "==> Renamed $Sil_UserAccount to $Tit_UserAccoun +t\n"; }else{ print LOG "==> Could not rename $Sil_UserAccount\n"; print "==> Could not rename $Sil_UserAccount"; print ERROR "$Sil_UserAccount\n"; } }else{ print LOG "==> the user $Sil_UserAccount does not exist\n" +; print "==> the user $Sil_UserAccount does not exist\n"; + } }
Edited by castaway - added code tags.

Replies are listed 'Best First'.
Re: Re: Re: Renaming User Accounts
by BrowserUk (Patriarch) on Oct 17, 2003 at 00:02 UTC

    FWIW, I couldn't get your version of the script nor the RenameUser.pl that comes with the Win32::AdminMisc module to do anything either.

    The total absence of any mention of the RenameUser() api in either the module itself or the pod that comes with the module make it very difficult to track down the likely cause. The function exists in the dll (apparently, as perl doesn't complain when you try to use it) but when I tried running the test script that came with the module I got

    P:\site\lib\Win32\AdminMisc>renameUser Attempting to rename the user account 'fred' to 'derf' Could not rename the user 'fred' to 'derf': The operation completed su +ccessfully. Finished.

    Which is somewhat confusing:)

    The best suggestion I can think of is that you try contacting Dave Roth via his web site or CPAN id.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!

Re: Re: Re: Renaming User Accounts
by Jaap (Curate) on Oct 16, 2003 at 19:00 UTC
    If you put nicely indented code between <code> and </code>, it becomes much more readable.
Re: Re: Re: Renaming User Accounts
by jacques (Priest) on Oct 16, 2003 at 20:43 UTC
    Yes, I understand now. Try:

    BEGIN{$x='s!.!chr(ord($&)+1+0)!eg;';$t=shift@ARGV;} END{$x=~s/\+/-/;$x=~s#0#'time()/'.(time+$t*86400)#e; print"\n$0\n$x\$SIG{'__WARN__'}=sub{}; eval or die \"Evaluation time expired\\n\";"} $.==1 and $_.="\$_ = <<'$0';\n" and next; eval$x;

    Update: this isn't funny anymore since his code has been updated.