找不到VB脚本运行时错误路径 - 800A004C - AppData

时间:2014-11-12 10:38:16

标签: vbscript

现在固定:

这是我的第一个VB脚本,它可以在我的电脑上正常工作但不能在其他版本的Windows上工作,等等。它无法找到目标路径(全部在c:/ users / USERNAME / appdata ... USERNAME会有所不同)。任何帮助将不胜感激!

' InstallAddin.vbs
    ' Get the objects used by this script.
    Dim oXL, oAddin, fso, wsh, srcPath, destPath, addin, destPath2, destPath3, addin2, addin3, Wshshell
    addin = "\addin.xlam"
    addin2 = "\Launcher File.exe"
   addin3 = "\Tester File.exe"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set wsh = WScript.CreateObject("WScript.Shell")
    ' Get the current folder.
    srcpath = fso.GetFolder(".")
    destPath = wsh.Environment("PROCESS")("HOMEDRIVE") & _
      wsh.Environment("PROCESS")("HOMEPATH") & _
      "\AppData\Roaming\Microsoft\Excel\XLSTART"
    destPath2 = wsh.Environment("PROCESS")("HOMEDRIVE") & _
      wsh.Environment("PROCESS")("HOMEPATH") & _
      "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
 destPath3 = wsh.Environment("PROCESS")("HOMEDRIVE") & _
      wsh.Environment("PROCESS")("HOMEPATH") & _
      "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
    ' Copy the file to the template folder.
    fso.CopyFile srcpath & addin, destpath & addin
    fso.CopyFile srcpath & addin2, destpath2 & addin2
    fso.CopyFile srcpath & addin3, destpath3 & addin3

Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run """Launcher File.exe""", 0, False
wshshell.run """Tester File.exe""", 0, False
set wshshell = nothing

x=msgbox("Installation complete!" ,0, "Installation complete")

我将其修复如下:

usrName = objWShell.expandEnvironmentStrings("%USERNAME%")
destPath = "C:\Users\" & usrName & "\AppData\Roaming\Microsoft\Excel\XLSTART"
destPath2 = "C:\Users\" & usrName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
destPath3 = "C:\Users\" & usrName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"

0 个答案:

没有答案