Running regsvr32 from a batch file isn't working

3.2k views Asked by At

I have created a batch file that goes to a series of application directories and registers all dll and ocx files within them. If I open an elevated command prompt and change to a specific directory and type in the regsvr command manually it works fine. The batch file looks like it is trying to register each file, but they do not get registered. I have tried right clicking on it and tell it to run as administrator (the command window does not show "Administrator" in the title bar), but it doesn't register. If I open an elevated command window and try to run the batch file from there, it doesn't work either.

I have also tried putting the script file in c:\Windows\System32 and C:\Windows\SysWOW64 and nothing has worked.

I also read that the file needed to be ANSI instead of Unicode, but that didn't help either.

Is there some sort of command I can put on the line with regsvr that will force each one to be elevated? I don't want to make the user type all the commands in manually.

Here is my batch file:

chdir c:\program files (x86)\pfps
for /r %%i in (*.dll) do regsvr32 /s %%i
chdir DataManager
for /r %%i in (*.dll) do regsvr32 /s %%i
chdir ..\falcon
for /r %%i in (*.dll) do regsvr32 /s %%i
for /r %%i in (*.ocx) do regsvr32 /s %%i
chdir FVOverlays
for /r %%i in (*.dll) do regsvr32 /s %%i
chdir ..\..\FVImageryService
for /r %%i in (*.dll) do regsvr32 /s %%i
chdir ..\GarminGPSFeed
for /r %%i in (*.dll) do regsvr32 /s %%i
chdir ..\MapDataServer
for /r %%i in (*.dll) do regsvr32 /s %%i
chdir ..\SkyViewNG
for /r %%i in (*.dll) do regsvr32 /s %%i
for /r %%i in (*.ocx) do regsvr32 /s %%i
chdir ..\System
for /r %%i in (*.dll) do regsvr32 /s %%i
for /r %%i in (*.ocx) do regsvr32 /s %%i
1

There are 1 answers

1
Andre Kampling On BEST ANSWER

The problem are the spaces in your path: c:\program files (x86)\pfps. The regsvr32 command will separate on spaces and read that as multiple arguments.

To allow spaces you have to use quotes:

for /r %%i in (*.dll) do regsvr32 /s "%%i"

leading to e.g.:

regsvr32 "c:\program files (x86)\pfps\blahblah.dll"

where the path to the file is handled as single argument for regsvr32.


Why does: chdir c:\program files (x86)\pfps work with spaces and without quotes?

It's explained here on ss64 about cd/chdir:

If Command Extensions are enabled [default] the CD command is enhanced as follows:

[...]

CD does not treat spaces as delimiters, so it is possible to CD into a subfolder name that contains a space without surrounding the name with quotes.

For example:
cd \My folder

is the same as:
cd "\My folder"

[...]

CHDIR is a synonym for CD

But I recommend always using quotes for paths.