Thursday 28 November 2019

RunAsAdmin - Run a program elevated. The program prompts for credentials.

This uses the inbuilt compilers in Windows 10 - there are three VB.NET compilers and three C# compilers - just copy each text file into the same folder and double click the batch file to make the program.
REM Three files follow
REM RunAsAdminConsole.bat
REM This file compiles RunAsAdmin.vb to RunAsAdmin.exe using the system VB.NET compiler.
REM Runs a program elevated using a manifest
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\RunAsAdmin.vb" /win32manifest:"%~dp0\RunAsAdmin.manifest" /out:"%~dp0\RunAsAdmin.exe" /target:winexe
REM To use
REM     RunAsAdmin 
pause



'RunAsAdmin.vb
imports System.Runtime.InteropServices 
Public Module MyApplication  
 Public Sub Main ()
  Dim wshshell as object
  WshShell = CreateObject("WScript.Shell")
  WshShell.Run(Command())
 End Sub 
End Module 




RunAsAdmin.Manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="Color Management" type="win32" /> <description>Serenity's Editor</description> <trustinfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedprivileges> <requestedexecutionlevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo> </assembly>