10

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
  • 275

3 Answers3

5

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

4

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

As BlueMonkMN answered the workaround with /machine:x86|amd64|arm|arm64 works. If you are on a 64bit intel machine and want to execute a batchfile there is no machine option that will work since cmd.exe is a 64 bit application. There is a 32bit version for cmd.exe at C:\Windows\sysWOW64\cmd.exe, so a command could be as follows:

runas /machine:x86 /trustlevel:0x20000 "C:\Windows\sysWOW64\cmd.exe <yourBatchfileHere>"

Since I can not comment on an answer yet I had to make a new on just in case someone has the same problem as me.

Simon
  • 31