VB icon

Bulk Un/Register DLLs & OCXs

Email
Submitted on: 1/20/2015 1:31:00 AM
By: Steven Hoyt (from psc cd)  
Level: Advanced
User Rating: By 2 Users
Compatibility: VB Script
Views: 535
 
     generate two batch files (one to register, one to unregister) that manage dlls/ocxs in a dev branch. the batch files execute and give the line number of a failed registry event. this is a two minute script that saves me time in trying to see what new dlls/ocxs were added/deleted...hope it is useful to all.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Bulk Un/Register DLLs & OCXs
' Description:generate two batch files (one to register, one to unregister) that manage dlls/ocxs in a dev branch.
the batch files execute and give the line number of a failed registry event. this is a two minute script that saves me time in trying to see what new dlls/ocxs were added/deleted...hope it is useful to all.
' By: Steven Hoyt (from psc cd)
'
' Assumes:this is a .vbs script...which you can easily convert to a vb exe...
'**************************************

Private mfso
Private mfd
Private mRegStream
Private mURegStream
Private mcstrHeader
Private mcstrErrText
Private mcstrFooter
Private mlngPtr
mcstrHeader = "@echo off" & vbCrLf & "cls" & vbCrLf & "echo [REG]..." & vbCrLf & vbCrLf & "set has_err=0" & vbCrLf & "set errors=0" & vbCrLf & "set e_text=0" & vbCrLf & vbCrLf
mcstrErrText = "if errorlevel=1 set has_err=1" & vbCrLf & "if errorlevel=1 set errors=[SEQ]" & vbCrLf & "if errorlevel=0 set e_text=%errors%" & vbCrLf & vbCrLf
mcstrFooter = "set e_text=Error, Line %e_text%" & vbCrLf & vbCrLf & "if %has_err%==0 set e_text=No Errors" & vbCrLf & vbCrLf & "cls" & vbCrLf & "echo [REG]!" & vbCrLf & "echo %e_text%" & vbCrLf & "pause"
mlngPtr = 0
mlnghFileReg = 1
mlnghFileUReg = 2
If MsgBox("Create Un/Register Batch Files?", vbYesNo, "Dll Auto-Register") = vbYes Then
Set mfso = CreateObject("Scripting.FileSystemObject")
Set mfd = mfso.GetFolder("C:\")
Set mRegStream = mfd.CreateTextFile("Register.bat", True, False)
Set mURegStream = mfd.CreateTextFile("UnRegister.bat", True, False)
mRegStream.Write Replace(mcstrHeader, "[REG]", "Registering")
mURegStream.Write Replace(mcstrHeader, "[REG]", "Un-Registering")
SetDllRegText "C:\Your Project\Dev\"
mRegStream.Write Replace(mcstrFooter, "[REG]", "Registered")
mURegStream.Write Replace(mcstrFooter, "[REG]", "Un-Registered")
mRegStream.Close
mURegStream.Close
MsgBox "Done.", vbOKOnly, "Dll Auto-Register"
End If
Private Sub SetDllRegText(ByVal strSearchPath)
Dim dr
Dim sfld
Dim f
Dim strPrintData
If Right(strSearchPath, 1) <> "\" Then strSearchPath = strSearchPath & "\"
Set dr = mfso.GetFolder(strSearchPath)
For Each f In dr.Files
If Right(LCase(f.Name), 4) = ".dll" Or Right(LCase(f.Name), 4) = ".ocx" Then
mlngPtr = mlngPtr + 1
strPrintData = Replace(mcstrErrText, "[SEQ]", mlngPtr)
mRegStream.Write "regsvr32.exe " & """" & strSearchPath & f.Name & """ /s" & vbCrLf & strPrintData
mURegStream.Write "regsvr32.exe /u " & """" & strSearchPath & f.Name & """ /s" & vbCrLf & strPrintData
End If
Next
If dr.SubFolders.Count Then
For Each sfld In dr.SubFolders
If Err.Number Then Exit For
SetDllRegText sfld.Path
Next
End If
End Sub


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.