3

I have a batch file, and it is a very simple program that launches website, a mini- web browser type experience, with commands that open programs, etc. How can i make an interface for this or a GUI? Without having to compleltey manually change my code. Here is an example of what my code is like:

:start
@echo off
COLOR 1E
cls
echo Welcome to Wannow Dashboard.  This is the main page.
echo Type in the number to be redirected to your desired location.
echo 1. Useful Websites
echo 2. Programs     
echo Wannow Dashboard created by Brad Wannow

set/p var1=
if %var1% == 1 goto Websites
if %var1% == 2 goto program
pause
exit

:websites
COLOR 1E
cls
echo Welcome to Wannow Dashboard: Websites. Select a command, type in number to be redirected.
echo 1. www.Pandora.com
echo 2. www.Google.com
echo 3. Aventa Blackboard
echo 4. Other
@echo OFF 

@echo %time% 
ping -n 1 -w 1 127.0.0.1 1>nul        
echo Wannow Dashboard 

Of course there is much more code, but this is the way my program is written, with also some START commands and user inputs, etc.

Matt
  • 74,352
  • 26
  • 153
  • 180
user1683444
  • 31
  • 1
  • 1
  • 3
  • graphical commands are not available in straight batch files. I would suggest you look at vbscript or powershell – SeanC Sep 19 '12 at 17:56
  • And then would my code have to be completley changed and things wouldn't work the same? How could I take the code above and change it into vbscript and add graphics? – user1683444 Sep 19 '12 at 18:05
  • there are many guides - this is the help file for [vbscript](http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en). yes it will be different. `Echo Hello World` would become `msgbox("Hello World")` and an input would look like `inputbox("What is your name?")` (at a very basic level) – SeanC Sep 19 '12 at 18:15
  • okay, thanks. I wish they could just automatically convert my code. to .vbs, and how will it look after it is converted? – user1683444 Sep 19 '12 at 18:49
  • there is no automatic conversion, and unless you have Visual Studio, no free integrated developer, but [notepad++](http://notepad-plus-plus.org/) seems to be the preferred editor because of its syntax highlighting – SeanC Sep 19 '12 at 18:58
  • Well, do you understand the batch file's code above? and what it does? And how that would work in a different language? – user1683444 Sep 19 '12 at 19:00
  • https://www.vistax64.com/vb-script/177754-create-menu.html#post826436 has an example script with a menu – SeanC Sep 19 '12 at 19:05

1 Answers1

3

graphical commands are not available in straight batch files. I would suggest you look at vbscript or powershell

there are many guides - this is the help file for vbscript. yes it will be different. Echo Hello World would become msgbox("Hello World") and an input would look like inputbox("What is your name?") (at a very basic level)

there is no automatic conversion, and unless you have Visual Studio, no free integrated developer, but notepad++ seems to be the preferred editor because of its syntax highlighting

from here, an example script with a menu

'-----------------------------------------------------------------
' Name: Menu Template Script
' By: Harvey Colwell
' CopyRight: (c) Jul 2000, All Rights Reserved!
'
'*****************************************************************
Option Explicit

Dim oFS, oWS, oWN

Set oWS = WScript.CreateObject("WScript.Shell")
Set oWN = WScript.CreateObject("WScript.Network")
Set oFS = WScript.CreateObject("Scripting.FileSystemObject")

'----------
' Script SetUp
'----------

'----------
' Main
'----------
Select Case InputBox ( _
"Enter menu item number then Click Ok. . ." & vbCrlf & vbCrlf & _
" [1] Item 1" & vbCrlf & _
" [2] Item 2" & vbCrlf & _
" [3] Item 3" & vbCrlf & _
" [4] Item 4", _
"Main Menu")

Case "1"
Call sub1()
Case "2"
Call sub2()
Case "3"
Call sub3()
Case "4"
Call sub4()
Case Else
WScript.Echo "You entered an invalid menu choice!"

End Select

'----------
' Clean Up
'----------

Call CleanUp

'-----------------------------------------------------------------
' Subroutines
'*****************************************************************

'---------------------
Sub CleanUp()
Set oWS = Nothing
Set oWN = Nothing
Set oFS = Nothing
WScript.Quit
End Sub

'---------------------
Sub sub1()
WScript.Echo "You selected Menu Item 1"
End Sub

'---------------------
Sub sub2()
WScript.Echo "You selected Menu Item 2"
End Sub

'---------------------
Sub sub3()
WScript.Echo "You selected Menu Item 3"
End Sub

'---------------------
Sub sub4()
WScript.Echo "You selected Menu Item 4"
End Sub

'-----------------------------------------------------------------
' Functions
'*****************************************************************
'---------------------

'***************************************
SeanC
  • 15,695
  • 5
  • 45
  • 66
  • line wrap got me. original had line numbers, and I chopped off a but of the program when I cut them out – SeanC Sep 19 '12 at 20:25
  • I'm sorry, but how do you open a .vbs file? OR what do I open it with .etc? Should i write it in Notepad++ or what also? Because it doesnt work as just a .vbs file and open like .bat? – user1683444 Sep 20 '12 at 02:18
  • you should be able to either double click on the file, or run it from the command line, including the extension e.g. `C:\> test.vbs` – SeanC Sep 20 '12 at 02:20
  • Where do I include the extension? Sorry, I am new to the coding world, as you can see. Sorry if I am asking way too many questions. But the program keeps saying line 4 has a sytax error, expecting statement. – user1683444 Sep 20 '12 at 02:31
  • wscript and/or cscript can be used to run vbs scripts, e.g `cscript test.vbs` or `wscript test.vbs` – SeanC Sep 20 '12 at 13:21
  • It does not open, it says expected statment on the first line of code 'Option Explicit', I don't know what to debug, because I didn't write the code and it cannot even get through the first line. – user1683444 Sep 20 '12 at 15:09
  • did you copy from my code block, or the example? I have put it on [pastebin](http://pastebin.com/GJxPhTJS) if that may be easier for you – SeanC Sep 20 '12 at 16:24
  • Yes, I got a little farther into the code, no output other than syntax error. Line 39 has expected ")". – user1683444 Sep 20 '12 at 17:20
  • Still no luck, man this is harder than i thought it would be. – user1683444 Sep 20 '12 at 17:26
  • if you use notepad++, you can see the line and column in the status line. – SeanC Sep 20 '12 at 18:15
  • I do use notepad++, and i see the line and a put the parenthesis where it said i needed it. It gives the same error. – user1683444 Sep 20 '12 at 18:35
  • line 39 is `WScript.Echo "You entered an invalid menu choice!"`. There should be no `()` there – SeanC Sep 20 '12 at 18:39
  • [here](https://docs.google.com/open?id=0B-WkQSncXamiZnlTclFyUEJNbWs) is the file, ready for download, and running fine on my system – SeanC Sep 20 '12 at 18:42
  • You made my day! Haha, thank you very much, I will defininlty be using it, I wonder what I was doing wrong? – user1683444 Sep 20 '12 at 18:47