Running a ps1 file as elevated

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Dennishk
Posts: 3
Last visit: Mon May 11, 2020 10:59 pm

Running a ps1 file as elevated

Post by Dennishk »

Product, version and build:
64 bit - PowerShell Studio 2018 v5.5.152
Operating system:
64 bit OS: Windows 10 - 1709

Hi,

I am scripting a GUI form to run some administrative/ support helping tasks.
In this script i want to be able to run - Explorer.exe - as other user. This reqiures me to change registry values.

I found something usefull and have been playing around with that until i got it to work. Now my problem is:
The GUI it self will be an EXE on the computer. This exe is run as another user (there for not elevated) .
The function to change the owner of the registry key (needed before i can edit the entry needed to be changes) needs to be run as administrator (elevated). Now what i need is to be able to run a seperate powershell window (elevated) to do this task. How would this be done?
I have tried to add a new ps1 file to my project and try to run this in my main psf - Start-Process Powershell EnablePrivilige.ps1 -RunAs - EnablePrivilige.ps1 is the name of the file. I have also tried to do it with calling the functions in the ps1 but powershell studio says that they are unknown.

Any ideas are appreciated.
cody m

Re: Running a ps1 file as elevated

Post by cody m »

[TOPIC MOVED BY MODERATOR]
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Running a ps1 file as elevated

Post by davidc »

If you wish to keep the script file external, make sure you set its Build property to Content. Then you will need to distribute the script the with executable.
David
SAPIEN Technologies, Inc.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked