-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaunchApp.hta
More file actions
85 lines (72 loc) · 2.02 KB
/
LaunchApp.hta
File metadata and controls
85 lines (72 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<html>
<head>
<title>Launch Application</title>
<HTA:APPLICATION
APPLICATIONNAME="ShinyLauncher"
BORDER="none"
CAPTION="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SYSMENU="no"
WINDOWSTATE="minimize"
/>
<script language="VBScript">
On Error Resume Next
Dim sh, fso, thisPath, root, bat, cfg, appTitle
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
thisPath = document.location.pathname
thisPath = Replace(thisPath, "file:///", "")
thisPath = Replace(thisPath, "/", "\")
thisPath = Replace(thisPath, "%20", " ")
root = fso.GetParentFolderName(thisPath)
bat = root & "\run.bat"
cfg = root & "\app_meta.cfg"
appTitle = "Shiny App Launcher"
If fso.FileExists(cfg) Then
Dim ts, line
Set ts = fso.OpenTextFile(cfg, 1)
Do Until ts.AtEndOfStream
line = Trim(ts.ReadLine)
If UCase(Left(line, 9)) = "APP_NAME=" Then
appTitle = Mid(line, 10)
Exit Do
End If
Loop
ts.Close
End If
document.title = appTitle
If Not fso.FileExists(bat) Then
MsgBox "run.bat was not found in:" & vbCrLf & root, 16, appTitle
window.close
End If
window.resizeTo 0,0
window.moveTo -10000,-10000
' Desktop shortcut — offer once per deployment folder
Dim markerFile
markerFile = root & "\.shortcut_offered"
If Not fso.FileExists(markerFile) Then
Dim answer
answer = MsgBox("Create a desktop shortcut for " & appTitle & "?", _
vbYesNo + vbQuestion, appTitle)
' Write marker so we only ask once regardless of answer
Dim tsMarker
Set tsMarker = fso.CreateTextFile(markerFile, True)
tsMarker.Close
If answer = vbYes Then
Dim desktopPath, oShortcut
desktopPath = sh.SpecialFolders("Desktop")
Set oShortcut = sh.CreateShortcut(desktopPath & "\" & appTitle & ".lnk")
oShortcut.TargetPath = "mshta.exe"
oShortcut.Arguments = Chr(34) & thisPath & Chr(34)
oShortcut.WorkingDirectory = root
oShortcut.Description = appTitle
oShortcut.Save
End If
End If
sh.Run """" & bat & """", 0, False
window.close
</script>
</head>
<body></body>
</html>