Perl script for starting a process as another user not working properly

1

I have a Perl script which uses Win32::API and the command CreateProcessWithLogonW in order to start a process as another user. However, when I run this script from a browser, the following error message appears on the server screen:

"The application failed to initiate properly (0xc0000142). Click on OK to terminate the application."

I have, however, discovered that if I stop Apache as a service and start it directly by double-clicking on httpd.exe, my perl script works without a problem. How can I get it to work when Apache is running as a service?

My code is as follows:

#!C:\usr\bin\perl
use CGI::Carp qw(fatalsToBrowser);
use Win32::API;

sub A2W{ pack 'S*', unpack 'C*', $_[0] }

my $CreateProcessWithLogon = new Win32::API('advapi32.dll', 'CreateProcessWithLogonW', ['P','P','P','P','P','P','P','P','P','P','P'],'N') || return $^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);

my $num=$CreateProcessWithLogon->Call(
    A2W( 'username' ),
    A2W( '\\.\ ' ),
    A2W( 'password' ),
    0,
    0,
    A2W( 'myprocess' ),
    0,
    0,
    0,
    $si,
    chr(0) x 100
) or die $^E;

print "Content-type:text/html\n\n";
print $num;
windows
apache
perl
asked on Stack Overflow May 26, 2019 by tim.tub • edited May 26, 2019 by melpomene

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0