?
Solved

Convert .vbs to .bat

Posted on 2009-04-29
9
Medium Priority
?
1,017 Views
Last Modified: 2012-05-06
I have a script that pulls the following information:
Model
Manufacturer
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)
Next
' <--------------- 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
Next
strProductKey = arrChars(k) & strProductKey
' <------- add the "-" between the groups of 5 Char -------->
If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
Next
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 )
  
Next
 
 
 
Next 
MyFile.Close
Next
 
Set objShell = CreateObject("Wscript.Shell")
objShell.Run"%comspec% /k ipconfig /all >>D:\Backup\CompInfo.txt", 0, True

Open in new window

0
Comment
Question by:ninebal
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 6

Expert Comment

by:cerrmj
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.

http://windowsitpro.com/article/articleid/15226/how-do-i-run-a-windows-script-from-the-command-line.html

http://windows-programming.suite101.com/article.cfm/windows_scripting_command_line_vbscript

Good luck


0
 
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.

0
 
LVL 27

Expert Comment

by:bluntTony
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.
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:ninebal
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.
0
 
LVL 27

Expert Comment

by:bluntTony
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\.....)
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 24272743
End of your batch file:

exit
0
 

Author Comment

by:ninebal
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
0
 
LVL 6

Accepted Solution

by:
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.
http://vlaurie.com/computers2/Articles/environment.htm

Good luck.
0
 

Author Closing Comment

by:ninebal
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
0

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