Inno Setup使用管理权限创建HTA的快捷方式

时间:2013-03-09 13:05:39

标签: inno-setup uac hta

我正在使用Inno Setup创建一个桌面快捷方式,用于打开Windows 7上Program Files中保存的HTA文件。此HTA文件调用需要以管理员身份运行的外部exe文件。

因此,为此,我想自动创建一个使用Inno Setup以管理员身份运行的快捷方式。这里的问题是快捷方式指向HTA文件而不是exe。我该怎么做呢?

3 个答案:

答案 0 :(得分:0)

检查此样本:

<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()
'***********************************************************
' http://dieseyer.de/scr/elevate.hta
' 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>

答案 1 :(得分:-1)

问题的直接答案是使用HTA的文件名作为参数创建mshta.exe的快捷方式。可以将mshta.exe的快捷方式标记为以管理员身份运行。

答案 2 :(得分:-1)

如果您的可执行文件需要管理员访问权限,那么您应该add an appropriate manifest to your executable,而不是尝试提升HTML应用程序。