Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Create Process As User

by gautamparimoo (Beadle)
on Mar 09, 2012 at 10:27 UTC ( #958667=perlquestion: print w/ replies, xml ) Need Help??
gautamparimoo has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I need to impersonate another user in my network and run a process under the impersonating user. I could only find the CreateProcessAsUser function in Win32::AdminMisc as a module which can help establish this. Is there any other method. Also ran the code below but i am not able to get results

use Win32::AdminMisc; use Win32; $Domain='con'; $User='administrator'; $Password='**********'; $Process = "cmd /c \"type c:\\autoexec.bat\""; if (Win32::AdminMisc::LogonAsUser($Domain, $User, $Password, LOGON32_L +OGON_INTERACTIVE)) { print "Successfully logged on.\n"; print "\nLaunching ...\n"; $Result = Win32::AdminMisc::CreateProcessAsUser( $Process, "Flags", CREATE_NEW_CONSOLE, "XSize", 640, "YSize", 400, "X", 200, "Y", 175, "XBuffer", 80, "YBuffer", 175, "Title", "Title: $User" . "'s $Pr +ocess program", "Fill", BACKGROUND_BLUE | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN, ); if ($Result) { print "Successful! The new PID is $Result.\n"; } else { print "Failed.\n\tError: " . Win32::FormatMessage(Win32::Admin +Misc::GetError()) . "\n"; } } else { print "Failed to logon.\n\tError".Win32::AdminMisc::GetError(); }

But i am getting the following result.. Successfully logged on. Launching ... Failed. Error: The operation completed successfully. Plz help.. How should i provide a value to $Process?

Comment on Create Process As User
Download Code
Re: Create Process As User
by gautamparimoo (Beadle) on Mar 09, 2012 at 10:32 UTC

    Now it is giving Incorrect function when i pass $Process=cmd.exe

      when i give this value :$process = "C:\\windows\\notepad.exe";

      I am logged in with other user credentials but after that i get Incorrect Function

Re: Create Process As User
by marto (Chancellor) on Mar 09, 2012 at 11:27 UTC

    I've never used this module. It looks as though you're trying to type the autoexec.bat as another user. Either debug what you have or consider using runas.

Re: Create Process As User
by Sinistral (Prior) on Mar 09, 2012 at 15:52 UTC

    Just to help others help the OP, I did not find this module listed in CPAN. I did, however, find it at http://www.roth.net, specifically at http://www.roth.net/perl/adminmisc/. You can also see if there are any Roth scripts that will help. Although the Roth site has a link to an FTP server to get the latest source, that doesn't seem to work. ActiveState doesn't list it in the PPM search engine, either.

    I also found Compiling Win32::AdminMisc on ActiveState 5.10 that describes getting it compiled on ActiveState Perl, but the OP seems to already have the module. That has a link to a Google Code version of the module, but, again, the OP needs help using the module, not getting it installed. Based on the dates of the modules, I suspect there won't be many Monks who can help.

Re: Create Process As User
by pvaldes (Chaplain) on Mar 09, 2012 at 19:37 UTC

    Have you tried this?

    my $Result = Win32::AdminMisc::CreateProcessAsUser( "type c:\\autoexec.bat", "Flags", CREATE_NEW_CONSOLE, ...

    (the name of the proccess is notepad.exe or notepad?)

      Its giving error as Incorrect function

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://958667]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2014-09-30 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (380 votes), past polls