简体   繁体   English

如何隐藏VB程序中的命令提示符并执行操作?

[英]How can I hide command prompt in a VB program but also take an action?

I am creating a program that will format flash drives selected by the user. 我正在创建一个程序,该程序将格式化用户选择的闪存驱动器。 I am doing this by using the format.com process. 我通过使用format.com流程来做到这一点。 The issue with hiding the command prompt window is command prompt requires you to hit enter in order to begin the format of the drive. 隐藏命令提示符窗口的问题是命令提示符要求您按Enter键才能开始驱动器的格式。 Is there a way to bypass this? 有没有办法绕过这个? Also, is there anyway VB can tell when command prompt has finished so I can create a message that says the formatting is finished? 此外,VB是否还能告诉命令提示符何时完成,以便我创建一条消息,说明格式化已完成? My relevant code is below. 我的相关代码如下。

For j = 0 To drives.Length() - 1
            Dim formatProcess As New ProcessStartInfo("format.com", drives(j) & "/Q /FS:NTFS /V:" & formattedDate)
            formatProcess.WindowStyle = ProcessWindowStyle.Hidden
            formatProcess.CreateNoWindow = True
            Process.Start(formatProcess)
        Next

Instead of hiding it, you can force a press of the enter key immediately (and then possibly hide it). 除了隐藏它,您可以立即强制按下Enter键(然后可能将其隐藏)。

You can do this: 你可以这样做:

SendKeys.Send("{ENTER}")

As for sensing when it is done: 至于何时完成检测:

Is there a process that shows up while it is formatting? 格式化时是否有显示的进程? If so, you can check for this process and display the message when the process isn't there. 如果是这样,您可以检查该过程并在该过程不存在时显示消息。

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

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