使HTA文件以管理员身份运行(提升)
问题描述:
在wsf,vbs和js文件中,您可以轻松了解它们是否运行提升,如果不运行,您可以轻松制作它们。
我该写的代码是这样的:使HTA文件以管理员身份运行(提升)
EnsureElevatedPrivileges();
WScript.Echo("Running elevated now!");
function EnsureElevatedPrivileges() {
if (!WScript.Arguments.Named.Exists("elevate")) {
new ActiveXObject("Shell.Application").ShellExecute(WScript.FullName, "\"" + WScript.ScriptFullName + "\" /elevate", "", "runas", 1);
WScript.Quit();
}
}
但由于全球WScript的变量不存在有这种不HTA文件。
那么我如何强制一个特定的HTA文件作为管理员运行(本身)?
答
您可以在此看一看:Procedure to run HTA elevated
<html>
<head>
<title>HTA Helpomatic</title>
<HTA:APPLICATION
ID="oHTA"
APPLICATIONNAME="HTAHelpomatic"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
<!-- ID="objHTAHelpomatic" -->
<!-- WINDOWSTATE="maximize" -->
</head>
<SCRIPT Language="VBScript">
If HTAElevate() = True Then
CreateObject("WScript.Shell").Run "mmc.exe compmgmt.msc", , True
Call Main()
End If
Sub Main()
MsgBox "HTA-Ende", 4096
End Sub
'*** v13.3 *** www.dieseyer.de *****************************
Function HTAElevate()
'***********************************************************
' Unter Windows x64 laufen VBS' nach einem Doppelklick in der x64-Umgebung
' mit %WinDi%\System32\wscript.exe oder mit %WinDi%\System32\cscript.exe.
' In der x64-Umgebung laufen VBS aber nicht (richtig). Die Prozedur
' HTAElevate() erkennt dies und startet ggf. das VBS in der
Const Elev = " /elevated"
' MsgBox oHTA.commandLine, , "5016 :: "
' Trace32Log "5018 :: oHTA.commandLine: ==" & oHTA.commandLine & "==", 1
HTAElevate = True
' If InStr(LCase(oHTA.commandLine), Elev) > 0 then MsgBox oHTA.commandLine, , "5022 :: "
If InStr(LCase(oHTA.commandLine), Elev) > 0 then Exit Function
On Error Resume Next
window.resizeto 750, 10 ' : window.moveto screen.width/2, screen.height/2
On Error GoTo 0
' MsgBox oHTA.commandLine, , "5030 :: "
createobject("Shell.Application").ShellExecute "mshta.exe", oHTA.commandLine & Elev, "", "runas", 1
HTAElevate = False
self.close
End Function ' HTAElevate()
</SCRIPT>
<body>
</body>
</html>