Created
January 13, 2023 23:00
-
-
Save markgodiy/609aa71db03d316ccfe284ceabef5fb6 to your computer and use it in GitHub Desktop.
Execute Powershell Script using VBA, with UAC for Security. To use this script as-is, .vbs file must be in the same folder as .ps1 file, then create shortcut to .vbs file as needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function RunAsAdmin() | |
| Dim objAPP | |
| If WScript.Arguments.length = 0 Then | |
| Set objAPP = CreateObject("Shell.Application") | |
| objAPP.ShellExecute "wscript.exe", """" & _ | |
| WScript.ScriptFullName & """" & " RunAsAdministrator",,"runas", 1 | |
| WScript.Quit | |
| End If | |
| End Function | |
| RunAsAdmin() | |
| strScriptPath = Wscript.ScriptFullName | |
| 'msgbox strScriptPath | |
| Set objFSO = CreateObject("Scripting.FileSystemObject") | |
| Set objFile = objFSO.GetFile(strScriptPath ) | |
| strScriptFolder = objFSO.GetParentFolderName(objFile) | |
| strCmd = "powershell.exe -noexit -executionpolicy remotesigned -file """ & strScriptFolder & """\MyScript.ps1""" | |
| 'msgbox strCmd | |
| Set shell = WScript.CreateObject("WScript.shell") | |
| shell.Run(strCmd), 1 , True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment