Programming, VBScript

VBScript CommonDialog in Windows VISTA and Windows 7

vbscript-commondialog-in-windows-vista-and-windows-7

VBScript is a light, useful programming language (script) in Windows OS. We can write a VBS with notepad or any text editor.

Hard code the file with an absolute path is not a good idea to reuse a script for a normal user. They always don’t know how to modify the script. We always select a file with File Dialog. File Dialog is a user-friendly GUI for the user to select a specific file.

However, I discover that (I think many people discover that) Windows VISTA and Windows 7 do not have UserAccounts.CommonDialog in default system settings. And I search it on the internal, but I still can’t find the answers.

Finally, I re-design the VBS into HTML format. Normally, you must install Internet Explorer in your Windows System. You can embed VBScript in script tag. (<script type=”text/vbscript”></script>)

Use <input type=”file”/> to act a CommonDialog

Use <input type=”button”/> to act a invoker (optional)

So, how could connect VBScript and XML.

Very simple, take a look at this. You refer the code below.

<script type="text/vbscript">
Sub Invoke
    Set InputFile = document.getElementsByTagName("input")(0)
    Msgbox InputFile.Value
End Sub
</script>
<input type="file"/>
<input type="button" value="invoker" onclick="Invoke"/>

Now, we can easy to create a File Dialog in any Windows OSs.

Try it yourself.