4

I had a script that needed to run as an administrator but then run a single command in a non-elevated context. I was previously doing it with runas /trustlevel:0x20000 program.exe, but after updating Windows 11 to 22H2 the command now gives the following output (running Notepad here as an example):

PS > runas /trustlevel:0x20000 notepad
RUNAS ERROR: Unable to run - notepad
87: The parameter is incorrect.

I've double-checked the trustlevel argument value and it appears to be correct:

PS > runas /showtrustlevels
The following trust levels are available on your system:
0x20000 (Basic User)

This happens for any app I try, not just Notepad or the one in my script. I've also tried it in Powershell 7, Windows Powershell (5) and from the command line, but no difference. Runas itself isn't completely broken, as I can do runas /profile /env /user:<username> notepad and it'll launch (after entering my password). I've also done an sfc /scannow just in case, but it's made no difference.

I'm currently trying to work out if there's anything I can do here or if the feature has just been deprecated in 22H2.

StormFoo
  • 215
  • 2
  • 13
  • That is all I have here (Windows 11 Pro 22H2 22621.755). Otherwise I do not know if there is anything around the issue. It show the same way in Windows 11 Insider (Build 25227.1000) – John Oct 26 '22 at 21:53
  • @StormFoo .... Do you get any different result using that command with another program other than `notepad.exe`? Wasn't sure if you could test a few other apps and see if the result is consistent. It might indicate something with that app perhaps but not sure what at the moment. – Vomit IT - Chunky Mess Style Oct 27 '22 at 21:46
  • @VomitIT-ChunkyMessStyle the result is the same regardless of program. I originally noticed it with a specific custom program, but I get the same outcome whether I use `notepad.exe`, `cmd.exe`, `pwsh.exe`, etc, so it appears to be an issue with `runas` executing at the trust level specified. – StormFoo Oct 28 '22 at 08:45

2 Answers2

3

This is a know issue with the latest Windows 11 update. It has been resolved in the preview build 25247:

Fixed an issue which was causing the runas command to unexpectedly fail in certain cases with error 87 saying the parameter was incorrect (when it wasn’t).

https://blogs.windows.com/windows-insider/2022/11/18/announcing-windows-11-insider-preview-build-25247/

3

The workaround is to include the /machine switch on the runas command line.

BlueMonkMN
  • 467
  • 1
  • 7
  • 17
  • 1
    Thanks, works a treat until the update occurs, probably the only flag I didn't attempt before posting (typical). Note for anyone following along that the parameter value may be different depending on the executable type, so for `notepad` I had to set `/machine:amd64`, but if I wanted to use a 32-bit executable I have to use `/machine:x86`. – StormFoo Nov 29 '22 at 15:41
  • In my case solution wast to use `runas /trustlevel:0x20000 /machine:x86 test.exe` but I get: `The image file c:\1\test.exe is valid, but it is for a different type of computer than the current one` So I had to check that my test.exe program was compiled as x64 and I had to compile them as x86 – Michał Lipok Mar 31 '23 at 11:13