Computer Hope

Microsoft => Microsoft DOS => Topic started by: vivek.m on August 11, 2008, 06:12:54 AM

Title: regsitering all dll files inside a folder
Post by: vivek.m on August 11, 2008, 06:12:54 AM
There are 100's of dll in a folder and I want to run regsvr32 on all those dlls. How can I do that?
Please help.

Thanks.
Title: Re: regsitering all dll files inside a folder
Post by: vivek.m on August 11, 2008, 06:59:18 AM
after searching on net for a while about vbscript, I am able to write the following the script which solves my problem:

Code: [Select]
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("D:\MyFolder") 'point to your directory
Set fc = f.Files
set shellObj = CreateObject("WScript.Shell")
Dim cnt
cnt = 0

For Each objFile In fc
If fso.GetExtensionName(objFile) = "dll" then
shellObj.Run "regsvr32 /s " & objFile
cnt = cnt+1
End If
Next
Wscript.echo("Total dlls found and registered = " & cnt)


curious if such things can be done through batch files also. I am new to both vbscript and batch files.

Thanks.
Title: Re: regsitering all dll files inside a folder
Post by: Sidewinder on August 11, 2008, 09:25:16 AM
This would be the batch code equivalent:

Code: [Select]
@echo off
set cnt=0
for %%v in (D:\MyFolder\*.dll) do (
regsvr32 /s "%%v"
call set cnt=%%cnt%%+1
)
echo Total dlls found and registered = %cnt%

Both batch code and VBScript have their uses. Generally I think you'll find batch code underpowered and a bit cryptic (six months from now will you remember what %%v represents?).

VBScript can be a bit wordy and much work takes place in functions with positional parameters (six months from now will you remember the parameter order for the instr function?)

VBScript combined with HTML code can create front-end GUIs for even the most boring of scripts. Batch code is strictly command line.

Both are good tools to know. If you find yourself doing repetitive computer chores, scripting is a fine way to automate them.

 8)
Title: Re: regsitering all dll files inside a folder
Post by: vivek.m on August 11, 2008, 10:09:54 PM
Thanks for the reply. It does the work but the only difference is in the output of count. It gives output as:
Total dlls register = 0+1+1+1+1+0+.... and says you do the bloody math yourself  :D

Anyway, thanks.

Vivek.

PS: I may not remember what %%v stands for even after 1 month but I can always bookmark this page and will visit it whenver in doubt.
Title: Re: regsitering all dll files inside a folder
Post by: Sidewinder on August 11, 2008, 10:18:26 PM
If you're gonna do arithmetic you have to tell the interpreter:

Code: [Select]
@echo off
set cnt=0
for %%v in (D:\MyFolder\*.dll) do (
regsvr32 /s "%%v"
call set /a cnt=%%cnt%%+1
)
echo Total dlls found and registered = %cnt%

Of course the DIY method works too.  ;D