gpt4 book ai didi

jscript - 使 HTA 文件以管理员身份运行(提升)

转载 作者:行者123 更新时间:2023-12-01 00:48:23 26 4
gpt4 key购买 nike

在 wsf、vbs 和 js 文件中,您可以轻松确定它们是否运行提升,如果不是,您可以轻松制作它们。
我为此编写的代码是这样的:

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();
}
}

但这在 HTA 文件中不起作用,因为那里不存在全局 WScript 变量。
那么如何强制以管理员身份运行特定的 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>

关于jscript - 使 HTA 文件以管理员身份运行(提升),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32799751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com