Tag Archive: VBScript

Pin .bat Batch File or Shortcut to Start Menu / Taskbar with Custom Icon – Windows 7, 8 & 10

So you want to pin a batch file or shortcut with a custom icon to the start menu / taskbar in Windows 7, 8 and 10?

Easily add a batch file (.bat) to the taskbar by following these steps:

1. Rename your .bat or .cmd file extension to .exe
2. Right click the newly renamed .exe file and select pin to taskbar
3. Rename the file extension back to .bat or .cmd
4. Shift+right click the newly pinned .exe taskbar icon and choose properties
5. Change the file extension from .exe to .bat or .cmd and change the icon as needed. (for lots of system icons here use the path: “%SystemRoot%\system32\SHELL32.dll”)
6. The shortcut will work immediately you’ll need to reboot or just kill explorer.exe in task manager and re-run it to update/refresh the icon if you changed it.

I use the method above to launch .vbs scripts from the taskbar.
Here’s how to create a .bat file to run vbs scripts…

Open notepad to create a blank text file and add one of the following lines
wscript.exe yourscript.vbs (wscript just runs the vbs as a Windows process)
or
cscript.exe yourscript.vbs (cscript runs the vbs in a command/console window)
then save the text file as a .bat file in the same folder as the .vbs script file.

 

If this helps you out please feel free to say thanks by clicking “Buy Me a Coffee” PayPal button in the sidebar (here) or via:https://www.paypal.me/AlanHart

Thank You

VBS Option Box – Simple VBScript MsgBox / Dialog Box with Options

I needed to create a basic script to execute a user selected routine but needed a simple way to capture the users choice. Like a MsgBox but with multiple options.
Here’s some nice simple code for a VBScript Option Box in case you want to do the same.

First we create a very basic HTML file which will act as the dialog box. (the options and buttons)…

<HTML>
<HEAD>
<TITLE>Make a selection</TITLE>
<SCRIPT language="VBScript">

Sub OKClick
If MenuOption(0).Checked Then
ChosenOption.Value = "Option 1"
End If
If MenuOption(1).Checked Then
ChosenOption.Value = "Option 2"
End If
If MenuOption(2).Checked Then
ChosenOption.Value = "Option 3"
End If
End Sub

Sub CancelClick
ChosenOption.Value = "Cancelled"
End Sub

</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<BR>
<B>Please select an option:</B><P>
<input type="radio" name="MenuOption" checked="true">Option 1<BR>
<input type="radio" name="MenuOption">Option 2<BR>
<input type="radio" name="MenuOption">Option 3
<P>
<input type="Button" value="OK" onClick="OKClick()">
<input type="Button" value="Cancel" onClick="CancelClick()">
<input type="hidden" name="ChosenOption">

</CENTER>
</BODY>
</HTML>

The hidden input above is used to store the users chosen option.
The VBScript below, opens the HTML file and loops while waiting for this chosen option value to change.
When this chosen option value changes the VBScript captures this chosen option in a variable so it knows what the user selected.

Set objExplorer = CreateObject("InternetExplorer.Application")

objExplorer.Navigate "file:///C:\Script\option.htm"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 230
objExplorer.Visible = 1

Do While (objExplorer.Document.All.ChosenOption.Value = "")
Wscript.Sleep 250
Loop

strSelection = objExplorer.Document.All.ChosenOption.Value

objExplorer.Quit

Wscript.Sleep 250

Select Case strSelection
Case "Option 1"
Wscript.Echo "You selected Option 1."
Case "Option 2"
Wscript.Echo "You selected Option 2."
Case "Option 3"
Wscript.Echo "You selected Option 3."
Case "Cancelled"
Wscript.Quit
End Select

Of course, instead of echoing the selected option you would put the code you want to run under each case.

This is a nice flexible solution allowing you to easily add/remove options.

You can do away with the OK button and, in the HTML, add onClick="OKClick()" to the radio button elements, so the user only needs to click once on the option they want.


If this info helps you out, tweet me to say thanks or

Because I’m so nice you can download the VBS and HTML files in this handy VBS Option Box Script Zip(851 bytes)
Note: make sure to put the HTML file in "C:\Script\" to test. (Or change the line in the .VBS file pointing to the location of the HTML file.