.bat file help
-
12 มีนาคม 2554 17:28
im trying to write a batch file that will ask me to select which programs open (that way i can open up some of my most used programs, but not all of which i preloaded) so for instance it would ask:
Choose which programs to run:
np. . . . . . . Run notepad
gc. . . . . . . Open Google Chrome
itunes. . . . .Open iTunes
then i would type which ones i would like to open. therefore, if i wanted to listen to music while browsing the internet i would type something simlilar to
gc, itunes
and i could mix and match any of the three
however, i am a little new to the command prompt and writing batch files. im guessing i need an if-then-else instance for this. but i wouldnt know how to tell the computer if i type gc, start(path to google chrome application). how would i?
ตอบทั้งหมด
-
14 เมษายน 2554 20:22
I wouldn't use .bat, I would use .vbs. Copy and paste following into text file and change extension to .vbs
StartMenu()
Sub StartMenu()
Notepad = "C:\Windows\System32\notepad.exe"
GoogleChrome = "C:\PathToGoogleChrome\Chrome.exe"
iTunes = "C:\PathToiTunes\iTunes.exe"Set wshShell = WScript.CreateObject ("WSCript.shell")
Option1 = "1) Notepad"
Option2 = "2) Google Chrome"
Option3 = "3) iTunes"
QueryChoice = InputBox(Option1 & VbCrLf & VbCrLf & Option2 & VbCrLf & VbCrLf & Option3 & VbCrLf & VbCrLf & Option4 & VbCrLf & VbCrLf & "Choose which program to run: ","Program Picker","")Set objRegExp = New RegExp
With objRegExp
.Pattern = "[0-3]"
.IgnoreCase = True
.Global = True
End WithIf QueryChoice = "" Then
wscript.quit
ElseIf objRegExp.Test(QueryChoice) Then
Select Case QueryChoice
Case 1
wshShell.run Notepad
Case 2
wshShell.run GoogleChrome
Case 3
wshShell.run iTunes
Case Else
Wscript.echo "Invalid Selection..."
StartMenu()
End Select
Else
Wscript.echo "Invalid selection..."
StartMenu()
End ifEnd Sub