VBScript CopyHere 函數停止

VBScript CopyHere 函數停止

我有一個腳本來提取不起作用的 .zip 資料夾的內容(程式碼位於帖子底部,僅供參考)。如果目標資料夾不存在,我將建立一個目標資料夾,然後使用 CopyHere 將內容移至目標資料夾。該腳本運行到創建資料夾的位置,然後在 CopyHere 函數期間似乎停止了(沒有從 zip 檔案中移動任何內容)。請注意,基於 Windows 的腳本宿主進程此時正在無限期地運行,我必須手動終止它。

這似乎是我的機器特有的,因為該腳本在我擁有的虛擬機器以及其他同事的機器(所有 x64 Windows 10 Professional)中運行。

我在嘗試提取到的位置擁有完全權限,因此我不認為這是權限問題。我能想到的機器之間的唯一區別是我安裝了 Ubuntu-in-Windows 功能來玩。也許這引起了問題?

我還可以採取哪些其他步驟來找出進程停滯的原因?

謝謝!

-肖恩

Function unzip(sZip)

    Dim oFSO, oShell
    dim zip, d

    Set oFSO = CreateObject("Scripting.FileSystemObject")

    sZipFile = oFSO.GetAbsolutePathName(sZip)
    sDestPath = oFSO.GetAbsolutePathName(Left(sZip, Len(sZip) - 4))

    If Not oFSO.FolderExists(sDestPath) Then
        oFSO.CreateFolder(sDestPath)
    End If

    Set oShell = CreateObject("Shell.Application")
    Set zip = oShell.NameSpace(sZipFile)
    set d = oShell.NameSpace(sDestPath)

    MsgBox "Got here"

    d.CopyHere zip.items, 256

    Set oFSO = Nothing
    Set oShell = Nothing

End Function

Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")

sPath = oFSO.GetParentFolderName(WScript.ScriptFullName)

sInstPath = sPath & "\dist\installers\"
aInsts = Array("4-AgilentIOLib.zip", "5-NationalInstrumentsLib.zip")

For i = 0 To UBound(aInsts)

    MsgBox "Unzipping " & sInstPath & aInsts(i)

    unzip(sInstPath & aInsts(i))

    MsgBox "Done"
Next

答案1

CopyHere正在使用該256選項,即Display a progress dialog box but do not show the file names.
來源

您是否可能收到了未看到的提示?您是否使用wscript.exe或執行腳本cscript.exe?您是否以交互方式運行它?

您可以嘗試使用 option4來不顯示進度對話框嗎?您也可以嘗試16+256新增Respond with "Yes to All" for any dialog box that is displayed.

我還運行了該腳本,它工作正常,但是當我重新運行它時,系統提示我覆蓋現有文件。

相關內容