Solved

Call VB Script silently for 2 batch files

Posted on 2016-09-08
7
53 Views
Last Modified: 2016-09-14
Hello,

I have the below code. Basically I am trying to run the VB script which calls 2 batch files present in 2 locations.
The below code does not work as desired. Please help

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\dell\hwv1.1.bat" & Chr(34), 0
WshShell.Run chr(34) & "C:\Drivers\batch2v1.2.bat" & Chr(34), 0


Set WshShell = Nothing

Open in new window

0
Comment
Question by:Siddharth S
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 41790204
Can you explain further.  What happens currently, what is displayed, and what behavior are you trying to change?

~bp
0
 

Author Comment

by:Siddharth S
ID: 41793401
Okay I think I posted the wrong question without checking completely. The issue seems to be with the batch file.

Bill, could you please check the below code, when I run it from the cmd pointing to the .bat file then the file saves properly with the %servicetag% but when I double click on it, it saves without a name and I cant even open the csv. Not sure what the reason is:

@ECHO OFF 
SETLOCAL EnableExtensions EnableDelayedExpansion


set OutputFile=C:\Drivers\%SERVICETAG%.csv
echo "Computer","Key","Version","Name","Publisher">"%OutputFile%"

call :getsw "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall"
call :getsw "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall"
call :getsw "HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

ENDLOCAL
exit /b

:getstg
for /f "delims== tokens=2" %%i in ('wmic bios get serialnumber /value') do SET SERVICETAG=%%i



:getsw
    for /F "delims=" %%g in ('reg query "%~1" 2^>NUL') do (
        set "_swRegKey=%%~g"
        set "_swName="
        set "_swVers="
        set "_swPub="
       
        for /F "tokens=1,2,*" %%G in ('
          reg query "%%~g" /V DisplayName 2^>NUL ^| findstr /I "DisplayName"
                                      ') do set "_swName=%%~I" 
        for /F "tokens=1,2,*" %%G in ('
          reg query "%%~g" /V DisplayVersion 2^>NUL ^| findstr /I "DisplayVersion"
                                      ') do set "_swVers=%%~I"
        for /F "tokens=1,2,*" %%G in ('
          reg query "%%~g" /V Publisher 2^>NUL ^| findstr /I "Publisher"
                                      ') do set "_swPub=%%~I"
       
        call :echosw 
        ) 
    exit /b

:echosw
    if "!_swName!!_swVers!"=="" (
        echo "%SERVICETAG%","unknown","!_swRegKey!","","">>"%OutputFile%"
    ) else (
        echo "%SERVICETAG%","!_swRegKey!","!_swVers!","!_swName!","!_swPub!">>"%OutputFile%"
    )
    exit /b

Open in new window


EDIT: I changed the code. Pasted the wrong code before.
0
 

Author Comment

by:Siddharth S
ID: 41793403
NVM, figured it out.. Silly mistake.. Checking vbs now
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Siddharth S
ID: 41793424
Okay so VB script is not calling the second batch file in the below code.
The first one executes fine but the second one does not.

Thanks in advance Bill.. You have been mighty helpful over the past few days.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 41793547
Okay so VB script is not calling the second batch file in the below code.

What VBS, what code below?

~bp
0
 

Author Comment

by:Siddharth S
ID: 41794757
Sorry, it actually works. I think.. Have to test it on other systems.
But here is the code.

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\dell\hwv1.1.bat" & Chr(34), 0
WshShell.Run chr(34) & "C:\Drivers\batch2v1.2.bat" & Chr(34), 0

Set WshShell = Nothing

Open in new window

0
 

Author Closing Comment

by:Siddharth S
ID: 41797587
Bill Prew, helpful and trying to help always. :)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question