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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Win32::API and CreateProcessWithLogonW by BrowserUk
in thread Win32::API and CreateProcessWithLogonW by slloyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.