Skip to content

Instantly share code, notes, and snippets.

@stuncloud
Created March 20, 2014 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuncloud/9660072 to your computer and use it in GitHub Desktop.
Save stuncloud/9660072 to your computer and use it in GitHub Desktop.
自身を昇格実行する UAC.Elevate() をスクリプトの最初のほうで呼ぶ
module UAC
procedure Elevate(arg = "")
if ! IsUserAnAdmin() then
UWSC_DIR = networkDriveToUnc(GET_UWSC_DIR)
CUR_DIR = networkDriveToUnc(GET_CUR_DIR)
UWSC_NAME = GET_UWSC_NAME
if pos(".exe", UWSC_NAME) then
exe = UWSC_NAME
dir = CUR_DIR
else
exe = "UWSC.exe"
dir = UWSC_DIR
arg = "<#DBL>" + CUR_DIR + "\" + UWSC_NAME + "<#DBL> " + arg
endif
sh = CreateOleObj("Shell.Application")
sh.ShellExecute(exe, arg, dir, "runas", 1)
exitexit
endif
fend
function networkDriveToUnc(path)
result = format(chr(0), 256)
size = lengthb(result)
if WNetGetUniversalNameA(path, UNIVERSAL_NAME_INFO_LEVEL, result, size) then
result = path
endif
fend
def_dll IsUserAnAdmin():BOOL:shell32
def_dll WNetGetUniversalNameA(string, long, {var string}, var long):long:mpr
const UNIVERSAL_NAME_INFO_LEVEL = $1
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment