Since I got this to work, I thought I'd post it, though you'd need to modify it if you don't use Win32::APi::prototype. And my hackish way of converting ASCII to WIDE will probably cause some frowns.
You'll also need to ensure you have the 'Secondary Logon' service running, even if you use the current user's logon credentials. I routinely have that disabled, which is what was stopping me from getting this to work earlier. The error message:
The service cannot be started, either because it is disabled or becaus
+e it has no enabled devices associated with it at ...
Is less than helpful, as it doesn't tell you which service it needs, and I have many of the standard ones turned off.
#! perl -slw
use strict;
use Win32::API::Prototype;
sub A2W{ pack 'S*', unpack 'C*', $_[0] }
sub W2A{ pack 'C*', unpack 'S*', $_[0] }
ApiLink(
'advapi32.dll', q[
BOOL CreateProcessWithLogonW(
LPCWSTR lpUsername,
LPCWSTR lpDomain,
LPCWSTR lpPassword,
DWORD dwLogonFlags,
LPCWSTR lpApplicationName,
LPTR lpCommandLine,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInfo
)
]
) or die $^E;
my $si = pack(
'LLLLLLLLLLLL SS LLLL',
68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1|0x100, 1, 0, 0, -1, -1, -1
);
CreateProcessWithLogonW(
A2W( 'theUsername' ),
A2W( '\\.\ ' ),
A2W( 'thePasword' ),
0,
A2W( 'C:/windows/system32/notepad.exe' ),
0, 0, 0, 0,
$si,
chr(0) x 100
) or die $^E;
-
-
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
-
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.