Convert .vbs to .bat

Posted on 2009-04-29
Medium Priority
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("wscript.shell")
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
  • 3
  • 2
  • 2
  • +2

Expert Comment

ID: 24265744
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 29

Expert Comment

by:Michael Pfister
ID: 24267383
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

ID: 24269684
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 : http://www.vbsedit.com/
Then just call this in a batch script as you would any other command.
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

ID: 24269778
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

ID: 24269922
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

ID: 24272743
End of your batch file:


Author Comment

ID: 24272938
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

Accepted Solution

cerrmj earned 2000 total points
ID: 24276563
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

ID: 31576190
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Phishing is at the top of most security top 10 efforts you should be pursuing in 2016 and beyond. If you don't have phishing incorporated into your Security Awareness Program yet, now is the time. Phishers, and the scams they use, are only going to …
This story has been written with permission from the scammed victim, a valued client of mine – identity protected by request.
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.
Where to go on the main page to find the job listings. How to apply to a job that you are interested in from the list that is featured on our Careers page.
Suggested Courses

807 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