Background
We recently needed a way to launch executables on a Windows system, but wanted to run them from a web browser, locally. Turns out to be pretty easy with a little bit of VBScript.
Solution
Here’s a quick example on how to make a .html file that can be used to launch applications locally. This seems like a total hack and might have nefarious uses but it also can be used constructively. It only appears to work with Internet Explorer on Windows, and you’ll need to tell IE to allow the script to work, but other than that it’s an easy workaround.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <html> <body> <SCRIPT language=VBScript> sub RunProg(CommandLine) Dim ObjShell Set ObjShell = CreateObject("WScript.Shell") errorstate = ObjShell.Run(CommandLine, 1, False) 'Destroy Command line object Set ObjShell = Nothing end sub </SCRIPT> <INPUT onclick="RunProg('C:\Windows\system32\calc.exe')" type='button' value='pushme'> </body> </html> |
The key to this trick is calling this VBScript from within an HTML script block.
1 2 3 4 5 6 7 | sub RunProg(CommandLine) Dim ObjShell Set ObjShell = CreateObject("WScript.Shell") errorstate = ObjShell.Run(CommandLine, 1, False) 'Destroy Command line object Set ObjShell = Nothing end sub |
References
NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.
