在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文件(本身)以管理员身份运行呢?
您可以看看这个:
<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%System32wscript.exe oder mit %WinDi%System32cscript.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>
<html>
<head>
<SCRIPT LANGUAGE="VBScript" use="to move window offscreen so that it should not flicker">
X=top.screenleft
Y=top.screentop
window.moveTo -2000,-2000
</SCRIPT>
<hta:application
ID="thisHta"
ApplicationName="The Great ManojBhakarPCM"
Border="thin"
BorderStyle="Static"
Caption="Yes"
ContextMenu="No"
MaximizeButton="No"
MinimizeButton="No"
Navigable="No"
Scroll="yes"
Selection="yes"
ShowInTaskbar="Yes"
SingleInstance="no"
SysMenu="Yes"
WindowState="normal"
>
<SCRIPT Language="VBScript" use="to Run As Administrator And window onload.">
If InStr(LCase(thisHta.commandLine), " /elevated") = 0 Then
createobject("Shell.Application").ShellExecute "mshta.exe", thisHta.commandLine & " /elevated", "", "runas", 4
self.close
else
window.moveTo X,Y
End If
Sub Window_OnLoad 'On window loading elements compeleted. start work here.
Document.body.innerHtml = "hello public, to kaise hai aap log? तो कैसे है आप लोग ?"
End Sub
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<style>
/* Author: ManojBhakarPCM */
body {
font-family: Arial, Helvetica, sans-serif;
}
.tile{/* Tile: width:vary, height: content wrap, padding: 5px;*/
height: auto !important;
padding:10px;
margin:3px;
display:inline-block;
}
.tilehead{
height: auto !important;
padding-left:10px;
padding-right:10px;
padding-top:2px;
padding-bottom:2px;
margin:2px;
font-size:10px;
display:inline-block;
}
/*-----COLORS----*/
.pink{background-color:#FF4081;color:white;}
.red{background-color:#D32F2F;color:white;}
.purple{background-color:#E040FB;color:white;}
.deeppurple{background-color:#512DA8;color:white;}
.indigo{background-color:#536DFE;color:white;}
.blue{background-color:#1976D2;color:white;}
.lightblue{background-color:#0288D1;color:white;}
.cyan{background-color:#00BCD4;color:white;}
.teal{background-color:#00796B;color:white;}
.green{background-color:#388E3C;color:white;}
.lime{background-color:#CDDC39;color:white;}
.yellow{background-color:#FFEB3B;color:white;}
.darkyellow{background-color:#FBC02D;color:white;}
.orange{background-color:#FF5722;color:white;}
.bluegray{background-color:#607D8B;color:white;}
.gray{background-color:#333;color:white;}
.roundcorner{border-radius:5px;}
.bold{font-weight:bold;}
.padmin{padding:5px;}
.padmid{padding:10px;}
.padfull{padding:15px;}
.inline{display:inline-block;}
/* --------CONTROLS---------*/
/*NAVBAR*/
.navbar {overflow: hidden;background-color: #333;padding:3px;text-decoration: none;}
.navbar a{padding:5px;font-size: 10px;text-decoration: none;}
.navbar a:hover{background-color:red;}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 50%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<body>
Hellow Worlds
</body>
</html>
我已经创建了这个hta模板,我经常使用它。我相信模板是与脚本等工作的最好方式,我通常保持将这些模板上传到网站,所以当在任何计算机(不是我的)上工作时,可以通过下载和开始编码来完成工作。特点:
- 以管理员身份运行
- 不闪烁
- 在得到admin之前不要显示 Unicode支持。
- 所有HTA标签。
- 为平滑UI提供有用的css类