Solved

Call VB Script silently for 2 batch files

Posted on 2016-09-08
7
61 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 56

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 56

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

617 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