0
votes

I'm using Inno Setup to create a desktop shortcut that opens an HTA file saved in Program Files on Windows 7. This HTA file calls an external exe file that needs to run as administrator.

So, to do this, I want to automatically create a shortcut that runs as admin using Inno Setup. The problem here is that the shortcut points to an HTA file instead of an exe. How do I go about doing that?

3
HTA is HTML application. It's basically a script. en.wikipedia.org/wiki/HTML_ApplicationCookieEater
I'm reasonably sure that shortcuts to documents (which is what an HTA probably counts as) can't run as admin. I would be extremely dubious about an HTA that wanted to do anything admin anyway -- HTAs are typically just packaged webpages, aren't they?Miral
True. I use an HTA because I don't need to create a complicated GUI. The HTA updates the content of itself by calling an external exe which overwrites the HTA file. That's why I need admin right. I think I should just place it directly under C:\some_folder so I don't need to mess with this.CookieEater
If your executable needs admin access, it should be marked as such with a suitable manifest (there are too many suitable questions in the sidebar panel to list). This will then allow the Windows Shell to ask the user to confirm before running it. This should not be done for the initial HTA shortcut.Deanna
Note that the "Run this program as an administrator" check box on the "Compatibility" tab is different from the "Run as administrator" check box when you click the "Advanced" button on the "Shortcut" tab. The point is that you can configure a specific shortcut to run as admin, which is what would be needed in the case of an HTA (as it would indeed be inappropriate to mark mshta.exe as requiring elevation).Bill_Stewart

3 Answers

0
votes

check this sample:

<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
votes

The direct answer to the question is to create the shortcut to mshta.exe with the HTA's filename as its parameter. The shortcut to mshta.exe can be marked to run as administrator.

-1
votes

If your executable requires admin access, then you should add an appropriate manifest to your executable, not try and elevate the HTML application.