Maximus5 / ConEmu

Customizable Windows terminal with tabs, splits, quake-style, hotkeys and more
https://conemu.github.io/
BSD 3-Clause "New" or "Revised" License
8.6k stars 573 forks source link

Elevated ConEmu can't create process, ErrCode=2 #2275

Closed Snaptags closed 3 years ago

Snaptags commented 3 years ago

Versions

ConEmu build: 210206 x64 OS version: Windows 10 x64 Used shell version: PowerShell 7.1.1

Problem description

One of the latest updates broke my alias to open an elevated ConEmu window

Steps to reproduce

  1. Paste this function into the pwsh console:
    function ele([string]$application = 'pwsh -NoLogo')
    {
    ConEmuC -c $application $args -new_console:a
    }
  2. type ele and hit \<enter> to execute it

Actual results

"ConEmuC64 can't create process, ErrCode=2, Command to be executed: pwsh -NoLogo"

Expected results

A new, elevated pwsh session opens. Funny thing: if I execute exactly the same command MANUALLY, it works as expected:

ConEmuC -c pwsh -NoLogo -new_console:a
SpawNBK commented 3 years ago

ConEmu does't find a file pwsh. I think conemu don't see system path in function You can find system path to a file and manualy execute file with filepath It's works for me

function ele([string]$application = (get-command 'powershell').Path +' -NoLogo')
{
    ConEmuc -c $application $args -new_console:a
}
Snaptags commented 3 years ago

Thanks for helping me with this. Using get-command fixes the issue.

In case anyone stumbling upon this issue needs a more generic solution:

function sudo([string]$application = 'pwsh')
{
    $path = (get-command $application).Path
    if ($application -eq "pwsh") {
        ConEmuC -c $path -NoLogo $args -new_console:a
    } else {
        Start-Process $path $args -Verb RunAs
    }
}

Then you can use sudo to get a Admin PowerShell or sudo appname to run any app as Admin (has to be found in the path)