0

Please lend some help, I'm a beginner with batch file and vbscript. I would be grateful if you could help me solve my problem.

Given:

a:

@echo off
pushd "C:\Program Files\appName" && popd
IF ERRORLEVEL 1 EXIT 0
pushd "C:\Program Files\appName"
IF EXIST application.exe GOTO Installed
popd
EXIT 1
:Installed
EXIT 2

b:

Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objFile = objFSO.OpenTextFile(listFile, 1)

dim sh , res

objName = objFSO.GetTempName
objTempFile = objName
'---- Sample Code 0 ----------------------'
'set sh = WScript.CreateObject("WScript.shell")
'res = sh.run("fileFullPath",0,true)
'wScript.echo  res
'----Sample Code 1 ---------------'
'set sh = WScript.CreateObject("WScript.shell")
'res = sh.run("fileName",0,true)
'wScript.echo  res
'---- Sample Code 2 ---------------------
'set sh = WScript.CreateObject("WScript.shell")
'res = sh.run("cmd /c fileName",0,true)
'wScript.echo  res
'---- Sample Code 3 ---------------------
'set sh = WScript.CreateObject("WScript.shell")
'res = sh.run("cmd /c fileFullPath",0,true)
'wScript.echo  res

The b:sample code 1 & 2 works fine with me but I need the sample code 0 & 3. with sample code 1 I always get an error : The system cannot find the file selected ,while with sample code 3 it would only return 0 when failed then 1 when successful, and not the returned value of the batch file.

Thanks,

4
  • Sample code 3 worked just fine when I tested it. However, exit code 0 normally means "success", so you shouldn't return it in case of an error. I would also recommend using exit /b instead of just exit. Commented Mar 6, 2014 at 12:45
  • Thanks for the response @AnsgarWiechers. I already have tried using exit /b before, but it still won't work. Considering that the file I'm going to search does exists. With sample code 1 & 2 it gives the value of 2. While with Sample Code 3, specified the full path of the batch file I keep on having 1 as my output. Is there another way around for me to have same output as sample code 1 & 2 given that I have to access the batch file by it's full path. Thanks. Commented Mar 6, 2014 at 23:04
  • Code 1 & 2 should only work when the batch script is in the current working directory. Other than that all 4 samples should yield the same result. Please provide evidence. Commented Mar 7, 2014 at 8:10
  • Hello @Ansgar-Wiechers. Yes, code 1 & 2 does only works that way. That's why I'm needing 0 & 3. It didn't yield same result because 0 & 3 result is equals to 1 means fail, Thanks for kick --> "0 normally means success". Commented Mar 7, 2014 at 9:57

1 Answer 1

1

I already got my problem solved just a while ago. I found out that even-though i already have had "cmd /c fileFullPath" double-quoted. When a folder name(s) consists some spaces, it would cause an issue --> file can't be found. Now I'm using "cmd /c ""fileFullPath""" instead.

Sorry for having my first post lack of information. I will do my best to make it clearer next time. Thanks a lot. :D

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.