GUI for batch file?

21,971

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
'*****************************************************************
'---------------------

'***************************************
Share:
21,971
Admin
Author by

Admin

Updated on January 23, 2021

Comments

  • Admin
    Admin over 3 years

    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.

  • SeanC
    SeanC over 11 years
    line wrap got me. original had line numbers, and I chopped off a but of the program when I cut them out
  • Admin
    Admin over 11 years
    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?
  • SeanC
    SeanC over 11 years
    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
  • Admin
    Admin over 11 years
    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.
  • SeanC
    SeanC over 11 years
    wscript and/or cscript can be used to run vbs scripts, e.g cscript test.vbs or wscript test.vbs
  • Admin
    Admin over 11 years
    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.
  • SeanC
    SeanC over 11 years
    did you copy from my code block, or the example? I have put it on pastebin if that may be easier for you
  • Admin
    Admin over 11 years
    Yes, I got a little farther into the code, no output other than syntax error. Line 39 has expected ")".
  • Admin
    Admin over 11 years
    Still no luck, man this is harder than i thought it would be.
  • SeanC
    SeanC over 11 years
    if you use notepad++, you can see the line and column in the status line.
  • Admin
    Admin over 11 years
    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.
  • SeanC
    SeanC over 11 years
    line 39 is WScript.Echo "You entered an invalid menu choice!". There should be no () there
  • SeanC
    SeanC over 11 years
    here is the file, ready for download, and running fine on my system
  • Admin
    Admin over 11 years
    You made my day! Haha, thank you very much, I will defininlty be using it, I wonder what I was doing wrong?