Jump to content

Using batch files to open programs


tal ormanda

Recommended Posts

How can I make a batch file to open a program. Like tell it to go to that path and open it? Like to open adware: C:/Documents and Settings/holenone/Desktop/Anti-Virus/Ad-Aware can you make it go to that location and open it? If so, can you make it do more than one by putting it on the next line?

EDIT: I figured out how to make programs open, but now how to open many at once, if I put the other location below it, it will open once I close the other. Anyway to make them all open at once?

Edited by tal ormanda
Link to comment
Share on other sites


I do not use batch much but here is one way of doing it with a VBS script.

Dim Act  : Set Act = CreateObject("Wscript.Shell")
'/-> Place The Path Here This Uses Environment Varibles
Dim App1 : App1 = Act.ExpandEnvironmentStrings("%Userprofile%\holenone\Desktop\Anti-Virus\Ad-Aware\THE_EXE_HERE")
Dim App2 : App2 = Act.ExpandEnvironmentStrings("%ProgramFiles%\SOME_FOLDER\THE_EXE_HERE")
Dim App3 : App3 = Act.ExpandEnvironmentStrings("%SystemDrive%\SOME_FOLDER\THE_EXE_HERE")
Dim App4 : App4 = Act.ExpandEnvironmentStrings("%Windir%\System32\SOME_FOLDER\THE_EXE_HERE")
'/-> This Runs The App Remove ' To Make Active
'/-> Chr(34) Adds Quote To The Path In Case There A Space In The Name
' Act.Run(Chr(34) & App1 & Chr(34),1,False
' WScript.Sleep 3000
' Act.Run(Chr(34) & App2 & Chr(34),1, False
' WScript.Sleep 3000
' Act.Run(Chr(34) & App3 & Chr(34),1, False
' WScript.Sleep 3000
' Act.Run(Chr(34) & App4 & Chr(34),1, False
' WScript.Sleep 3000
'/-> Remove This It Only Will Show The Varibles Path
Act.Popup App1 & vbCrLf & App2 & vbCrLf & App3 & vbCrLf & App4,0,"Path To",0 + 32 + 4096

Here is another way using VBS scripts and a Array and a Loop

Dim Act  : Set Act = CreateObject("Wscript.Shell")
Dim App, StrA : App = Array(_
Act.ExpandEnvironmentStrings("%Userprofile%\holenone\Desktop\Anti-Virus\Ad-Aware\THE_EXE_HERE"),_
Act.ExpandEnvironmentStrings("%ProgramFiles%\SOME_FOLDER\THE_EXE_HERE"),_
Act.ExpandEnvironmentStrings("%SystemDrive%\SOME_FOLDER\THE_EXE_HERE"),_
Act.ExpandEnvironmentStrings("%Windir%\System32\SOME_FOLDER\THE_EXE_HERE"))
'/-> Loop Threw The Array Items
For Each StrA In App
'/-> This Runs The App Remove ' To Make Active
'/-> Chr(34) Adds Quote To The Path In Case There A Space In The Name
' Act.Run(Chr(34) & StrA & Chr(34),1,False
' WScript.Sleep 3000
'/-> Remove This It Only Will Show The Varibles Path If Not Needed Closes It Self In Four Seconds
Act.Popup StrA, 4, "App Path", 0 + 32 + 4096
Next

Edited by gunsmokingman
Link to comment
Share on other sites

...

He specifically said he wanted a batch file :wacko:

Try "start /?" from a command prompt to see its options, and use it to run the program.

I guess you must of missed this :wacko: it pays to read.

I do not use batch much but here is one way of doing it with a VBS script.

Since I can read and my reply to the original post was an alternative way of doing it what he wanted.

What you post does not add

1:\ A simple yes you can use the Start /Wait or Start /w to start the app

2:\ It provides no example of any type of code and how to use it

Examples that could of been adding
@Echo Off
CLS
Color F3
Mode 99, 7
Title Run App
Start /Wait "%Userprofile%\holenone\Desktop\Anti-Virus\Ad-Aware\THE_EXE_HERE"
Start /Wait "%ProgramFiles%\SOME_FOLDER\THE_EXE_HERE"
Start /Wait "%SystemDrive%\SOME_FOLDER\THE_EXE_HERE"
Start /Wait "%Windir%\System32\SOME_FOLDER\THE_EXE_HERE"

@Echo Off
CLS
Color F3
Mode 99, 7
Title Run App
Start "%Userprofile%\holenone\Desktop\Anti-Virus\Ad-Aware\THE_EXE_HERE"
ping -n 5 127.0.0.1>nul
Start "%ProgramFiles%\SOME_FOLDER\THE_EXE_HERE"
ping -n 5 127.0.0.1>nul
Start "%SystemDrive%\SOME_FOLDER\THE_EXE_HERE"
ping -n 5 127.0.0.1>nul
Start "%Windir%\System32\SOME_FOLDER\THE_EXE_HERE"
ping -n 5 127.0.0.1>nul

Example VBS Script With A Error Control

