简体   繁体   English

在Visual Basic中使用命令提示符

[英]Using Command Prompt in Visual Basic

I am trying to create an application in visual basic to open up a command prompt. 我试图在Visual Basic中创建一个应用程序以打开命令提示符。 I then want to type the word "Message" into the command prompt and have my application recognize the word "Message" and then run my application. 然后,我想在命令提示符下键入单词“ Message”,并使我的应用程序识别单词“ Message”,然后运行我的应用程序。

Any help leading me into the right direction would be greatly appreciated. 任何将我引向正确方向的帮助将不胜感激。 Do I need to create a batch file or something else for this to work? 我需要创建一个批处理文件或其他文件才能工作吗? Any advice, articles, or sample code is greatly appreciated. 任何建议,文章或示例代码都将不胜感激。 This is all new to me. 这对我来说是全新的。 I don't have much code, but this is what I have in visual basic: 我没有太多代码,但这是我在Visual Basic中所拥有的:

Process.Start("cmd")
If (cmd.CommandText = "Message") Then
    'calls another class to actually run the program
End If

It's the classic, good news and bad news. 这是经典的,好消息和坏消息。

The bad news is VBA can't do what you want natively. 坏消息是VBA无法自然完成您想要的事情。 What you need to do is to call the "shell and wait" function, then capture it's output on the standard in. 您需要做的是调用“ shell and wait”函数,然后在标准输入中捕获其输出。

This will require you to go beyond just VBA, and link into some windows guts (kernel32). 这将需要您超越VBA,并链接到某些Windows胆量(kernel32)。 The good news is that VBA makes that easy. 好消息是VBA使这变得容易。

While I don't have source for you, a rather extensive article, with code here was referenced in this Stackoverflow Question 虽然我没有来源,你是一个相当广泛的文章,用代码这里在此引用#1提问

Hope this helps! 希望这可以帮助!

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

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