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;
In reply to Re: Win32::API and CreateProcessWithLogonW
by BrowserUk
in thread Win32::API and CreateProcessWithLogonW
by slloyd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |