Solved

Call VB Script silently for 2 batch files

Posted on 2016-09-08
7
48 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 53

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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 53

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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