运行 来自批处理文件的 regsvr32 不工作
Running regsvr32 from a batch file isn't working
我创建了一个批处理文件,该文件转到一系列应用程序目录并在其中注册所有 dll 和 ocx 文件。如果我打开提升的命令提示符并切换到特定目录并手动输入 regsvr 命令,它就可以正常工作。批处理文件看起来像是在尝试注册每个文件,但它们没有注册。我试过右键单击它并以管理员身份告诉它 运行(命令 window 没有在标题栏中显示 "Administrator"),但它没有注册。如果我打开提升的命令 window 并尝试从那里 运行 批处理文件,它也不起作用。
我也试过将脚本文件放在 c:\Windows\System32 和 C:\Windows\SysWOW64 中,但没有任何效果。
我还了解到该文件需要是 ANSI 而不是 Unicode,但这也无济于事。
是否有某种命令可以与 regsvr 联机,强制提升每个命令?我不想让用户手动输入所有命令。
这是我的批处理文件:
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
问题是路径中的空格:c:\program files (x86)\pfps
。 regsvr32
命令将以空格分隔并将其作为多个参数读取。
要允许空格,您必须使用引号:
for /r %%i in (*.dll) do regsvr32 /s "%%i"
导致例如:
regsvr32 "c:\program files (x86)\pfps\blahblah.dll"
其中文件路径作为 regsvr32
的单个参数处理。
为什么:chdir c:\program files (x86)\pfps
使用空格而不使用引号?
已说明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
但我建议始终对路径使用引号。
我创建了一个批处理文件,该文件转到一系列应用程序目录并在其中注册所有 dll 和 ocx 文件。如果我打开提升的命令提示符并切换到特定目录并手动输入 regsvr 命令,它就可以正常工作。批处理文件看起来像是在尝试注册每个文件,但它们没有注册。我试过右键单击它并以管理员身份告诉它 运行(命令 window 没有在标题栏中显示 "Administrator"),但它没有注册。如果我打开提升的命令 window 并尝试从那里 运行 批处理文件,它也不起作用。
我也试过将脚本文件放在 c:\Windows\System32 和 C:\Windows\SysWOW64 中,但没有任何效果。
我还了解到该文件需要是 ANSI 而不是 Unicode,但这也无济于事。
是否有某种命令可以与 regsvr 联机,强制提升每个命令?我不想让用户手动输入所有命令。
这是我的批处理文件:
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
问题是路径中的空格:c:\program files (x86)\pfps
。 regsvr32
命令将以空格分隔并将其作为多个参数读取。
要允许空格,您必须使用引号:
for /r %%i in (*.dll) do regsvr32 /s "%%i"
导致例如:
regsvr32 "c:\program files (x86)\pfps\blahblah.dll"
其中文件路径作为 regsvr32
的单个参数处理。
为什么:chdir c:\program files (x86)\pfps
使用空格而不使用引号?
已说明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 folderis the same as:
cd "\My folder"[...]
CHDIR is a synonym for CD
但我建议始终对路径使用引号。