Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Translate simple .bat file to .vbs

Status
Not open for further replies.

Soundlover4711

Technical User
Joined
Jul 27, 2005
Messages
15
Location
NL
Hi All!

I'd like to check if a file exists, if it exists the script should go on and do nothing, if the file doesn't exists the script should start a batch file for software installation.

In .bat it would look like this:
----------------------------------
if not exist "C:\CENTENN.IAL\AUDIT\CAgent32.exe" goto INSTALL
EXIT

:INSTALL
"C:\Program Files\Cent\InstCent.bat"
EXIT
----------------------------------

Could someone please help me in translating this to .vbs???

Thanks!!!!
 
look at the filesystemobject and WshShell
Set WshShell = CreateObject("Wscript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
str2Find = WshShell.ExpandEnvironmentStrings(%programfiles%\appA\app.exe")
intReturn = 0
str2Run = WshShell.ExpandEnvironmentStrings(%programfiles%\appinstall.exe")
If FSO.FileExists(str2Find) Then
'do nothing
Else
If FSO.FileExists(str2Run) Then
intReturn = WshShell.Run("%programfiles%\run.exe", 1, True) 'or False
Else
intReturn = 1
End If
End If

Set WshShell = Nothing
Set FSO = Nothing
Wscript.Quit intReturn
 
Hi, Thanks!

In my test environment it was working but now there seems to be something wrong in this line:

--------
intReturn = WshShell.Run("C:\Program Files\Cent\InstCent.bat", 1, True) 'or False
--------

??? I don't know what ???

Thx 4 help!
 
intReturn = WshShell.Run(Chr(34) & "C:\Program Files\Cent\InstCent.bat" & Chr(34), 1, True)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
thanks PHV, always miss out the "" on these sorts of posts.

soundlover, try and avoid hard coded paths to stuff like program files etc etc try and use things like

%windir%, %programfiles%, %computername% etc etc

should make things more robust
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top