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

I wrote this program to change local admin password or any local users password, but i also made it so that i can do it on a mass level of 100 or more computers. The only problem is the program locks up until it is done and then prints out the information. I want it to print out the info as it goes along and also so that it does lock up. If any one can modify my code and send it back to me or atleast point me in the right direction. If you want to test out the code make sure you put "\\" in front of the computer name
use Tk; use TK::Dialog; use Win32::AdminMisc; use Win32::GUI; open (OUTPUT, ">Error.txt"); select(OUTPUT); $| = 1; my $DOS = Win32::GUI::GetPerlWindow(); Win32::GUI::Hide($DOS); ###################################################################### +###### my $mw = MainWindow->new; my $c = $mw->Canvas( -width =>582, -height=>450); $c->pack; ###################################################################### +###### sub Exec { if ($server =~ m/txt/) { open(DAT, $server) or die "Could not open file!\n"; @computers=<DAT>; close(DAT); foreach $computer(@computers) { if ($computer =~ /\n/) { chomp($computer); } } } else { @computers = $server; } foreach $computer(@computers) { print OUTPUT "$computer\n"; $text->insert("end", "$computer\n"); if ($CheckRenameAdmin) { AdminRename(); } if ($CheckAdminPassword) { AdminPasswordSet(); } if ($CheckRenameGuest) { GuestRename(); } if ($CheckDisableGuest) { GuestDisable(); } my $break = "================================================= +\n"; print OUTPUT "$break"; $text->insert("end", "$break"); } } ###################################################################### +############## sub Quit { my $d = $mw->Dialog( -text => "Are you sure you want to quit?", -buttons => ["Yes", "No"]); my $answer = $d->Show(); close(OUTPUT); exit if ($answer eq "Yes") } ###################################################################### +############## sub GuestRename { my $Guestuser = "Guest"; my $NewGuestUser = "DisabledGuestAccount"; my $Guest = Win32::AdminMisc::RenameUser($server, $Guestuser, $New +GuestUser); if($Guest == 1) { $GuestRenameText = "The user $Guestuser was changed to $NewGue +stUser\n"; } else { $GuestRenameText = "The user $Guestuser was not changed to $Ne +wGuestUser\n"; print OUTPUT "$GuestRenameText"; } $text->insert("end", $GuestRenameText); } ###################################################################### +############## sub GuestDisable { my $NewGuestUser = "DisabledGuestAccount"; my $GuestDisable = Win32::AdminMisc::UserSetMiscAttributes($server +, $NewGuestUser, USER_FLAGS => UF_ACCOUNTDISABLE | UF_PASSWD_CANT_CHANGE | UF_D +ONT_EXPIRE_PASSWD); if($GuestDisable == 1) { $GuestDisableText = "The Guest Account has been disabled\n"; } else { $GuestDisableText = "The Guest Account was not disabled\n"; print OUTPUT "$GuestDisableText"; } $text->insert("end", "$GuestDisableText"); } ###################################################################### +############### sub AdminRename { my $AdminRename = Win32::AdminMisc::RenameUser($server, $Adminuser +, $NewAdminUser); if($AdminRename == 1) { $AdminRenameText = "$Adminuser has been renamed to $NewAdminUs +er\n"; } else { $AdminRenameText = "$Adminuser has not been renamed to $NewAdm +inUser\n"; print OUTPUT "$AdminRenameText"; } $text->insert("end", "$AdminRenameText"); } ###################################################################### +############### sub AdminPasswordSet { $AdminPasswordSet = Win32::AdminMisc::SetPassword($server, $NewAdm +inUser, $AdminPass); if($AdminPasswordSet == 1) { $AdminPasswordSetText = "Admin password has been set\n"; } else { $AdminPasswordSetText = "Admin password has not been set\n"; print OUTPUT "$AdminPasswordSetText"; } $text->insert("end", "$AdminPasswordSetText"); } ###################################################################### +################# $mw->title("Admin Tools"); $text = $mw->Scrolled('Text', -scrollbars => 'seo'); $lab = $mw->Label( -text => 'Select your choices'); $quit = $mw->Button( -text => "Quit", -command => \&Quit); $run = $mw->Button( -text => "Run", -command => \&Exec); $adminrename = $mw->Checkbutton( -text => "Rename Admin Account", -variable => \$CheckRenameAdmin ); $adminSetPass = $mw->Checkbutton( -text => "Set Admin Password", -variable => \$CheckAdminPassword ); $Guestrename = $mw->Checkbutton( -text => "Rename Guest Account", -variable => \$CheckRenameGuest ); $GuestDisable = $mw->Checkbutton( -text => "Disable Guest Account", -variable => \$CheckDisableGuest ); $Servername = $mw->Entry( -textvariable => \$server ); $Adminpass = $mw->Entry( -textvariable => \$AdminPass ); $TextAdminPass = $mw->Label( -text => "New Admin Password:"); $TextServerName = $mw->Label( -text => "Enter computer or .txt file:"); $OldAdmin = $mw->Entry( -textvariable => \$Adminuser ); $NewAdmin = $mw->Entry( -textvariable => \$NewAdminUser ); $TextAdminUser = $mw->Label( -text => "Enter the Current Admin username:"); $TextNewAdminUser = $mw->Label( -text => "Enter the New Admin username:"); $adminrename->place(-x =>0, -y => 15); $Guestrename->place(-x =>0, -y => 32); $adminSetPass->place(-x =>0, -y => 49); $GuestDisable->place(-x =>0, -y => 64); $text->place(-x => 4, -y => 89); $quit->place(-x => 540, -y => 57); $run->place(-x => 500, -y => 57); $lab->place(-x => 0, -y => 0); $Servername->place(-x => 180, -y => 19); $Adminpass->place(-x => 180, -y => 57); $TextAdminPass->place(-x => 187, -y => 38); $TextServerName->place(-x => 180, -y => 0); $OldAdmin->place(-x => 360, -y => 19); $NewAdmin->place(-x => 360, -y => 57); $TextAdminUser->place(-x => 340, -y => 0); $TextNewAdminUser->place(-x => 340, -y => 38); MainLoop; Win32::GUI::Show($DOS) ;

Edit: g0n readmore tags

Replies are listed 'Best First'.
Re: Increase response time
by liverpole (Monsignor) on May 11, 2006 at 14:37 UTC
    Hi SteveS832001,

    My guess would be that everywhere you do:

    $text->insert(...);
    you should include an update as well:
    $text->insert(...); $mw->update();

    It's also a good idea to put use strict and use warnings at the top of your program, as they will help you catch a lot of things that might otherwise go unnoticed.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Increase response time
by BrowserUk (Patriarch) on May 11, 2006 at 15:50 UTC
    but i also made it so that i can do it on a mass level of 100 or more computers.

    How about if you work out how to make your mass rename work, then come back and ask about improving response times.

    Hint: In your code each call to Win32::AdminMisc looks something like:

    my $thing = Win32::AdminMisc::RenameUser($server, ...

    but when you use your mass rename facility, the variable $server is set to a filename with '.txt' on the end:

    if ($server =~ m/txt/) { open(DAT, $server) or die "Could not open file!\n"; @computers=<DAT>; close(DAT); foreach $computer(@computers) { if ($computer =~ /\n/) { chomp($computer); } }

    So that isn't going to work. You should really learn to pass parameters to your subroutines instead of using global variables. It makes this sort of thing much easier to see.

    BTW. The last 5 lines above are effectively the same as

    chomp @computers;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      It already does it on a mass level i was just letting everyone know

        In that case, you will not be interested in this version of your code that runs clean under strict and warnings and is now in a form that would make it easy to run the updates 10, or 20 or even 100 machines at a time in parallel.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.