Solved

Call VB Script silently for 2 batch files

Posted on 2016-09-08
7
42 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 52

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

18 Experts available now in Live!

Get 1:1 Help Now