-1

I am under the context of a script executed within an installation package MSI created with InstallShield. I execute the below script:

Set wshShell = CreateObject( "WScript.Shell" )
User = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
MsgBox "User: " & User

' The parameters are received through MSI parameters
' msiexec /I MyMSI_x64.msi configFileSrc="Z:\MyFolder\FileToCopy.txt" configFolderDst="c:\temp\"

' Testing parameters
Dim configFileSrc, configFolderDst
configFileSrc = "Z:\MyFolder\FileToCopy.txt"
configFolderDst = "c:\temp\"

' **********************************************************************
' Copy file to destination folder
' **********************************************************************
if(configFileSrc <> "") Then
    call copyFile(configFileSrc, configFolderDst)
End if

' **********************************************************************
' Function to copy file
' **********************************************************************
Sub CopyFile(SourceFile, DestinationFile)

    Set fso = CreateObject("Scripting.FileSystemObject")
    
    If not fso.FileExists(SourceFile) Then
        MsgBox "The file " & SourceFile & " is not found and will therefore not be copied to destination folder.", vbExclamation, "Parameter file not found" 
        Exit Sub
    End If 
 ...

The FileExists always return false when executed from a mounted drive. When the script is executed locally (replacing configFileSrc which is actually provided as a parameter), the the script works fine. I am pretty sure that InstallShield use the Admin local account of the machine which have potentially no permission on the mounted drive but I don't know how to check. I have tried to display the current user strUserName but the box is empty. Any idea?

Salim
  • 495
  • 3
  • 20
  • 1
    Your problem analysis is probably correct. The reason why you are not seeing the username is because you are setting the variable `User` and not `strUserName`. Using `Option Explicit` would have made this apparent. – Geert Bellekens Nov 17 '20 at 06:44
  • 1
    Does this answer your question? [Mapping a network drive and checking for its existence in VBScript](https://stackoverflow.com/questions/7336685/mapping-a-network-drive-and-checking-for-its-existence-in-vbscript) – user692942 Nov 17 '20 at 08:46
  • Hello Lankymart, thanks. No it does not address my question. In my situation the network share is already mounted and accessing it cause the issue despite a correct path. – Salim Nov 18 '20 at 07:13
  • HI Geert, thanks, dummy mistake. Actually, it invalidated my hypothese. The wshShell.ExpandEnvironmentStrings show the same user than the logged in user which has the relevant privileges to access the network share. – Salim Nov 19 '20 at 21:34

1 Answers1

0

Mapped drives are per user token. Admins have two tokens. So running as admin means it does not have access to mapped drives as a normal user.

Use UNC paths. \\server\sharename\folder\file.ext.

  • In fact, I am receiving the paths through MSI parameters (I updated the main post). I have no control over what is received :-S – Salim Nov 19 '20 at 21:38