Search code examples
windowsbatch-filevbscript

include .bat code into vbs


I have this "launchprogram.bat" to call "myprogram.exe" (real name ppbS.exe)

Original code launchprogram.bat

call "ppbS.exe"
set ppbPath=ppbS
set pathHold=%path%
set path=%ppbPath%;%path% 
ppbS create "ppbS" ShowPct 1 No Crawl 1 SetCrawlTime 1 300000
ppbS settext 1 "Start myprogram... Be pacient"
second.bat
ppbS shutdown
set path=%pathHold%
set pathHold=
set ppbPath=

Note: "second.bat" is another bat run hide

extra: This version of "launchprogram.bat" is provided by Noodles

"Cmd /c ""ppbS.exe"" & Dir & set ppbPath=ppbS & set pathHold=%path% & set path=%ppbPath%;%path% & ppbS create ""ppbS"" ShowPct 1 No Crawl 1 SetCrawlTime 1 300000 & ppbS settext 1 ""Start myprogram... Be pacient"" & second.bat & ppbS shutdown"

Anyway; i used this "start.vbs" to call "launchprogram.bat"

On Error Resume Next
mensaje = MsgBox("Start myprogram", vbOKCancel, "myprogram")
If mensaje = vbOK Then
    Script = "launchprogram.bat"
    Set objshell = CreateObject("Wscript.Shell")
    strPath = Wscript.ScriptFullName
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile(strPath)
    strFolder = objFSO.GetParentFolderName(objFile)
    NewPath = objFSO.BuildPath(strFolder, Script)
    Set objshell = CreateObject("wscript.shell")
    objshell.Run NewPath, vbHide
Else
    Set objshell = CreateObject("Wscript.shell")
    rmensaje = objshell.popup("Cancel myprogram", 3, "myprogram", 16)
End If

As you can see, they are too many scripts and too many codes to call a simple program.

Request:

I want to delete "launchprogram.bat" and put its code into "start.vbs", for use only one script to call "myprogram.exe"

Thanks a lot


Solution

  • objshell.run "Cmd /c ""myprogram.exe"" & Dir & set ppbPath=myprogram & set pathHold=%path% & set path=%ppbPath%;%path% & ppbS create ""myprogram"" ShowPct 1 No Crawl 1 SetCrawlTime 1 300000 & ppbS settext 1 ""Start myprogram... Be pacient"" & ppbS shutdown", vbhide
    

    VBHide isn't defined. If it was it would be 0. As undefined it is treated as 0. This is because constants aren't available in VBScript. It's just luck that VBHide happens to be 0.