Tania Aballe
Tania Aballe

Reputation: 41

Launching .exe from PowerShell window SOMETIMES causes it to be run in separate window, so I can't see output or get $lastexitcode

I am by no means a PowerShell expert; I have spent a good while googling this, but haven't found an answer.

The basic idea of my script is to run a Microsoft tool called appcert.exe with command-line arguments. appcert.exe returns 0, 1, or -1; I am checking it with $lastexitcode.

appcert.exe only runs on Windows 7 and Windows 8, so I have run my script on both.

Everything works fine on Windows 7x64 (PS version = 2.0). I can manually run all the same steps. I see the output of appcert.exe in the same PS window.

Different story on Windows 8x64 (RTM), where PS version = 3.0, CLRVersion = 4.0.30319.17929.

Sometimes, appcert.exe runs "inline" (like it did in Win7); other times, a command window is launched, the appcert.exe output flies by, and command window closes. The PS window that called it can't check $lastexitcode (which, by the way, is not set at all).

I tried all PS versions on machine, and results are as follows:

  1. appcert.exe is launched in separate window in these instances:

    • In PowerGUI 3.2.0.2237 (uses PS 2.0)
    • In regular PowerShell (non-admin)
    • In Windows PowerShell ISE (non-admin)
  2. appcert.exe is launched inline in these instances:

    • Ran Powershell as administrator
    • Ran ISE as administrator

Behavior above is obtained whether I:

  1. Launch script, which calls the appcert command like this: & $CertToolPath
  2. cd to the home direcotry of the tool and type .\appcert.exe
  3. Run this: Cmd /c appcert.exe
  4. Run this: Invoke-expression –command appcert.exe
  5. Run this: [system.diagnostics.process]::start("appcert.exe")

My colleagues are equally stumped by this.

My machine is in a test domain, not a workgroup. I log into the machine as an admin of the test domain, so theoretically, I'm already an admin.

I install the MS tool as that admin, too. In fact, I never do anything as the machine's local admin. Any ideas? :)

Many thanks in advance, Tania

Upvotes: 4

Views: 753

Answers (1)

Danny Tuppeny
Danny Tuppeny

Reputation: 42333

Can you repro this with any other exe? Do you have UAC prompts disabled?

Is it possible that appcert.exe requires to be run as Admin, and if not, it automatically re-launches itself as Admin (this should cause a UAC prompt, but if you've turned them off, it would appear to just spawn a new instance automatically)?

Upvotes: 1

Related Questions