Solved

Call VB Script silently for 2 batch files

Posted on 2016-09-08
7
37 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
  • 5
  • 2
7 Comments
 
LVL 51

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 51

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now