0

我正在尝试将一些 DLL 从APPDATA系统根目录复制并注册它们,但我不断收到“找不到路径错误”。

On Error Resume Next
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "%AppData%\something\something\something\x64\*.dll" , "C:\Windows\SysWOW64\" , OverwriteExisting
objFSO.CopyFile "%AppData%\something\something\something\x86\*.dll" , "C:\Windows\System32\" , OverwriteExisting

Dim objShell
Set WshShell = WScript.CreateObject( "WScript.Shell" ) 
WshShell.run "c:\windows\SysWOW64\regsvr32.exe /s c:\windows\SysWOW64\something.dll" 
WshShell.run "c:\windows\SysWOW64\regsvr32.exe /s c:\windows\SysWOW64\something.dll" 
WshShell.run "c:\windows\SysWOW64\regsvr32.exe /s c:\windows\SysWOW64\something.dll" 
wscript.sleep 1000
WshShell.run "c:\windows\System32\regsvr32.exe /s c:\windows\SysWOW64\something.dll" 
WshShell.run "c:\windows\System32\regsvr32.exe /s c:\windows\SysWOW64\something.dll" 
WshShell.run "c:\windows\System32\regsvr32.exe /s c:\windows\SysWOW64\something.dll" 
4

1 回答 1

1

这些FileSystemObject方法不扩展环境变量。改变这个:

objFSO.CopyFile "%AppData%\something\something\something\x64\*.dll" , "C:\Windows\SysWOW64\" , OverwriteExisting
objFSO.CopyFile "%AppData%\something\something\something\x86\*.dll" , "C:\Windows\System32\" , OverwriteExisting

进入这个:

Set sh = CreateObject("WScript.Shell")
appdata = sh.ExpandEnvironmentStrings("%APPDATA%")
src = objFSO.BuildPath(appdata, "something\something\something\x64\*.dll")
objFSO.CopyFile src, "C:\Windows\SysWOW64\", OverwriteExisting
src = objFSO.BuildPath(appdata, "something\something\something\x86\*.dll")
objFSO.CopyFile src, "C:\Windows\system32\", OverwriteExisting

但是,您的逻辑在这里是错误的。尽管有(误导性的)名称,但该system32文件夹包含 64 位文件,并且该SysWOW64文件夹包含 64 位系统上的 32 位文件,因此您需要切换目标文件夹:

Set sh = CreateObject("WScript.Shell")
appdata = sh.ExpandEnvironmentStrings("%APPDATA%")
src = objFSO.BuildPath(appdata, "something\something\something\x64\*.dll")
objFSO.CopyFile src, "C:\Windows\system32\", OverwriteExisting
src = objFSO.BuildPath(appdata, "something\something\something\x86\*.dll")
objFSO.CopyFile src, "C:\Windows\SysWOW64\", OverwriteExisting

如果您也有 32 位系统,则需要检测操作系统架构并根据该测试的结果复制文件:

Set sh = CreateObject("WScript.Shell")
appdata = sh.ExpandEnvironmentStrings("%APPDATA%")
If sh.Environment("PROCESS")("PROCESSOR_ARCHITECTURE") = "AMD64" Then
  src = objFSO.BuildPath(appdata, "something\something\something\x64\*.dll")
  objFSO.CopyFile src, "C:\Windows\system32\", OverwriteExisting
  src = objFSO.BuildPath(appdata, "something\something\something\x86\*.dll")
  objFSO.CopyFile src, "C:\Windows\SysWOW64\", OverwriteExisting
Else
  src = objFSO.BuildPath(appdata, "something\something\something\x86\*.dll")
  objFSO.CopyFile src, "C:\Windows\system32\", OverwriteExisting
End If
于 2013-09-16T08:47:16.010 回答