windows GUI 使用批处理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3367265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GUI Using Batch
提问by Nathan Campos
When you try to do things using Windows Batch, you normally think on a Text Program, but I want to know if there is anyway to use instead of those string inputs at the command window, put on a TextField
, and that the messages get displayed at a MsgBox
. Also, if it's possible to hide the console window.
当您尝试使用 Windows Batch 做事时,您通常会想到一个文本程序,但我想知道是否有任何方法可以代替命令窗口中的那些字符串输入,放在 a 上TextField
,并且消息显示在一个MsgBox
。另外,如果可以隐藏控制台窗口。
Don't matter if VBScript is needed, but only Batch should be better for me
是否需要 VBScript 无关紧要,但只有 Batch 对我来说应该更好
采纳答案by EKS
There was GUI programs in DOS, remember that all windows version before 98 SE all started from DOS ( Not NT kernal based os off course, like we are all using now).
DOS下有GUI程序,记住98 SE之前的所有windows版本都是从DOS启动的(当然不是基于NT内核的操作系统,就像我们现在都在使用的那样)。
Assuming your not planning on writing a DOS app ( qbasiccan do this i think). You can off course do a few tings.
假设您不打算编写 DOS 应用程序(我认为qbasic可以做到这一点)。你当然可以做一些事情。
DOS based menus, sort of easy UI where you would use number on your keyboard to navigate. If your not going for any of the above solutions, you can use a batch file to Start a Windows applciation.
基于 DOS 的菜单,一种简单的用户界面,您可以在其中使用键盘上的数字进行导航。如果您不采用上述任何解决方案,您可以使用批处理文件来启动 Windows 应用程序。
There are also solutions where you could either start a application, or even use a system compiler to compile the code for the app you want. You can off course start the DOS window hidden, that kind of depends on where you start it from.
还有一些解决方案,您可以启动应用程序,甚至使用系统编译器来编译所需应用程序的代码。您当然可以隐藏启动 DOS 窗口,这取决于您从哪里启动它。
回答by SiliconChaos
You might want to take a look at AutoIt, you are able to create executables (with no dependencies) which will not open a console window. You can create GUI windows or just popup plain input or message boxes.
您可能想看看AutoIt,您可以创建不会打开控制台窗口的可执行文件(没有依赖项)。您可以创建 GUI 窗口或只是弹出简单的输入或消息框。
Most of the automation programs/scripts I build are in AutoIt.
我构建的大多数自动化程序/脚本都在 AutoIt 中。
回答by Joey
Without additional tools you're unlikely to succeed with batch files alone. VBScript makes displaying an input box or a message box trivial as you noted. From a batch file you can only show a message box and that one's not even pretty.
如果没有额外的工具,单独使用批处理文件是不可能成功的。正如您所指出的,VBScript 使显示输入框或消息框变得简单。从批处理文件中,您只能显示一个消息框,而那个甚至不漂亮。
You can certainly hide the console window (ShowWindowwill do that), but again, you'll need another program to do it for you. Also it's not nice to hide it if started from a shell already – let the batch file terminate prematurely and you have a console window hidden somewhere.
您当然可以隐藏控制台窗口(ShowWindow会这样做),但同样,您需要另一个程序来为您做这件事。此外,如果已经从 shell 启动,隐藏它也不好 - 让批处理文件过早终止,并且您有一个隐藏在某处的控制台窗口。
I'd suggest you use VBScript which runs on almost as many machines as pure batch files and is orders of magnitude better suited for what you want here.
我建议您使用 VBScript,它在几乎与纯批处理文件一样多的机器上运行,并且在数量级上更适合您想要的内容。
回答by inovasyon
I tried to do this with just batch files but give up after a while. Instead, I'm quite happy with the solution I found. Check FroGwhich let's you to create nice looking and flexible GUI's just with XML. There are samples on their site to give you an idea. There is also a wizards apprentice (something like that) also XML based but it was rather limited. There are some more powerful alternatives out there but it looks like you don't want to involve complicated stuff. So I will not complicate the answer.
我试图只用批处理文件来做到这一点,但过了一会儿就放弃了。相反,我对找到的解决方案感到非常满意。检查FroG,它可以让您仅使用 XML 创建漂亮且灵活的 GUI。他们的网站上有样本可以给你一个想法。还有一个巫师学徒(类似的东西)也是基于 XML 的,但它相当有限。有一些更强大的替代方案,但看起来您不想涉及复杂的东西。所以我不会把答案复杂化。
回答by HighTechProgramming15
You can create a VBS-file using batch, execute that file and delete it when you are done:
您可以使用批处理创建 VBS 文件,执行该文件并在完成后将其删除:
@echo off
md temp
cd temp
(
echo Do
echo X=MsgBox^("This is an example of GUI using batch and VBS.",0+64,"Example"^)
echo X=MsgBox^("Do you want to exit this application?",4+32,"Exit"^)
echo If X=6 Then
echo Exit Do
echo End If
echo Loop
) > gui.vbs
gui.vbs
cd ..
(
echo dim filesys
echo set filesys = CreateObject^("Scripting.FileSystemObject"^)
echo filesys.DeleteFolder "temp"
) > delTemp.vbs
delTemp.vbs
del delTemp.vbs
回答by Patrick Cuff
I think the closest that you're going to get with just Windows batch is using the SET /P variable=[promptString]
command to prompt the user for input.
我认为最接近的方法是使用 Windows 批处理SET /P variable=[promptString]
来提示用户输入。
I once worked in an area where there were a lot of batch scripts that needed lots of arguments passed to them, that the users (non-technical) found awkward and confusing (and justifiably so). I created a GUI "wrapper" for these scripts that would parse each batch file and create a dynamic GUI for its arguments. The user could click a button to run the script; I would shell out to an invisible console, capture the output, and display it in a scrollable textbox. The user could then copy the result to the clipboard or save it to a text file. Perhaps you can do something like that for your scripts?
我曾经在一个有很多批处理脚本需要传递给它们的参数的领域工作过,用户(非技术人员)发现它们很尴尬和困惑(这是有道理的)。我为这些脚本创建了一个 GUI“包装器”,它将解析每个批处理文件并为其参数创建一个动态 GUI。用户可以点击一个按钮来运行脚本;我会转入一个不可见的控制台,捕获输出,并将其显示在可滚动的文本框中。然后,用户可以将结果复制到剪贴板或将其保存到文本文件中。也许你可以为你的脚本做类似的事情?