我正在尝试将一些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"
答案 0 :(得分: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