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

I'm using the AdminMisc module to try to rename Windows NT user accounts, but is having no success. I'm a domain admin and have all the right and privledges I need. Does anyone have an idea why this is not working?

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

    Have you tried the Monk's ritual?


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

Re: Renaming User Accounts
by jonnyfolk (Vicar) on Oct 16, 2003 at 16:05 UTC

    I suspect that it'll boil down to something in your script that's not correct.

    Hope that helps...

      Hello AM,
      What jonnyfolk was trying to say {grin} was that if you try posting some of your code (the relevant bit/s) we might have a snowballs chance in hell of helping you.

      Also a somewhat more detailed account of exactly why you are "having no success" might in fact be useful, think about posting error messages or relevant parts from error logs.

      The wonderful jeffa has posted a nice node about how _not_ to ask a question, a quick read before posting again would probably be very beneficial.

      Anyhow, welcome to the monastery. :)

      # 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.

        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!

        If you put nicely indented code between <code> and </code>, it becomes much more readable.
        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.