Blog

Thoughts, views, rants. You know the drill.

If you support any company's computer infrastructure you will often find that being able to script, or at least having someone who can script on your team, is very useful.

This coming week a client is relaunching an internal initative and wanted a popup to start up on each user's session advertising the relaunch. When they came to us originally and asked for it to be done we were having a bit of trouble coming up with a decent idea. We're sodding busy and we didn't think that writing and compiling some small application to do this was worth it, and we were asked with a little over 1 working day to come up with something.

Over night I had an awesome idea; why create a new application? This client is running a Windows only domain, and the one thing that we know is on all desktops, laptops and terminal servers? Internet Explorer. We also use a login script that executes every logon.

If you're not aware most things in Windows are controllable via the various Windows Scripting technologies. Whilst a lot of the documentation is tricky to find, Internet Explorer is no different. Here's what we've eventually ended up deploying.
Option Explicit ' We need the on error.. incase the user closes the window before the sleep finishes, ' this prevents any error popups On Error Resume Next Dim ie, sh, widthscreen, heightscreen, widthwindow, heightwindow Set sh = CreateObject("WScript.Shell") Set ie = CreateObject("InternetExplorer.Application") ie.ToolBar = False ie.StatusBar = False ie.Resizable = False ie.Navigate("http://webserver/yourfile") ' Wait until ie is ready Do Until ie.readyState = 4 Wscript.Sleep 25 Loop ' Screen dimensions widthscreen = ie.document.ParentWindow.Screen.AvailWidth heightscreen = ie.document.ParentWindow.Screen.AvailHeight ' We wanted a 90% screen size widthwindow = ie.document.ParentWindow.Screen.AvailWidth * .9 heightwindow = ie.document.ParentWindow.Screen.AvailHeight * .9 ie.document.ParentWindow.resizeto widthwindow, heightwindow ' Center the ie window ie.document.ParentWindow.moveto ((widthscreen - widthwindow) / 2), ((heightscreen - heightwindow) / 2) ' We wanted to disable the scroll bars ie.document.ParentWindow.document.body.scroll = "no" ' Show the window ie.Visible = True ' Hello! sh.AppActivate "Your title" ' Wait 10 seconds Wscript.Sleep 10000 ' Close ie.Quit ' Clean Up Set ie = Nothing Set sh = Nothing
Simply create a webpage, add it to an internal web server, and then call this in your logon script (with the relevant changes), and you're well away. Since we use a simple batch file, rather than another script, all we needed to add was (I added the "start" command as I didn't want the logon script to block until the popup was closed):
start cscript \\path\to\popup.vbs

Just make sure that you get your web address correct!