【问题标题】:VBScript file copy FileExists return false mounted drive driveVBScript 文件复制 FileExists 返回错误安装的驱动器驱动器
【发布时间】: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


【解决方案1】:

映射的驱动器是每个用户令牌。管理员有两个令牌。因此,以管理员身份运行意味着它无法以普通用户身份访问映射的驱动器。

使用 UNC 路径。 \\server\sharename\folder\file.ext.

【讨论】:

  • 其实我是通过MSI参数接收路径的(我更新了主帖)。我无法控制收到的内容:-S
猜你喜欢
  • 2019-07-30
  • 1970-01-01
  • 2015-04-10
  • 1970-01-01
  • 2016-12-06
  • 1970-01-01
  • 2017-10-17
  • 2012-01-02
  • 2018-04-16
相关资源
最近更新 更多