【发布时间】:2021-02-28 08:46:09
【问题描述】:
我在使用 InstallShield 创建的安装包 MSI 中执行的脚本的上下文中。我执行以下脚本:
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
...
从已安装的驱动器执行时,FileExists 总是返回 false。当脚本在本地执行时(替换实际作为参数提供的 configFileSrc),脚本工作正常。 我很确定 InstallShield 使用机器的管理员本地帐户,该帐户可能对已安装的驱动器没有权限,但我不知道如何检查。我试图显示当前用户 strUserName 但该框为空。 有什么想法吗?
【问题讨论】:
-
您的问题分析可能是正确的。您看不到用户名的原因是因为您正在设置变量
User而不是strUserName。使用Option Explicit会让这一点显而易见。 -
你好 Lankymart,谢谢。不,它没有解决我的问题。在我的情况下,网络共享已经挂载,尽管路径正确,但访问它会导致问题。
-
嗨,Geert,谢谢,愚蠢的错误。实际上,它使我的假设无效。 wshShell.ExpandEnvironmentStrings 显示与登录用户相同的用户,该用户具有访问网络共享的相关权限。
标签: vbscript installshield file-copying mounted-volumes