VBscript运行cmd并等待输出

时间:2016-03-28 16:28:43

标签: vbscript

我正在尝试使用Certutil读取用户的PKI卡数据并将数据转储到文本文件中。我们的想法是将其作为登录脚本的一部分,以使用过期证书收集用户的一些数据。

这是我的代码部分:

set oShell = WScript.CreateObject("WScript.Shell")
strcommand = "cmd /c certutil -scinfo -silent > " & StrPath
oShell.Run strcommand, true

它似乎工作,将证书数据转储到文本文件(strpath变量),但是一旦我向脚本添加更多行,它永远不会等待命令窗口完成。它只是在几分之一秒内关闭。我知道读取PKI卡需要7秒钟。我已经尝试过睡眠以及do / while循环,似乎没有任何东西允许命令窗口运行。我还尝试了here.

列出的各种intwindowstyle选项

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

<!DOCTYPE html> <?php ob_clean();session_start(); if (isset($_GET['logout'])){ session_destroy(); } if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] == false) { header("Location: index.php"); } if (isset($_POST['submit'])){ header( 'Location: Review.php' ); } ?> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Attach Image</title> <link href="CSS/boilerplate.css" rel="stylesheet" type="text/css"> <link href="CSS/master.css" rel="stylesheet" type="text/css"> <script src="JAVASCRIPT/respond.min.js"></script> </head> <body link="black"> <?php if (isset($_POST['delete'])){ if (file_exists("UPLOADS/Image Attachment.jpg")) { echo '<font size="3"><p align="center"><b>DETLEION COMPLETE: </font><font color="#000000" size="3">Image no longer available</b></p></font>'; unlink('UPLOADS/Image Attachment.jpg'); $loadingimage = false; } else{ echo '<font size="3"><p align="center"><b>DETLEION FAILED: </font><font color="#000000" size="3">No image available for Deletion</b></p></font>'; } } if(isset($_FILES['UploadFileField'])){ $allowed = array('jpg','png','jpeg'); $name = $_FILES["UploadFileField"]["name"]; $tmp = $_FILES['UploadFileField']['tmp_name']; $type = $_FILES['UploadFileField']['type']; $newName = "Image Attachment.jpg"; $types = array('jpg','png','jpeg'); $ext = pathinfo($name, PATHINFO_EXTENSION); if(in_array($ext,$types)){ move_uploaded_file($tmp, "UPLOADS/$newName"); echo '<font size="3"><p align="center"><b>UPLOAD SUCCESSFUL: </font><font color="#000000" size="3">Your document has now been uploaded and is ready to send.</b></p></font>'; $loadingimage = true; } else { if(!$tmp){ echo '<font size="3"><p align="center"><b>UPLOAD FAILED: </font><font color="#000000" size="3">No document has been selected.</b></p></font>'; } else { echo '<font size="3"><p align="center"><b>UPLOAD FAILED: </font><font color="#000000" size="3">Uploaded document was an incorrect extension type, please use ".jpg", ".jpeg", or "png" only.</b></p></font>'; } } } ?> <div class="gridContainer clearfix"> <div id="borderDiv"> <div id="navDiv"> <div id="backNavDiv"> <a href="index.php?logout"><font color="white"><p align="right"><b>&nbsp;&lt;&nbsp;Log Out</b></p></font></a> </div> </div> <div id="headerDiv"> <p>Attach Image</p> </div> <div id="loginBtnDiv"> <div id="uploadAreaDiv"> <form action="AttachImage.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm"> <label for="UploadFileField"></label> <input type="file" name="UploadFileField" id="UploadFileField"/> <input type="submit" name="UploadButton" id="UploadButton" value="Upload"/> </form> </div> <form action="AttachImage.php" method="post" enctype="multipart/form-data" name="delete" id="delete"> <input id="delete" name="delete" type="submit" value="Delete"> </form> <form action="AttachImage.php" method="post" enctype="multipart/form-data" name="FileForm" id="FileForm"> <input id="submit" name="submit" type="submit" value="Next"> </form> </div> </div> </div> <div id="logoDiv"> <img src="IMAGES/Logo.png"> </div> </body> </html> 应该有效。第二个参数是oShell.Run strcommand, ,true参数,而不是intWindowStyle。你也可以使用

oShell.Run strcommand,bWaitOnReturn:= true

如果这不起作用,您可以尝试使用Exec Method。此链接指向的文档有一个很好的示例,即使用一个循环bWaitOnReturn,该循环将一直运行,直到该过程结束。