I've got a lovely HTA that is intended to be displayed on all our users screens at Windows startup, as defined by a GPO. While everything is working fine, I'd really like to have it as an "always on top" window or at least grab focus/flash whenever somebody clicks away.
Every forum thread I've found via Google says this is not possible, but other people have found 'hacks' to get this to work. Various people mention either modal/modeless dialogues or using an onblur function. Unfortunately, as a self taught 'coder', my VBS/HTA powers are fairly weak and I don't really know how to put this into practice.
Would anybody be able to give me some guidance on how I could possibly launch the HTA and retain focus or keep it above other windows somehow?
Cheers
Andy
http://www.autoitscript.com/autoit3/docs/functions/WinSetOnTop.htm
Cheers,
Trevor Sullivan
Consultant
http://trevorsullivan.wordpress.com
- Edited by Trevor Sullivan [MVP]MVP, Moderator Wednesday, April 03, 2013 6:10 PM
http://www.autoitscript.com/autoit3/docs/functions/WinSetOnTop.htm
Cheers,
Trevor Sullivan
Consultant
http://trevorsullivan.wordpress.com
- Edited by Trevor Sullivan [MVP]MVP, Moderator Wednesday, April 03, 2013 6:10 PM
I might fall back on this if nobody can suggest a way of doing it via VBS or within the HTA itself ... ?
I'm not completely against using a 3rd party tool like this, but I'd like to avoid it if possible.
http://www.scriptinganswers.com/forum2/forum_posts.asp?TID=2300
you might be able to use the hta, to open another hta, that is allways on top (System modal).
look at this article by scripting guys, it describes how to open a model dialog box.
You could make this dialog box your main interface.
http://207.46.16.252/en-us/magazine/2007.05.heyscriptingguy.aspx
Merry x-mas
wshShell.Run "application.hta"
do
wscript.sleep 5000
wshShell.AppActivate "xx Application Title xx"
loop
With the HTA window frame removed, preventing the user from closing it prematurely (unless they figure out how to press Alt-F4) this is a simple but effective solution.
My only problem now is trying to figure out how to quit the VBS loop once the HTA has been closed. Is there a wscript.shell function I can use to check for the existence of the HTA by title or process?
Cheers
Andy
set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computerName & "\root\cimv2")
continueRunning = true
While continueRunning
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & executableName & "'")
if colProcessList.count = 0 then
continueRunning = false
else
Wscript.sleep 5000
end if
wend
I'm going to have a dig around myself and will post what I find for any others in the same boat as me.
Cheers
Andy
win32_Process has a property "CommandLine" that includes full path to running application (MSHTA.EXE in case of HTA App) and full path to its arguments (path of your HTA that is executed).
You can use this property to find all instances of MSHTA.EXE and do some filtering to identify if any of them is running your HTA. here is a sample script that prints out command line of all running HTAs.
strHTAExecutable = "MSHTA.EXE"
set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & strHTAExecutable & "'")
if colProcessList.count = 0 then
'no HTA Apps found running, code to handle the condition
else
for each objProcess in colProcessList
wscript.echo objProcess.commandLine
'code to find out your HTA based on its path/name from objProcess.commandLine property
next
end if
Hope it helps,
Here's my code to turn a HTA into a nag screen, if anybody needs it:
strHTAexe = "MSHTA.EXE" wshShell.Run "REPLACE WITH HTA FILENAME.hta" set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2") do wscript.sleep 5000 Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & strHTAexe & "'") If colProcessList.count = 0 Then wscript.quit Else a = 0 For each objProcess in colProcessList If inStr(objProcess.commandLine, "REPLACE WITH PART OF HTA FILENAME") <> 0 Then a = 1 End If Next If Not a = 1 Then wscript.quit End If End If wshShell.AppActivate "REPLACE WITH HTA APP TITLE" loopThanks again all !
Cheers
Andy
- Marked as answer by CraigLieb Sunday, January 10, 2010 8:09 PM
Here's my code to turn a HTA into a nag screen, if anybody needs it:
strHTAexe = "MSHTA.EXE" wshShell.Run "REPLACE WITH HTA FILENAME.hta" set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2") do wscript.sleep 5000 Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & strHTAexe & "'") If colProcessList.count = 0 Then wscript.quit Else a = 0 For each objProcess in colProcessList If inStr(objProcess.commandLine, "REPLACE WITH PART OF HTA FILENAME") <> 0 Then a = 1 End If Next If Not a = 1 Then wscript.quit End If End If wshShell.AppActivate "REPLACE WITH HTA APP TITLE" loopThanks again all !
Cheers
Andy
- Marked as answer by CraigLieb Sunday, January 10, 2010 8:09 PM
You need a Third-party application
http://www.nirsoft.net/utils/nircmd.html 32 or 64 bit version
put nircmdc.exe in your path or in the folder with hta file,
now use this sample .hta
<!========================================================================
<!
<! NAME: RusiaToday.hta
<!
<! REVISION:
<!
<! AUTHOR: Emprear / gc.gianello[dot]gmail.com
<!
<! DATE : 15/02/2013 09:03:38
<!
<! COMMENT:
<! Rusia Today en Espaol
<! Canal Internacional de Noticias
<!
<!======================================================================-->
<!
<html>
<head>
<title>RusiaToday</title>
<script type="text/javascript">
window.resizeTo(470,300);
var intHorizontal = screen.width;
var intVertical =screen.height;
var left_pos = (intHorizontal - 470) / 2;
var top_pos = (intVertical - 300) / 2;
window.moveTo(left_pos,top_pos);
</script>
<HTA:APPLICATION
ID="RusiaToday"
APPLICATIONNAME="RusiaToday"
BORDER="Dialog"
BORDERSTYLE="Normal"
CAPTION="yes"
CONTEXTMENU="no"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
ICON = "http://actualidad.rt.com/favicon.ico"
SCROLL="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="Normal"
>
<script type="text/javascript">
function ontop(){
if ((document.getElementById('wtop').innerHTML) == 'notop') {
document.getElementById('wtop').innerHTML = 'top';
new ActiveXObject("WScript.Shell").Run('%comspec% /C nircmdc win settopmost title RusiaToday 0',0,true);
}else{
document.getElementById('wtop').innerHTML = 'notop';
new ActiveXObject("WScript.Shell").Run('%comspec% /C nircmdc win settopmost title RusiaToday 1',0,true);
}
}
</script>
<style type="text/css">
html, body{
padding: 0;
border: none;
margin: 0;
overflow: hidden;
}
object#rto{
margin: 0;
border: none: padding: 0;
;
left: 0;
top: 0
z-index: 1;
}
button#wtop{
;
top: 1%;
right: 1%;
z-index: 999;
width:38px;
font-size: 10px;
font-weight: bold;
padding: 2px 4px;
}
/*]]>*/
</style>
</head>
<body style="background:#1E1D11">
<object type="application/x-shockwave-flash" data="http://actualidad.rt.com/static/jwplayer/player.swf" id="rto" height='274' width='470'>
<param name="movie" value="http://actualidad.rt.com/static/jwplayer/player.swf" />
<param name="loop" value="false" />
<param name="menu" value="false" />
<param name="play" value="true" />
<param name="wmode" value="transparent" />
<param name='allowfullscreen' value='true'>
<param name='allowscriptaccess' value='always'>
<param name="flashvars" value="&autostart=true&backcolor=0x000000&bandwidth=1016&controlbar=over&file=RT_Spanish_2&frontcolor=0xffffff&image=http%3A%2F%2Factualidad.rt.com%2Fstatic%2Fvideo-player-bg.png&lightcolor=0xffffff&mute=false&plugins=viral-2d&screencolor=0x404040&skin=http%3A%2F%2Factualidad.rt.com%2Fstatic%2Fjwplayer%2Fplayer_skin.zip&streamer=rtmp%3A%2F%2Frt.fms.visionip.tv%2Flive%3Fautostart%3Dtrue&viral.onpause=false"
/>
<param name="bgcolor" value="#1E1D11" />
</object>
<button onclick="ontop();" id="wtop">top</button>
</body>
</html>
Look at the ontop() function and how alternate top and notop status using nircmdc command line utilitiy
Thats all
Regards
- Proposed as answer by Emprear Friday, February 15, 2013 3:38 PM
You need a Third-party application
http://www.nirsoft.net/utils/nircmd.html 32 or 64 bit version
put nircmdc.exe in your path or in the folder with hta file,
now use this sample .hta
<!========================================================================
<!
<! NAME: RusiaToday.hta
<!
<! REVISION:
<!
<! AUTHOR: Emprear / gc.gianello[dot]gmail.com
<!
<! DATE : 15/02/2013 09:03:38
<!
<! COMMENT:
<! Rusia Today en Espaol
<! Canal Internacional de Noticias
<!
<!======================================================================-->
<!
<html>
<head>
<title>RusiaToday</title>
<script type="text/javascript">
window.resizeTo(470,300);
var intHorizontal = screen.width;
var intVertical =screen.height;
var left_pos = (intHorizontal - 470) / 2;
var top_pos = (intVertical - 300) / 2;
window.moveTo(left_pos,top_pos);
</script>
<HTA:APPLICATION
ID="RusiaToday"
APPLICATIONNAME="RusiaToday"
BORDER="Dialog"
BORDERSTYLE="Normal"
CAPTION="yes"
CONTEXTMENU="no"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
ICON = "http://actualidad.rt.com/favicon.ico"
SCROLL="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="Normal"
>
<script type="text/javascript">
function ontop(){
if ((document.getElementById('wtop').innerHTML) == 'notop') {
document.getElementById('wtop').innerHTML = 'top';
new ActiveXObject("WScript.Shell").Run('%comspec% /C nircmdc win settopmost title RusiaToday 0',0,true);
}else{
document.getElementById('wtop').innerHTML = 'notop';
new ActiveXObject("WScript.Shell").Run('%comspec% /C nircmdc win settopmost title RusiaToday 1',0,true);
}
}
</script>
<style type="text/css">
html, body{
padding: 0;
border: none;
margin: 0;
overflow: hidden;
}
object#rto{
margin: 0;
border: none: padding: 0;
;
left: 0;
top: 0
z-index: 1;
}
button#wtop{
;
top: 1%;
right: 1%;
z-index: 999;
width:38px;
font-size: 10px;
font-weight: bold;
padding: 2px 4px;
}
/*]]>*/
</style>
</head>
<body style="background:#1E1D11">
<object type="application/x-shockwave-flash" data="http://actualidad.rt.com/static/jwplayer/player.swf" id="rto" height='274' width='470'>
<param name="movie" value="http://actualidad.rt.com/static/jwplayer/player.swf" />
<param name="loop" value="false" />
<param name="menu" value="false" />
<param name="play" value="true" />
<param name="wmode" value="transparent" />
<param name='allowfullscreen' value='true'>
<param name='allowscriptaccess' value='always'>
<param name="flashvars" value="&autostart=true&backcolor=0x000000&bandwidth=1016&controlbar=over&file=RT_Spanish_2&frontcolor=0xffffff&image=http%3A%2F%2Factualidad.rt.com%2Fstatic%2Fvideo-player-bg.png&lightcolor=0xffffff&mute=false&plugins=viral-2d&screencolor=0x404040&skin=http%3A%2F%2Factualidad.rt.com%2Fstatic%2Fjwplayer%2Fplayer_skin.zip&streamer=rtmp%3A%2F%2Frt.fms.visionip.tv%2Flive%3Fautostart%3Dtrue&viral.onpause=false"
/>
<param name="bgcolor" value="#1E1D11" />
</object>
<button onclick="ontop();" id="wtop">top</button>
</body>
</html>
Look at the ontop() function and how alternate top and notop status using nircmdc command line utilitiy
Thats all
Regards
- Proposed as answer by Emprear Friday, February 15, 2013 3:38 PM
Hi SpankyJ,
There's actually an easier solution: use the setInterval method and let mshta bring the window in focus every n ms. Set the HTA's properties to remove the sysmenu, scroll bars, etc and you're done!
<script language="vbscript">
window.setInterval "setfocus()", 100
Function setfocus
window.focus()
End Function
</script>
<hta:application
applicationname="MyHTA"
border="none"
borderstyle="complex"
caption="My HTML Application"
contextmenu="no"
icon="myicon.ico"
innerborder="yes"
maximizebutton="no"
minimizebutton="no"
navigable="no"
scroll="no"
selection="no"
showintaskbar="no"
singleinstance="yes"
sysmenu="no"
version="1.0"
windowstate="normal"
>
- Edited by Martin Sauriol Monday, April 01, 2013 4:21 PM typo
- Proposed as answer by omegastripes Thursday, July 31, 2014 7:10 PM
Hi SpankyJ,
There's actually an easier solution: use the setInterval method and let mshta bring the window in focus every n ms. Set the HTA's properties to remove the sysmenu, scroll bars, etc and you're done!
<script language="vbscript">
window.setInterval "setfocus()", 100
Function setfocus
window.focus()
End Function
</script>
<hta:application
applicationname="MyHTA"
border="none"
borderstyle="complex"
caption="My HTML Application"
contextmenu="no"
icon="myicon.ico"
innerborder="yes"
maximizebutton="no"
minimizebutton="no"
navigable="no"
scroll="no"
selection="no"
showintaskbar="no"
singleinstance="yes"
sysmenu="no"
version="1.0"
windowstate="normal"
>
- Edited by Martin Sauriol Monday, April 01, 2013 4:21 PM typo
- Proposed as answer by omegastripes Thursday, July 31, 2014 7:10 PM
Works like a charm, simple is normally better...
Thanks
- Edited by RMaldi Thursday, August 28, 2014 12:52 AM
Works like a charm, simple is normally better...
Thanks
- Edited by RMaldi Thursday, August 28, 2014 12:52 AM
Not sure why but so long as I try using vbscript my code will not work.
Have switched over to javascript and the hta recognizes it fine now. Anyone else running into that problem I suggest switching over to javascript; more functionality anyways.
Works fine for me!!! Thanks!
<script language="vbscript">
window.setInterval "setfocus()", 100
Function setfocus
window.focus()
End Function