我正在尝试创建一个vbscript,我从Java调用解压缩文件,然后使用解压缩的文件 . 我需要在提升模式下运行解压缩 . 当我这样做时,vbscript不会等待文件在返回之前被解压缩,并且下一个命令在文件存在之前运行 .

这就是我现在正在做的事情:

Java的:

public void unzipElevated( String fileName, String Target )
{
   String  unzipFile = "cscript " 
          + tmpDir.getAbsoluteFile() + File.separator + "RunElevated.vbs "
          + "UnzipFiles.vbs "    
          + fileName + " "
          + Target   + File.separator;
   ArrayList<String> lines = new ArrayList<String>();

   Process p;
   try
   {
      p = Runtime.getRuntime().exec( unzipFile );
      p.waitFor();

      InputStream s = p.getInputStream();
      Scanner     i = new Scanner( s );
      while (i.hasNextLine())
         lines.add( i.nextLine() );
   }
   catch (Exception e)
   {
   }
}

vbscript :( RunElevated.vbs)

' Run the script in elevated mode
'
' This will be needed to install programs into Program Files
prgName      = Wscript.Arguments.Item(0)
prgArgs      = ""
If Wscript.Arguments.Count > 1 Then
   For i = 1 To Wscript.Arguments.Count - 1
      prgArgs = prgArgs & " " & Wscript.Arguments.Item(i)
   Next
End If
Set objShell = CreateObject("Shell.Application")
Set fso      = CreateObject("Scripting.FileSystemObject")
strPath      = fso.GetParentFolderName (WScript.ScriptFullName)
If fso.FileExists(strPath & "\" & prgName) Then
   prgCmd = Chr(34) & strPath & "\" & prgName & Chr(34)
   If prgArgs <> "" Then
      prgCmd = prgCmd & " " & prgArgs
   End If 
   objShell.ShellExecute "wscript.exe", prgCmd, "", "runas", 1
Else
   Wscript.Echo "Script file not found"
End If

vbscript:(UnzipFiles.vbs)

' unzip a file- for now assume that full paths will be provided
ZipFile  = Wscript.Arguments.Item(0)
Extract  = Wscript.Arguments.Item(1)
Set fso  = CreateObject("Scripting.FileSystemObject") 
If fso.FileExists( ZipFile ) Then
' If the extraction location does not exist create it.
   If NOT fso.FolderExists( Extract ) Then 
      fso.CreateFolder( Extract ) 
   End If 

' Do the extraction  
   set objShell   = CreateObject( "Shell.Application" ) 
   set FilesInZip = objShell.NameSpace( ZipFile ).items 
   objShell.NameSpace( Extract ).CopyHere  FilesInZip, 16 

   Set objShell = Nothing 
Else
   Wscript.echo "Zip file not found"
End If

Set fso      = Nothing

我在RunElevated中使用wscript,因为我想从uzip命令看到进度框,而不是cmd窗口 . 我在CopyHere中使用16来不提示覆盖文件 .

它工作得很好除了它在压缩开始后立即返回,这使得尝试使用解压缩文件变得混乱 .

我找到了Run命令,它有一个等待进程完成的选项:

Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "TestScript.vbs" intWindowStyle, bWaitOnReturn

我假设允许我(将bWaitOnReturn设置为true)让vbscript等到调用完成后,但我没有看到如何使用Run在提升模式下运行 .

我一直在寻找,但我没有找到一种方法来提升并等待该过程完成 . 这似乎是一个非常常见的要求(每当复制,解压缩等) . 我是一个vbscript新手,我要么找不到答案,要么在看时不认识它 .

一些vbscript大师可以帮助我吗?或者如果我的Java错了,我也很乐意在那里提供帮助!