run as Admin?

Ask your PowerShell-related questions, including questions on cmdlet development!
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 6 years and 2 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
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

run as Admin?

Post by mqh77777 »

PowerShell Studio 5.4.145
Windows 10 x64 systems

Behind a button I have the following code. How do I run openfiles.exe with an Elevated Prompt (i.e. Admin) ?

$pc = $PCNameBox.Text
$ID = $FileID.Text
$richtextbox_Output.Clear()
$richtextbox_Output.SelectionColor = 'Blue'
$statusbar1.text = 'Closing open file, please wait.'
$results = openfiles /disconnect /ID $ID /s $pc
$richtextbox_Output.appendtext("This file was closed" + " " + $results)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: run as Admin?

Post by jvierra »

You have to start the script elevated. There is no way to elevate a single line.
This topic is 6 years and 2 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