Advertisement
dcandygmailcom

Runs a command elevated using a manifest

Feb 9th, 2019
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.44 KB | None | 0 0
  1. REM Three files follow
  2. REM RunAsAdminConsole.bat
  3. REM This file compiles RunAsAdminconsole.vb to RunAsAdminconsole.exe using the system VB.NET compiler.
  4. REM Runs a command elevated using a manifest
  5. C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\RunAsAdminconsole.vb" /win32manifest:"%~dp0\RunAsAdmin.manifest" /out:"%~dp0\RunAsAdminConsole.exe" /target:exe
  6. REM To use
  7. rem RunAsAdminconsole <Command to run>
  8. pause
  9.  
  10.  
  11. ----------------------------------------
  12.  
  13. RunAsAdmin.manifest
  14.  
  15. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  16. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  17. <assemblyIdentity
  18.     version="1.0.0.0"
  19.     processorArchitecture="*"
  20.     name="Color Management"
  21.     type="win32"
  22. />
  23. <description>Serenity's Editor</description>
  24. <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
  25. <security>
  26.     <requestedPrivileges>
  27.         <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
  28.     </requestedPrivileges>
  29. </security>
  30. </trustInfo>
  31. </assembly>
  32.  
  33.  
  34. ----------------------------------------
  35.  
  36. 'RunAsAdminConsole.vb
  37. 'Change cmd /k to cmd /c to elevate and run command then exit elevation
  38. imports System.Runtime.InteropServices
  39. Public Module MyApplication  
  40.        
  41.     Public Sub Main ()
  42.         Dim wshshell as object
  43.         WshShell = CreateObject("WScript.Shell")
  44.         Shell("cmd /k " & Command())
  45.     End Sub
  46.  
  47. End Module
  48.  
  49.  
  50. ----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement