Title: RE: AdminMisc::LogonAsUser

Here is some source that is available off www.roth.net under code samples from David's new  book. I am able to run this on my Win2K Pro system with no problems.

Kind regards,
Trevor J. Joerges
_____________________________________________________________________________
#  RunAs.pl
#  Example 7.14:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script demonstrates how a user can be impersonated and
#  a new process created as the impersonated user.
#
print "From the book 'Win32 Perl Scripting: The Administrator's Handbook' by Dave Roth\n\n";


use Win32::AdminMisc;
my( $Domain, $User ) = ( ( shift @ARGV ) =~ /((.*)\\)?(.*?)$/ )[1..2];
$Password = shift @ARGV;
$Process = join( " ", @ARGV );
print "\nStarting \"$Process\" as $User in the \U$Domain\E domain...\n\n";
$Result = Win32::AdminMisc::LogonAsUser( $Domain,
                                         $User,
                                         $Password,
                                         LOGON32_LOGON_INTERACTIVE );
if( $Result )
{
    $LogonUser = Win32::AdminMisc::GetLogonName();
    print "Successfully logged on as $LogonUser.\n";
    $Result = Win32::AdminMisc::CreateProcessAsUser(
                                $Process,
                                "Flags"  => CREATE_NEW_CONSOLE,
                                "XSize"  => 640,
                                "YSize"  => 400,
                                "X"      => 200,
                                "Y"      => 175,
                                "XBuffer"=> 80,
                                "YBuffer"=> 175,
                                "Show"   => SW_MAXIMIZE,
                                "Title"  => "\u$User\'s $Process program",
                                "Fill"   => BACKGROUND_BLUE    |
                                            FOREGROUND_RED     |
                                            FOREGROUND_BLUE    |
                                            FOREGROUND_GREEN |
                                            FOREGROUND_INTENSITY );
    if( $Result )
    {
        print "Successful! The new processes PID is $Result.\n";
    }
    else
    {
        print "Failed.\n\tError: ", Error(), "\n";
    }
}
else
{
    print "Failed to logon.\n\tError: ", Error(), "\n";
}

sub Error
{
    return( Win32::FormatMessage( Win32::AdminMisc::GetError() ) );
}

_________________________________________________________________________


-----Original Message-----
From: Sheldon Fuchs [mailto:[EMAIL PROTECTED]]
Sent: November 28, 2000 11:11 AM
To: [EMAIL PROTECTED]
Subject: AdminMisc::LogonAsUser


I am having some problems attempting to use Win32::AdminMisc::LogonAsUser,
basically it doesn't work ;-)

I have tried this using both my own domain account, as well as the local
admin for the machine, and still get the error printed, I am using 2k, not
sure if this will make the difference or not. Please, any help would be
appreciated. Here's the code:

if ( ! Win32::AdminMisc::LogonAsUser($Domain, $User, $Password)){
        print "Could not logon\n";
}
else {print "Logon was good\n";}

Of course, it's always "Could not logon". I'm not even certain how to
troubleshoot this (how do I get the last error from windows?) printing the
value of $! just gives "no such file or directory". I'm sure I'm missing
something.

Thanks.
Sheldon
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to