Click here to Skip to main content
15,920,053 members
Articles / Programming Languages / VBScript
Article

VBSCRIPT - Window Always On Top

Rate me:
Please Sign up or sign in to vote.
2.17/5 (3 votes)
22 Feb 2005 118.2K   5   8
This program's purpose is to load the target url and keep it in focus and covering the whole screen until the user selects a button on the screen which closes the window or hit's <ALT-F4>.

Introduction

This program's purpose is to load the target url and keep it in focus and covering the whole screen until the user selects a button on the screen which closes the window or hit's <ALT-F4>. 

 

Using the code

The code is pretty self documenting.  Just cut and paste it into a .vbs file.  Change the URL to any address, be it on the web or a network UNC path.< /p>< /p>

'**************************************************************************************************
'This code will open a web browser and point it at the url specified.
'sURL is the url to the website you want to load.
'This vbscript will not allow the user to switch to any other window till this script ends.
'**************************************************************************************************
dim sURL
'**************************************************************************************************
'**************************************************************************************************



'The url to the webpage that you want the user to go to.
sURL= "http://www.google.com"




'**************************************************************************************************
'**************************************************************************************************
'**************************************************************************************************
'!!!!!!!!!!DO NOT CHANGE BELOW HERE UNLESS YOU KNOW WHAT YOU DOING!!!!!!
'**************************************************************************************************
'**************************************************************************************************
'**************************************************************************************************
dim objIE, bExit
bExit = 0
on error resume next

'Create an Internet Explore Browser
Set objIE = CreateObject("InternetExplorer.Application")    

objIE.navigate(surl) 'Navigate to the website

'Set the browser to fullscreen and theatermode
objIE.Fullscreen=true                                

'This makes the window not closable until the user exits the page using a script on the html
'page that has a window.close command or they use Alt-F4
'Setting the TheaterMode on and then off makes the object show properly.

objIE.TheaterMode=true                                        
objIE.TheaterMode=false                            

'Turn off the status bar
objIE.statusbar=false                                

'Turn off the toolbar
objIE.toolbar=false                                    

'Turn off Resizable
objIE.Resizable=false

while bExit=0                                        
    'While the browser is showing loop

    objIE.document.focus()                                
    'Set the browser to focus which brings it to the top.

    objIE.top =0            
    objIE.Left=0                            
    'Sets the window to the upper left hand corner

    if err.number <>0 then                            
        'if an error occured exit the program
    bExit = 1
    end if
wend
'Clean up the objects 

set objIE = nothing                                    

Points of Interest

The key to this working of course is the loop which moves the window into focus and to position 0,0.  It took a little playing around but it works very effectively.

History

Written on 2/22/2004

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Question[Message Deleted] Pin
BPB8975414-Jun-06 3:57
BPB8975414-Jun-06 3:57 
AnswerRe: Thanks, but does not work [XP-SP2] Pin
VincentGee114-Jun-06 4:05
VincentGee114-Jun-06 4:05 
GeneralRe: Thanks, but does not work [XP-SP2] Pin
VincentGee114-Jun-06 4:05
VincentGee114-Jun-06 4:05 
GeneralThanks for sharing Pin
Todd Davis25-Feb-05 3:49
Todd Davis25-Feb-05 3:49 
Despite the other comments, this is a useful article. A bit sparse admittedly, but the content of the code is fine. I know our IT department uses stuff like this when needed. For example, sometimes they need to "make sure" that things are read and responded to, such as Sarbanes-Oxley compliance info or licensing info.

Yes, it sucks and its annoying. But sometimes a neccessary evil.

Anyway, don't be discouraged by the negative comments. Everyone gets to share here, and sometimes the articles are targeted to a very small audience (such as yours) and the bigger audience starts to scream that it is useless. Don't listen to it. You did a good deed by sharing and giving back to the community, and at some point, someone who was looking for this exact code is going to find it, and be happy that you shared it.

Good work!

-Todd Davis (toddhd@gmail.com)
GeneralPlease nuke this now Pin
Shog922-Feb-05 8:58
sitebuilderShog922-Feb-05 8:58 
GeneralRe: Please nuke this now Pin
Christian Graus22-Feb-05 9:03
protectorChristian Graus22-Feb-05 9:03 
GeneralRe: Please nuke this now Pin
deceptus22-Feb-05 15:26
deceptus22-Feb-05 15:26 
GeneralRe: Please nuke this now Pin
Shog922-Feb-05 17:15
sitebuilderShog922-Feb-05 17:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.