VB脚本系统在某些计算机/用户上找不到指定的文件

时间:2020-01-14 15:13:26

标签: vbscript

美好的一天!我有一个打开访问应用程序的脚本。

此脚本仅对多个用户有效。该用户遇到此错误

“错误80070002:系统找不到指定的文件”。

我非常确定我的脚本没有问题,因为只有一个人遇到此问题。

是否存在引起此问题的计算机设置或更新? 除“打开文件”部分外,其他所有功能均正常。

这仅适用于某些计算机/用户。大多数计算机/用户都可以毫无问题地执行此操作。

提前谢谢!

这是脚本

'*******************************************************************************
'Find user name
'*******************************************************************************    
Set WshNetwork = CreateObject("WScript.Network")
userName = WshNetwork.UserName
Set WshNetwork = Nothing

'******************************************************************************* 
'Find version of master file
'******************************************************************************* 
Set folder = objfso.GetFolder(folderPath)  
For Each file In folder.Files
    If InStr(file.Name, "AMSDshbd_M") = 1 Then
        masterVersion = Mid(file.Name, 11, (InStrRev(file.Name, ".") - 11))
        Exit For
    End If
Next

'*******************************************************************************
'Find version of user file, if it exists
'*******************************************************************************    
isUserFile = 0
For each file In folder.Files    
    If InStr(file.Name, "AMSDshbd_" & userName) = 1 Then
        isUserFile = 1
        userVersion = Mid(file.Name, (Len(userName) + 10), (InStrRev(file.Name, ".") - (Len(userName) + 10)))
        Exit For
    End If
Next

'*******************************************************************************
'Copy the file if no user file exists or if the user version is not current
'*******************************************************************************
sourceFile = folderPath & "AMSDshbd_M" & masterVersion & ".accde"
targetFile = folderPath & "AMSDshbd_" & userName & "_M" & masterVersion & ".accde"

isCopyNeeded = 1
if isUserFile = 1 then
    if userVersion = masterVersion then
        isCopyNeeded = 0
    end if
end if

if isCopyNeeded = 1 then
    objFSO.CopyFile sourceFile, targetFile, True
end if

'*******************************************************************************
'Open the file
'*******************************************************************************
sComTxt = Chr(34) & microsoftAccessFile & Chr(34) & " " & Chr(34) & targetFile & Chr(34) 
'objShell.Run sComTxt
objShell.Run sComTxt,,true

Set objFSO = Nothing
Set objShell = Nothing

1 个答案:

答案 0 :(得分:0)

我知道发生了什么事。变量“ microsoftAccessFile”是MS Access EXE的路径,某些用户具有此Access EXE的其他路径,这就是为什么它不适用于他们的原因。我确定了他们的Access EXE的存储路径,并更改了他们的脚本,它现在可以正常工作。感谢您指出变量