Convert .vbs to .bat

Posted on 2009-04-29
Last Modified: 2012-05-06
I have a script that pulls the following information:
Dell Service Tag
OS Version
CD Key
"ipconfig /all"

Then it creates a txt file located in D:\Backup\CompInfo.txt

Is there an easy way to convert this to a .bat? I'm familiar with both .vbs and .bat, but I'm not a programmer.

const HKEY_LOCAL_MACHINE = &H80000002 

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"

strValueName = "DigitalProductId"

strComputer = "."

dim iValues()

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 

     strComputer & "\root\default:StdRegProv")

oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValues

Dim arrDPID

arrDPID = Array()

For i = 52 to 66

ReDim Preserve arrDPID( UBound(arrDPID) + 1 )

arrDPID( UBound(arrDPID) ) = iValues(i)


' <--------------- Create an array to hold the valid characters for a microsoft Product Key -------------------------->

Dim arrChars

arrChars = Array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9")


' <--------------- The clever bit !!! (Decrypt the base24 encoded binary data)-------------------------->

For i = 24 To 0 Step -1

k = 0

For j = 14 To 0 Step -1

k = k * 256 Xor arrDPID(j)

arrDPID(j) = Int(k / 24)

k = k Mod 24


strProductKey = arrChars(k) & strProductKey

' <------- add the "-" between the groups of 5 Char -------->

If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey


strFinalKey = strProductKey


' <---------- This part of the script displays operating system Information and the license Key --------->

Dim fso, MyFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set MyFile = fso.CreateTextFile("D:\Backup\CompInfo.txt", True)

strComputer = "." 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 

Set colItems = objWMIService.ExecQuery(_

"SELECT * FROM Win32_ComputerSystem",,48)

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Set colSMBIOS = objWMIService.ExecQuery (_

"Select * from Win32_SystemEnclosure") 

	Set objWMIService = GetObject("winmgmts:" _

  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _

  ("Select * from Win32_OperatingSystem")

Set wshShell=CreateObject("")

For Each objOperatingSystem in colOperatingSystems

For Each objSMBIOS in colSMBIOS 

For Each objItem in colItems 

strOS = objOperatingSystem.Caption

  strSerial = objOperatingSystem.SerialNumber


MyFile.WriteLine("Model: " & objItem.Model & vbCrLf & "Manufacturer: " & objItem.Manufacturer & vbCrLf & "Dell Service Tag: " & objSMBIOS.SerialNumber & vbCrLf & "OS: " & strOS & vbNewLine & "CD Key:" & vbTab & strFinalKey )






Set objShell = CreateObject("Wscript.Shell")

objShell.Run"%comspec% /k ipconfig /all >>D:\Backup\CompInfo.txt", 0, True

Open in new window

Question by:ninebal
    LVL 6

    Expert Comment

    Your best option would be to use the cscript command from within the .bat file to execute your .vbs script.

    Here are a couple of articles about how to do that (note there is a small typo in the example in the first link.

    Good luck

    LVL 28

    Expert Comment

    There is too uch string handling in the VBS, I'd say no way to translate it to a batch.
    Either go the way cerrmj suggested and wrap a batch around it like

    cscript /nologo yourscript.vbs

     or throw the VBS in Visual Studio VB and compile it to a command line utility.

    LVL 27

    Expert Comment

    If you want to compile it to an exe, download VBSEdit - you can compile a script into an exe using this and it's free :
    Then just call this in a batch script as you would any other command.

    Author Comment

    Okay, now that I am calling it from a bat file, it open up a command window and sits at a blinking curser. I can close the window manually, and the script works fine, I just need it to automatically close the command window.
    LVL 27

    Expert Comment

    This behaviour sometimes happens if you call the command without specifying the full path to it. Try using the full path (C:\folder\.....)
    LVL 21

    Expert Comment

    End of your batch file:


    Author Comment

    I have tried to put use the full path, and putting exit at the end of the files. Neither of those worked. I was able to get my scripts to run properly by adding a call to the bat file at the beginning of the vbs, but I hardcoded they path to the bat file. This will not work for what I need it to do.

    Basically I'm running 2 scripts and the printmig.exe to backup info from remote servers. I need to have it bundled into a single file so I'm using winrar to create an exe that will extract both scripts to a temp directory, run them, then delete the files when complete.

    My problem now is that I can't figure out how to call the bat file from the temp location in the vbs. I know you can do:

    set MyPath=%CD%
    call %CD%\MyFile.bat

    In command line, but how do you do that in vbs? I did find this script:

    Set fso = CreateObject("Scripting.FileSystemObject")
      wscript.Echo fso.GetParentFolderName(wscript.ScriptFullName)

    But again that doesn't quite do what I need it to do. I can usually follow a script and see what is is GENERALLY doing, but I'm pretty much worthless when it comes to writing the stuff
    LVL 6

    Accepted Solution

    How about setting up an environment variable on the system in question to use for the path to extract your files to and then to run the .bat and script file from.  Here is some info on how to setup an environment variable.

    Good luck.

    Author Closing Comment

    Thanks for all the great info!

    I actually "cheated" and made the vbs script it's own exe, then added that to the rest of my stuff

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now