ninebal
asked on
Convert .vbs to .bat
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.
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
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.
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.
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.
Then just call this in a batch script as you would any other command.
ASKER
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.
This behaviour sometimes happens if you call the command without specifying the full path to it. Try using the full path (C:\folder\.....)
End of your batch file:
exit
exit
ASKER
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.Fi leSystemOb ject")
wscript.Echo fso.GetParentFolderName(ws cript.Scri ptFullName )
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
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.Fi
wscript.Echo fso.GetParentFolderName(ws
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
I actually "cheated" and made the vbs script it's own exe, then added that to the rest of my stuff
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