Jump to content

Conversion from batch file to VBS script


Recommended Posts

I am wondering if it is an "easy" process to convert this batch file to a vb script:

FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\CD.bin SET CDROM=%%i:

if not exist %windir%\system32\reg.exe copy "%CDROM%\CD\W2K\reg.exe" %windir%\system32

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

REG ADD %KEY% /V TITLE /D "Test" /f

REG ADD %KEY%\001 /VE /D "MS Office Pro 2003 Fr." /f
REG ADD %KEY%\001 /V 1 /D "\\Source\setup.exe TRANSFORMS=Unattended.mst /qb-" /f

rundll32.exe iernonce.dll,RunOnceExProcess

Any input appreciated! :hello:

Link to comment
Share on other sites


It's quite easy. I'll post one of my scripts that has those elements in it for you to look at. This is the VBscript I run from cmdlines.txt:

Option Explicit
Dim ws, fs, sysdrv, windir, progdir, Drives, Drive, strCD, strOEM
Set ws = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
sysdrv = ws.ExpandEnvironmentStrings ("%SYSTEMDRIVE%")
windir = ws.ExpandEnvironmentStrings ("%SYSTEMROOT%")
progdir = ws.ExpandEnvironmentStrings ("%PROGRAMFILES%")
Drives = Array("C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", _
"T", "U", "V", "W", "X", "Y", "Z")
For Each Drive In Drives
If fs.FileExists(Drive & ":\WIN51") Then strCD = Drive & ":\"
Next
strOEM = strCD & "OEM\"

'**********************************************************************
'** Subroutine; Set the RunOnceEx key with values                    **
'**********************************************************************
Sub SetROE
Dim strKeyPath
strKeyPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\"
ws.RegWrite strKeyPath & "TITLE", "Installing Software", "REG_SZ"
ws.RegWrite strKeyPath & "001\", "Cleaning up" , "REG_SZ"
ws.RegWrite strKeyPath & "001\1", strOEM & "001_Start.vbs", "REG_SZ"
If fs.FileExists(strOEM & "Streets.7z") Then
 ws.RegWrite strKeyPath & "005\", "Microsoft Streets and Trips 2005", "REG_SZ"
 ws.RegWrite strKeyPath & "005\1", strOEM & "005_Streets.vbs", "REG_SZ"
End If
If fs.FileExists(strOEM & "Microsoft Office 2003 SP1\PRO11.MSI") Then
 ws.RegWrite strKeyPath & "010\", "Microsoft Office 2003 SP1", "REG_SZ"
 ws.RegWrite strKeyPath & "010\1", strOEM & "010_Office.vbs", "REG_SZ"
End If
ws.RegWrite strKeyPath & "015\", "Administrative Tools and Advanced Applications", "REG_SZ"
ws.RegWrite strKeyPath & "015\1", strOEM & "015_Admin.vbs", "REG_SZ"
ws.RegWrite strKeyPath & "020\", "Accessories and Multimedia Applications", "REG_SZ"
ws.RegWrite strKeyPath & "020\1", strOEM & "020_Accessories.vbs", "REG_SZ"
ws.RegWrite strKeyPath & "025\", "Utilities and CD-R Tools", "REG_SZ"
ws.RegWrite strKeyPath & "025\1", strOEM & "025_Utilities.vbs", "REG_SZ"
ws.RegWrite strKeyPath & "030\", "Security and Malware Applications", "REG_SZ"
ws.RegWrite strKeyPath & "030\1", strOEM & "030_Security.vbs", "REG_SZ"
ws.RegWrite strKeyPath & "050\", "Compress Select Directories", "REG_SZ"
ws.RegWrite strKeyPath & "050\1", strOEM & "050_Compress.vbs", "REG_SZ"
'ws.RegWrite strKeyPath & "055\", "Initial Hard Disk Defragmentation", "REG_SZ"
'ws.RegWrite strKeyPath & "055\1", strOEM & "055_1stDefrag.vbs", "REG_SZ"
ws.RegWrite strKeyPath & "060\", "Configure the Page File", "REG_SZ"
ws.RegWrite strKeyPath & "060\1", strOEM & "060_PageFile.vbs", "REG_SZ"
ws.RegWrite strKeyPath & "065\", "Defragment the Registry", "REG_SZ"
ws.RegWrite strKeyPath & "065\1", strOEM & "065_RegDefrag.vbs", "REG_SZ"
End Sub

'**********************************************************************
'** Run Tasks                                                        **
'**********************************************************************
If fs.FileExists(sysdrv & "\Drivers.cmd") Then fs.DeleteFile(sysdrv & "\Drivers.cmd"), True
ws.Run "REGEDIT /S cmdlines.reg",0,True
SetROE

EDIT: Well for some reason the comment lines got garbled. Also if you copy/paste this into notepad on a 1024x768 screen it should be much more readable.

Link to comment
Share on other sites

Thanks you for your reply, but all your example are pointing to another external file... is it possible to do something like this:

ws.RegWrite strKeyPath & "TITLE", "Installing Software", "REG_SZ"
ws.RegWrite strKeyPath & "001\", "MS Office Pro 2003", "REG_SZ"
ws.RegWrite strKeyPath & "001\1", "\\Source\setup.exe TRANSFORMS=Unattended.mst /qb-", "REG_SZ"

Link to comment
Share on other sites

I Believe This Set The Source , Here Is I Hope A Correct Break Down

It say A Drive With This File WIN51 = strOEM

Then He Add Another Varible OEM\ To it For The Path

If fs.FileExists(Drive & ":\WIN51") Then strCD = Drive & ":\"

Next

strOEM =strCD & "OEM\"

ws.RegWrite strKeyPath & "065\1", strOEM & "065_RegDefrag.vbs", "REG_SZ"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...