I have a utility compiled powershell with gui (powershell studio) this utility run a list of files exe or cmd, or ps1’s.
Some of the cmd or ps1 require admin rights (the user is a local admin) to run below are two of the commands that fail if not an admin and then the code that launches them
code that will fail: (both are in .ps1 files)
dism /online /import-defaultappassociations:c:\Scripts\DefaultApps\DefaultApps.xml
or
Import-StartLayout -LayoutPath “Start.xml” -MountPath C:\
To the first question, yes, it is equivalent to using ‘Run as Administrator’.
As for the other question, I’m not really sure what you mean. If you’re asking whether there are other methods of elevating, there might be, but I’m not familiar with any of them. There are some popular self-elevating snippets around here that effectively check if the current session is elevated, and if not, they trigger an elevated session and re-run the current sequence of code.
But as far as I know, even that makes use of `-RunAs`.
You do have the option of simply directly calling an executable along with any arguments it might have using Start-Process, but in general any process called from an elevated PowerShell session inherits the elevated status.
This is the first few lines of my code that makes sure the script I’m running is running as admin and if it isn’t then it’ll re open’s itself as admin
(you’ll still get a smart screen check if that’s still on asking if you are sure you want to run PS as admin)