Dim Act  : Set Act = CreateObject("Wscript.Shell")
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim App, StrA : App = Array(_
Act.ExpandEnvironmentStrings("%Userprofile%\holenone\Desktop\Anti-Virus\Ad-Aware\THE_EXE_HERE"),_
Act.ExpandEnvironmentStrings("%ProgramFiles%\SOME_FOLDER\THE_EXE_HERE"),_
Act.ExpandEnvironmentStrings("%SystemDrive%\SOME_FOLDER\THE_EXE_HERE"),_
Act.ExpandEnvironmentStrings("%Windir%\System32\SOME_FOLDER\THE_EXE_HERE"))
'/-> Loop Threw The Array Items
For Each StrA In App
If Fso.FileExists(StrA) Then
'/-> This Runs The App Remove ' To Make Active
'/-> Chr(34) Adds Quote To The Path In Case There A Space In The Name
' Act.Run(Chr(34) & StrA & Chr(34),1, False
' WScript.Sleep 3000
'/-> Remove This It Only Will Show The Varibles Path If Not Needed Closes It Self In Four Seconds
Act.Popup StrA, 4, "App Path", 0 + 32 + 4096
Else
Act.Popup "Missing This File" & vbcrlf &_
StrA, 4, "Missing", 0 + 32 + 4096
End If
Next

Since your post does not offer any practical informatiom on what he wanted to do I wrote this for him.

Example batch cmd with a Error Control

@Echo Off
CLS
Color F3
Mode 99, 7
Title Run App
Set App1="%Userprofile%\holenone\Desktop\Anti-Virus\Ad-Aware\THE_EXE_HERE"
Set App2="%ProgramFiles%\SOME_FOLDER\THE_EXE_HERE"
Set App3="%SystemDrive%\SOME_FOLDER\THE_EXE_HERE"
Set App4="%Windir%\System32\SOME_FOLDER\THE_EXE_HERE"

:: Check For The First APP
If Exist %App1% Goto Run_App1
If Not Exist %App1% Goto OPS_App1

:: Check For The second APP
:RunApp2
If Exist %App2% Goto Run_App2
If Not Exist %App2% Goto OPS_App2

:: Check For The Third APP
:RunApp3
If Exist %App3% Goto Run_App3
If Not Exist %App3% Goto OPS_App3

:: Check For The Fourth APP
:RunApp4
If Exist %App4% Goto Run_App4
If Not Exist %App2% Goto OPS_App4

:App1
start %App1%
ping -n 5 127.0.0.1>nul
Goto RunApp2

:: Run The Second App
:App2
start "%App2%"
ping -n 4 127.0.0.1>nul

:: Run The Third App
:App3
start "%App3%"
ping -n 5 127.0.0.1>nul

:App4
start "%App4%"
ping -n 5 127.0.0.1>nul
Goto TheEnd

:: Missing The First App
:OPS_App1
CLS
Echo.
Echo Missing This File
Echo -^> %App1%
ping -n 4 127.0.0.1>nul
Goto RunApp2

:: Missing The Second App
:OPS_App2
CLS
Echo.
Echo Missing Ths File
Echo -^> %App2%
ping -n 4 127.0.0.1>nul
Goto RunApp3

:: Missing The Third App
:OPS_App3
CLS
Echo.
Echo Missing Ths File
Echo -^> %App3%
ping -n 4 127.0.0.1>nul
Goto RunApp4

:: Missing The Fourth App
:OPS_App4
CLS
Echo.
Echo Missing Ths File
Echo -^> %App4%
ping -n 4 127.0.0.1>nul
Goto TheEnd

:TheEnd
Goto EOF
Exit

Any way to run app1, wait for it to close, then 2 wait for close then 3 and so on?
Yes there is

Cmd Promt

start /wait SOME_APP
or
start /w SOME_APP

VBS Script

The Number 0 means to start it hidden

The Number 1 means to start it not hidden and full size

The Number 2 means to start it and only show the dialog on the task bar

True means wait for the app

False means not to wait for the app

Act.Run(Chr(34) & StrA & Chr(34),1, True

Link to comment
Share on other sites

That Sample batch file is fabulous! Good work!

In the original post, AdAware was used as an example. If that's the actual program to be used in the batch file, once run, there are two choices to make,,,,,Check for Updates or Run a Scan. Which would you be doing and do you know the command line option to make it do that automaticly?

To just run programs that are going to require operator intervention doesn't avail you much.

You might as well just run the program from a desktop icon. (I do!)

I use batch files a lot and have for 26 years, so I find this thread "Velly Intelestink"!

Thank Y'all for some interesting work, :thumbup

B)

PS: Batch language has gone through several transitions in the years since I learned it and taught it in our local "Community Education Dept." My last book on Batch was the DOS 6.22 manual. Don't laugh!

Where can I find a tutorial or manual on the current batch language? Anyone know?

I saw commands in that big batch file that were totally unknown to me and I'd love to get 'up to date'.

Edited by Andromeda43
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...