我有一个HTA,它将一组文件复制到USB记忆棒,作为创建USB实用程序磁盘的一部分。它工作正常,但问题是HTA在复制过程运行时变得没有响应。
Const FOF_CREATEPROGRESSDLG = &H0&
sub CopyFiles(driveletter) ' Copys Files to the new USB Disk showing progress bar
if radio(0).checked Then
Set objFilesys = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
driveletter = ((driveletter) & "\")
Set objFolder = objshell.NameSpace(driveletter)
pathstring = objFilesys.GetAbsolutePathName("c:")
objFolder.CopyHere pathstring & "\" & "*.*", FOF_CREATEPROGRESSDLG
exit sub
elseif radio(1).checked Then
Set objFilesys = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("shell.application")
pathstring = userselections.txtFile.value
if objFilesys.fileExists(pathstring & "\" & "kernel.sys") then
driveletter = ((driveletter) & "\")
Set objFolder = objshell.NameSpace(driveletter)
objFolder.CopyHere pathstring & "\" & "*.*", FOF_CREATEPROGRESSDLG
Else
msgbox "Error! The Specified path does not contain valid Install Files", vbcritical
end if
end if
end sub
答案 0 :(得分:0)
您的问题似乎是shell.application的CopyHere方法是异步的 - 它在您复制时不会暂停执行。
“objFolder.CopyHere”启动,之后立即调用“Exit Sub”,导致代码在CopyHere完成之前失去控制权。
有一些making CopyHere sort of synchronous
的例子Here's one适用于压缩,但可以根据您的需要进行调整。