Created
March 20, 2014 09:20
-
-
Save stuncloud/9660072 to your computer and use it in GitHub Desktop.
自身を昇格実行する
UAC.Elevate() をスクリプトの最初のほうで呼ぶ
This file contains 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
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