0

NOW FIXED:

This is my first VB script and it works fine on my PC but not on others with the same version of Windows, etc. It fails to find the destination paths (all in c:/users/USERNAME/appdata... where USERNAME will vary). Any help would be greatly appreciated!

' 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")

I fixed it as follows:

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"
Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48
  • Have you checked the strings you're creating (`destPathX`) against the actual paths on the systems where it fails? Is there an error message, or does it fail silently? – Justin Ryan Nov 12 '14 at 10:52
  • The locations exist. They have the same set-up as on my PC. Could I set the destPath using %APPDATA% + \Roaming\Microsoft\Excel\XLSTART in some way? This is my first vbs script. – user3842077 Nov 12 '14 at 10:55
  • For example, something like: destPath = %APPDATA% "\Roaming\Microsoft\Excel\XLSTART" – user3842077 Nov 12 '14 at 10:57
  • [Access the 'Application Data' folder when using Folder Redirection](http://stackoverflow.com/questions/18781992/access-the-application-data-folder-when-using-folder-redirection) – Justin Ryan Nov 12 '14 at 11:06
  • Which line exactly is raising the error? – Ansgar Wiechers Nov 12 '14 at 11:25
  • I've fixed it with the following: `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"` Thanks for your help! – user3842077 Nov 12 '14 at 12:06
  • The system drive is not always mounted at C:\, so you may want to take that into consideration. – Justin Ryan Nov 12 '14 at 13:32
  • Please do not change questions into answers. If you found a solution for your problem yourself: post it as an answer of your own. – Ansgar Wiechers Nov 12 '14 at 14:59
  • @JustinRyan - thanks, but in this case all users will have the system drive mounted at c:\. – user3842077 Nov 12 '14 at 21:04

0 Answers0