简体   繁体   English

VBScript 在启动 EXE 以安装程序之前等待文件被提取的命令

[英]VBScript command to wait for files to be extracted before launching EXE to install program

I'm looking at having a script that decompresses a file (PDMsetup.zip) and then launch the executable that it extracts.我正在寻找一个解压缩文件 (PDMsetup.zip) 的脚本,然后启动它提取的可执行文件。

ZipFile="PDMsetup.zip"
ExtractTo=".\"
 
Set fso = CreateObject("Scripting.FileSystemObject")
sourceFile = fso.GetAbsolutePathName(ZipFile)
destFolder = fso.GetAbsolutePathName(ExtractTo)
 
Set objShell = CreateObject("Shell.Application")
Set FilesInZip=objShell.NameSpace(sourceFile).Items()
objShell.NameSpace(destFolder).copyHere FilesInZip, 16
 
Set fso = Nothing
Set objShell = Nothing
Set FilesInZip = Nothing

wscript.sleep 480000

Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile) 
strPath = strFolder &  "\Startwinstall.exe"
objShell.Run strPath

I want to get rid of;我想摆脱;

wscript.sleep 480000

and replace it with a command that tells the script wait until the extraction is done before launching startwinstall.exe并将其替换为告诉脚本等待提取完成后再启动 startwinstall.exe 的命令

I've kept adjusting the wait time to make up for differences in PC performance with the extraction, but a command to just 'wait' until it's done would be preferential.我一直在调整等待时间,以弥补提取过程中 PC 性能的差异,但最好是“等待”直到提取完成的命令。

Delete any previous copy of the installer exe in the target folder and then wait for that file to be created.删除目标文件夹中安装程序 exe 的任何先前副本,然后等待创建该文件。 Create your objects once at the top of the script.在脚本顶部创建一次对象。 And there's no need to set the objects to Nothing.并且无需将对象设置为 Nothing。 That will happen automatically when the script ends.这将在脚本结束时自动发生。 The edited script is below:编辑后的脚本如下:

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWSH = CreateObject("Wscript.Shell")
Set oApp = CreateObject("Shell.Application")

MyFolder = oFSO.GetParentFolderName(WScript.ScriptFullName) 
ExtractTo = ".\"
ZipFile = "PDMsetup.zip"
StartApp = ExtractTo & "Startwinstall.exe"
On Error Resume Next
oFSO.DeleteFile StartApp
On Error Goto 0

sourceFile = oFSO.GetAbsolutePathName(ZipFile)
destFolder = oFSO.GetAbsolutePathName(ExtractTo)

Set FilesInZip = oApp.NameSpace(sourceFile).Items()
oApp.NameSpace(destFolder).copyHere FilesInZip, 16

Do Until oFSO.FileExists(StartApp)
  WScript.Sleep 1000
Loop

oWSH.Run StartApp

Note: I assigned a MyFolder variable, but it's not currently being used.注意:我分配了一个MyFolder变量,但它当前未被使用。 ExtractTo = ".\" could be changed to ExtractTo = MyFolder . ExtractTo = ".\"可以更改为ExtractTo = MyFolder You could also eliminate the GetAbsolutePathName lines if you are using MyFolder with the ZipFile name.如果您使用带有 ZipFile 名称的MyFolder ,您也可以删除GetAbsolutePathName行。 There are always many ways to do the same thing.总是有很多方法可以做同样的事情。

Note: I think the above can be done with a much briefer (probably two line) PowerShell script.注意:我认为上面的内容可以用一个更简短的(可能是两行)PowerShell 脚本来完成。 Let me know if you're interested in that solution.如果您对该解决方案感兴趣,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM