I am trying to use CreateProcessWithLogonW with Win32::API and cannot seem to get it to work. It always returns "The parameter is incorrect". Any ideas what I am doing wrong?
#!perl
use strict;
use Win32::API;
my $user="username";
my $pass="password";
print createProcessWithLogon('notepad.exe',$user,$pass);
exit;
###############
sub createProcessWithLogon{
my $program=shift;
my $username=shift;
my $password=shift;
my $LOGON_NETCREDENTIALS_ONLY = 0x2;
my $CREATE_NEW_CONSOLE = 0x10;
my $CreateProcessWithLogon = new Win32::API('advapi32.dll', 'Creat
+eProcessWithLogonW', ['P','P','P','P','P','P','P','P','P','P','P'],'N
+') || return $^E;
print "calling[$program,$username,$password]\n";
#Set Flag
my $dwFlags = 1; # STARTF_USESHOWWINDOW
$dwFlags |= 0x100; # STARTF_USESTDHANDLES otherwise we inherit t
+he parents handles on 98
# SW_HIDE=0 SW_SHOWNORMAL=1 SW_SHOWMINIMIZED=2
my $show=1;
my $si = pack("LLLLLLLLLLLL SS LLLL",68,0,0,0,0,0,0,0,0,0,0,$dwFla
+gs,$show,0,0,-1,-1,-1);
my $processinfo = pack("LLLL",0,0,0,0);
my $num=$CreateProcessWithLogon->Call(
$username, #lpUsername
undef, #lpDomain
$password, #lpPassword
$LOGON_NETCREDENTIALS_ONLY, #dwLogonFlags,
"hello", #lpApplicationName
$program, #lpCommandLine
$CREATE_NEW_CONSOLE, #dwLogonFlags,
undef, #lpEnvironment
".", #lpCurrentDirectory
$si, #lpStartupInfo
$processinfo #lpProcessInfo
) || return "Bad Call - $^E";
return $num;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.