Windows:隐藏一个新进程(无窗口) [英] Windows: start a new process hidden (no window)

查看:128
本文介绍了Windows:隐藏一个新进程(无窗口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行第3方程序(在我的情况下为VLC),而Windows中不会弹出任何窗口.我正在将Java程序作为Windows服务运行,但运行正常,但是无论我做什么,当我使用Runtime.exec()启动VLC时,都会弹出一个窗口. VLC的命令行参数阻止了GUI,但随后弹出了一个黑色控制台-效果不佳.

I want to execute a 3rd party program (VLC in my case) without any window popping up in Windows. I am running my java program as a Windows service which works fine, but when I start VLC using Runtime.exec() then a window pops up, no matter what I do. There's command line arguments to VLC that prevent the GUI but then a black console pops up - not much better.

所以:您知道如何从Java启动外部程序以使没有可见的窗口出现吗? (它在Mac OS X中可以正常工作,而且我认为Linux会一样)

So: Any idea how to start an external program from Java so that no visible window shows up? (It works just fine in Mac OS X and I assume Linux will be the same)

我知道有一种方法可以直接将libVLC集成到您的Java程序中,但是该选项对我不起作用.

I know there is a way to directly integrate libVLC into your Java program but that option does not work for me.

推荐答案

也许有比这更好的解决方案,但是应该有效.

There's probably a better solution than this, but this should work.

如果安装了Windows脚本(在Win98及更高版本上为标准),则将以下行另存为.vbs文件(例如,invisible.vbs).

If you have Windows Scripting installed (standard on Win98 and newer) save the following line as a .vbs file (invisible.vbs, for example).

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

此脚本允许您使用以下命令以不可见的方式运行任何.bat文件:

This script allows you to run any .bat file invisibly with the following command:

wscript.exe "C:\Path\To\File\invisible.vbs" "C:\Path\To\Another\File\BatFile.bat"

这是基于 cheeken的答案的,因为它将允许您隐藏cmd控制台.您要做的就是创建一个包含start vlc.bat文件.

This builds on cheeken's answer because it will allow you to hide the cmd console. All you have to do is create a .bat file with start vlc in it.

注意:如果使用此脚本执行.bat文件,则该文件必须自行关闭,并且不会引发导致其挂起的错误.如果是这样,它将一直存在,直到关闭或通过任务管理器将其关闭为止.

Note: If you execute a .bat file with this script, it has to close itself and it cannot throw an error which causes it to hang. If it does it will stick around until shutdown or until you close it through the task manager.

这篇关于Windows:隐藏一个新进程(无窗口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