How to run an executable from a PHP site as a specific Windows user?

By default, PHP runs under the IUSR account . When executed directly:

$lastline = exec('D:\\MyProgram.exe', $output, $return_var);

It is running, but the program cannot perform tasks due to insufficient privileges. My question is: How to run an executable file under a Windows account from a PHP site?

I tried:

Run through Sysinternals PsExec :

$lastline = exec('D:\\PsExec.exe -u UserName -p Password -accepteula "D:\\MyProgram.exe"', $output, $return_var);

MyProgram.exe is not even running at all. PHP returns empty output, and return_var returns -1073741502. I assume this is some kind of unhandled exception.


Running through lsrunas :

$lastline = exec('D:\\lsrunas.exe /user:UserName /password:Password /domain:DOMAIN /command:"D:\\MyProgram.exe" /runpath:D:\\', $output, $return_var);

MyProgram.exe is also not running. PHP returns empty output, and return_var returns 0.


Microsoft runas , .


PHP, shell_exec, system passthru


IIS, - LOCAL SERVICE, SYSTEM . EDIT: , . , , Load User Profile ( 3 ).

- ?

. .

+3
1

, , , .

  • IIS
  • Advanced Settings > Identity > Custom account
  • Advanced Settings > Load User Profile true ( )
  • " ",

-- :

. 5. , , -, . .

(!):

PHP FastCGI, fastcgi.impersonate = 0 php.ini .


:

, , *.bat PHP.

@echo off
SET now=%date% %time%
SET out=[%now%] %userdomain%\%username%
echo %out%
echo %out% > D:\hello.txt
::msg * "%out%"

if %username%=="SpecificUser" (
  exit /B 100
) else (
  exit /B 200
)

SpecificUser . . .

, script . D:\hello.txt .

+4

All Articles