0

I am not able to embed VBScript in the Windows batch file.

Part of code cadastro.bat :

@echo off
 echo.
set /p opcao3= DESEJA EXPORTAR ? (S-SIM / N-NAO):
if %opcao3%== s goto:Export else goto :Error
if %opcao3%== S goto:Export else goto :Error
if %opcao3%== n goto:Buscar else goto :Error
if %opcao3%== N goto:Buscar else goto :Error
echo.

:Export

 For /f "delims=" %%i in ('Cscript //nologo "script_.vbs" "Selecione uma pasta"') do Set "folder=%%i\%codigoPesq%__RELATORIO.txt"
 For /f "eol=- delims=" %%i in ('find /I "%codigoPesq%__" Registros') do >>"%folder%" Echo.%%i

START %folder%
ECHO.
ECHO.
ECHO.
ECHO.
ECHO                      VERIFIQUE O LOCAL [%folder%]
ECHO.
echo.
echo                      ENTER PARA VOLTAR AO MENU PRINCIPAL

script.vbs:

Dim objFolder, objShell
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Selecione uma pasta.", &H4000, 0)
If Not (objFolder Is Nothing) Then
   wscript.echo objFolder.Self.path
Else
   wscript.echo 0
End If

I just wanted vbscript to be inside the batch, thank you for helping me.

0

1 Answer 1

2

As I understand the question you want to have a single file with both vbscript and batch code. If yes try this:

@echo off
 echo.
set /p opcao3= DESEJA EXPORTAR ? (S-SIM / N-NAO):
if %opcao3%== s goto:Export else goto :Error
if %opcao3%== S goto:Export else goto :Error
if %opcao3%== n goto:Buscar else goto :Error
if %opcao3%== N goto:Buscar else goto :Error
echo.

:Export

 For /f "delims=" %%i in ('cscript //nologo "%~f0?.wsf" //job:VBS') do Set "folder=%%i\%codigoPesq%__RELATORIO.txt"
 For /f "eol=- delims=" %%i in ('find /I "%codigoPesq%__" Registros') do >>"%folder%" Echo.%%i

START %folder%
ECHO.
ECHO.
ECHO.
ECHO.
ECHO                      VERIFIQUE O LOCAL [%folder%]
ECHO.
echo.
echo                      ENTER PARA VOLTAR AO MENU PRINCIPAL

exit /b %errorlevel%

<package>
  <job id="VBS">
    <script language="VBScript">
        Dim objFolder, objShell
        Set objShell = CreateObject("Shell.Application")
        Set objFolder = objShell.BrowseForFolder(0, "Selecione uma pasta.", &H4000, 0)
        If Not (objFolder Is Nothing) Then
           wscript.echo objFolder.Self.path
        Else
           wscript.echo 0
        End If
    </script>
  </job>
</package>

This uses a 'hack' described here. Though here the batch part is not put in xml comment block it should work fine and I find it more readable.Usually the cscript parser looks into .wsf files and gets only whats between <package> tags , though for robustness you can put a comment block for the batch code (or CDATA for even more robust code).

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

1 Comment

Hello friend, I tested the code that you gave me and I could not export the search. When it goes to search it opens another .BAT.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.