Run DOS Command / Batch File: How to capture output when impersonating as other user?

I would like to know of there is a way to capture the full output of a target executable when using the following feature:

Properties > Runtime > Execution properties > Run Action As User

If I don’t use this feature, I can see all the executable output in the log. But when enabled, I see only return code. No output at all.

I am using Run DOS Command / Batch File action, but this feature is also supported by others. I haven’t tried others yet.

Why:
So when something goes wrong and I get a return code like -1073741502 It becomes impossible to debug

Use the Execute Program action unless you are running batch file or dos command. As for not logging output, I just tested here and was able to see the full output.

Vincent, thanks for the advise. I’ve replaced all Run DOS command actions with Execute Program actions. Now I see the real target executable path in the “Output from” section of the build log, instead of cmd.exe. But I still get no further output, except the return code.

I’ve checked under normal circumstances I can see the output too. But when the project runs by FBCMD, triggered by a PHP website, the action fails, an then this is the only output that is logged:

Executing external process: C:\Windows\system32\inetsrv\appcmd.exe
Parameters: start site /site.name:"TestSite"
Impersonating User: Administrator
Output from C:\Windows\system32\inetsrv\appcmd.exe
Program returned code  : -1073741502


So there is no way I can debug why the action fails. appcmd.exe is a smart Microsoft tool that always outputs the error description. Finalbuilder only captures the return code in this case, why?.

If you run windows calculator, in programmer mode, set to dec, paste in the error code and then switch to hex you get FFFFFFFFC0000142. Taking only the last 8 chars, C0000142 is a stop due to a dll initialization error. So it’s not the error code from appcmd, appcmd.exe is not starting. My best guess at this time would be a permissions issue.

This is a most accurate guess. It is a permissions issue I’m trying to solve for a week now, this is why I’m trying different approaches to start IIS website.
I need some serious assistance here please.

This is the scenario:
1) User clicks a button on a web page (IIS, PHP) in his browser window
- That webpage runs under a Application Pool impersonated as a dedicated Windows user, let’s say: FBUser
- FBUser is a part of Administrators users group
2) PHP uses exec() function to call FBCMD.exe to run the FinalBuilder project
- FBCMD.exe process executed by FBUser. This is confirmed.
3) FBCMD runs all the project actions successfully, including Creating IIS site, Deleting IIS site, running APPCMD to add/remove binding information, without a need for more permissions.
4) Start/Stop/Restart IIS site action fails.
- Execute Program action, calling APPCMD to start/stop website fails too.
- Execute Program action, calling APPCMD to start/stop website, impersonated as buit-in Administrator account fails too.

Q1) Why does starting/stopping a website require more permissions than creating/deleting the same site?

You say that you conclude that appcmd.exe is not starting at all. But the same call to appcmd with different arguments (adding/removing bindings) executes successfully! So based on my logic the return code -1073741502 DOES come from appcmd.exe itself.
Q2) Why does a call to “appcmd.exe set site /site.name: …” executes successfully, but “appcmd.exe start site /site.name: …” fails with dll initialzation error?

Earlier during the testing I came across the error code from appcmd call by FB, with a large negative number and no output. What I did is I executed exact the same command from the Command Prompt window, where appcmd gave me the exact file that couldn’t be loaded and something like “access denied”. For current situation I can’t recreate that error from the Command Prompt because when run from command prompt, it runs successfully. Except that I use Microsoft’s built-in runas command to impersonate as Administrator. That may be different from what FinalBiuilder’s Run Action As User is doing.

Q1) I have no idea, we didn’t write appcmd.exe. Resolving permissions errors is beyond the support that we provide. If we had to provide support for every specific windows permissions error we would never get any other work done. We do not decided what permissions a tool needs to do something. I would suggest you contact microsoft to find out what specific permissions it needs.

The error code does come from appcmd.

Q2) Again, no idea… ask microsoft.

We redirect stdout and stderror when executing a process. We can only capture something if it is written to the pipe. When you specify a user, we call CreateProcessWithLogon rather than CreateProcess. Whether this is the same as runas I could not say, I don’t have the source to windows.