youtuber Posted February 21, 2020 Posted February 21, 2020 (edited) How can I run cmd file as an administrator in the folder I am in? I have tried all of the following possibilities. #RequireAdmin ;~ $CmdPath = @ScriptDir & "\Test.cmd" ;~ Run(@ScriptDir & "\Test.cmd") ;~ Run(@ComSpec & " /k " & $CmdPath ,@ScriptDir) ;~ ShellExecute(@ComSpec ," /k " & $CmdPath ,@ScriptDir) ;~ ShellExecute(@ScriptDir & "\Test.cmd") ;~ ShellExecute($CmdPath, "", "", "runas") ;~ ShellExecute($CmdPath, "", @WorkingDir, "runas") ;~ RunAs("USER", @ComputerName, "", "", $CmdPath, @ScriptDir, "", @SW_SHOWMAXIMIZED) Edited February 21, 2020 by youtuber
Subz Posted February 21, 2020 Posted February 21, 2020 What do you mean? C:\Windows\System32\cmd.exe is where cmd.exe exists, do you want just change the title of the window? #RequireAdmin Run(@ComSpec & " /k Title " & @ScriptDir ,@ScriptDir)
youtuber Posted February 21, 2020 Author Posted February 21, 2020 (edited) Not a title, Test.cmd file in the working folder I am in and I want to run it in Admin authority. As seen here Edited February 21, 2020 by youtuber
Subz Posted February 21, 2020 Posted February 21, 2020 #RequireAdmin forces it to open as Administrator, setting the working directory, it will open in that directory, here is a basic test I used which opens command prompt in @ScriptDir #RequireAdmin Local $sTestCmd = "Test1.cmd" FileDelete(@ScriptDir & "\" & $sTestCmd) FileWrite(@ScriptDir & "\" & $sTestCmd, "dir *" & @CRLF & "pause" & @CRLF) Run(@ComSpec & " /k " & $sTestCmd ,@ScriptDir)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now