如何使用C#以Process.Start()全屏打开视频文件?(How to open video file in full screen with Process.Start() using C#?)
我想知道如何使用Process.Start()在FULL SCREEN中打开视频文件。
我目前的代码以最大化模式打开了我的目录中的(唯一)文件,这不会隐藏Windows 10任务栏。 如何用Process.Start()全屏打开视频文件?
static void Main(string[] args) { foreach (var path_to_object in Directory.GetFiles(@"D:\")) { ProcessStartInfo file_object = ProcessStartInfo(path_to_object); file_object.WindowStyle = ProcessWindowStyle.Maximized; Process.Start(file_object); } }
I would like to know how to open a video file in FULL SCREEN using Process.Start().
The code I currently have opens the (only) file in my directory in maximized mode, which does not hide the windows 10 task bar. How to open video file in full screen with Process.Start()?
static void Main(string[] args) { foreach (var path_to_object in Directory.GetFiles(@"D:\")) { ProcessStartInfo file_object = ProcessStartInfo(path_to_object); file_object.WindowStyle = ProcessWindowStyle.Maximized; Process.Start(file_object); } }
原文:https://stackoverflow.com/questions/47859585
最满意答案
这是一个使用WMIC的解决方案。
public static void main( String[] args ) throws Exception { // Vars Process process; String output; // Execution process = Runtime.getRuntime().exec("cmd /c wmic process call create calc.exe | findstr ProcessId"); output = readTrimmedOutput(process.getInputStream()); System.out.println("Output from command: " + output); // Basic string manipulation to get process id String str_proc_id = output.split(" = ")[1].replace(";",""); System.out.println("ProcessId is: " + str_proc_id); // Some thread delay that you can comment/uncomment for testing if running or not Thread.sleep(5000); // Finding if process is still running process = Runtime.getRuntime().exec("cmd /c wmic process get processid | findstr " + str_proc_id); output = readTrimmedOutput(process.getInputStream()); boolean isRunning = output.contains(str_proc_id); System.out.println("Is process still running? " + isRunning); } private static String readTrimmedOutput(InputStream is) throws Exception { BufferedReader breader = new BufferedReader(new InputStreamReader(is)); String line = breader.readLine(); return line != null ? line.trim() : ""; }
示例输出
Output from command: ProcessId = 6480; ProcessId is: 6480 Is process still running? true
为了显示/显示cmd控制台,将一些行改为:
// Execution String your_command = "cmd.exe /c \"dir\""; process = Runtime.getRuntime().exec("cmd /c wmic process call create \"" + your_command + "\" | findstr ProcessId");
参考文献:
https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx
Here's a solution that uses WMIC.
public static void main( String[] args ) throws Exception { // Vars Process process; String output; // Execution process = Runtime.getRuntime().exec("cmd /c wmic process call create calc.exe | findstr ProcessId"); output = readTrimmedOutput(process.getInputStream()); System.out.println("Output from command: " + output); // Basic string manipulation to get process id String str_proc_id = output.split(" = ")[1].replace(";",""); System.out.println("ProcessId is: " + str_proc_id); // Some thread delay that you can comment/uncomment for testing if running or not Thread.sleep(5000); // Finding if process is still running process = Runtime.getRuntime().exec("cmd /c wmic process get processid | findstr " + str_proc_id); output = readTrimmedOutput(process.getInputStream()); boolean isRunning = output.contains(str_proc_id); System.out.println("Is process still running? " + isRunning); } private static String readTrimmedOutput(InputStream is) throws Exception { BufferedReader breader = new BufferedReader(new InputStreamReader(is)); String line = breader.readLine(); return line != null ? line.trim() : ""; }
Sample output
Output from command: ProcessId = 6480; ProcessId is: 6480 Is process still running? true
For showing/displaying cmd console change some lines to:
// Execution String your_command = "cmd.exe /c \"dir\""; process = Runtime.getRuntime().exec("cmd /c wmic process call create \"" + your_command + "\" | findstr ProcessId");
References:
https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx
相关问答
更多-
你必须重定向你的输出。 有一个成员hStdOutput和hStdError应该被重定向。 在MSDN上是一个例子。 You have to redirect your output. There is a member hStdOutput and hStdError which should be redirected. Here on MSDN is an example.
-
执行显示控制台窗口的命令并获取进程的句柄(Execute command displaying console window and also get handle of the process)[2023-08-24]
这是一个使用WMIC的解决方案。 public static void main( String[] args ) throws Exception { // Vars Process process; String output; // Execution process = Runtime.getRuntime().exec("cmd /c wmic process call create calc.exe | findstr ProcessId"); ... -
自定义Powershell主机调用没有控制台窗口的外部程序(Custom Powershell Host Invoke external program without console window)[2022-07-01]
事实证明,这是调用控制台命令的预期行为。 在Windows 7及更高版本中,conhost.exe负责处理对控制台程序的调用。 在这种情况下,ping和netstat会触发要创建的conhost实例,它会处理请求,返回结果,然后保持打开状态。 conhost.exe启动是导致我看到的控制台闪存的原因。 它保持打开的事实是我只看到控制台窗口闪烁一次的原因。 一旦conhost连接到调用进程,所有后续控制台命令都由同一个实例处理。 我将此标记为答案,因为应该创建一个新问题来专门解决conhost问题。 资源。 ... -
窗口句柄(HWND)对于系统来说是全局的,因此您可以将句柄作为十进制数字打印到字符串缓冲区中,在使用CreateProcess产生子进程时将其作为字符串传递给命令行,并调用_wtoi()或类似的将字符串再次转换回句柄。 Window handles (HWNDs) are global to the system so you can just print the handle as a decimal number into a string buffer, pass it as a string on ...
-
对于任何想要实现这一目标的人,我使用以下方法做到了。 保存为任何东西.BAT或其他.CMD 更改以下内容以设置您要定位的特定ProcessID编号。 设置pid = 5540 @echo off set pid=5540 echo Option Explicit >temp.vbs echo Dim Shell, WMI, wql, process >>temp.vbs echo Set Shell = CreateObject("WScript.Shell") >>temp.vbs echo Set WM ...
-
家庭作业? 在将员工添加到数据库中时,您已经拥有运行SQL查询的代码。 要显示数据库中的所有员工,您希望执行类似于addEmployee方法的操作,但不要运行INSERT sql命令而是要SELECT using (SqlConnection connection = new SqlConnection(YOURCONNECTIONSTRING)) { connection.Open(); using (SqlCommand c ...
-
是否可以从ruby GUI脚本(.rbw)启动控制台进程(Is it possible to start console process from ruby GUI script (.rbw))[2022-05-11]
问题是Windows上的每个可执行文件在构建时都被定义为GUI可执行文件或控制台可执行文件(嗯,这里有更多细节,但这里没关系)。 运行Ruby脚本的可执行文件是一个GUI可执行文件(它也恰好使用Tk实际构建一个GUI,即使屏幕截图中只有一个非常简单的一个),并且ping可执行文件是一个Console可执行文件。 如果GUI可执行文件启动Console可执行文件,则会自动创建一个控制台以运行可执行文件; 你无法改变这一点 。 当然,图片比这更复杂。 这是因为控制台应用程序实际上可以使用GUI(它只需要进行正确 ... -
您需要在STARTUPINFO结构中指定您希望最初最小化控制台窗口: ZeroMemory(&si); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_MINIMIZE; You need to specify in the STARTUPINFO structure that you want your console window to be initially minimized: ...
-
我终于想出了如何在启动windows应用程序时将其透明地附加到控制台(如果它是前景窗口)。 不要问我为什么必须传递STD_ERROR_HANDLE而不是STD_OUTPUT_HANDLE,但它只是起作用,可能是因为可以共享标准错误。 注意:控制台可以在显示内部应用程序消息时接受用户输入,但在stderr从您的应用程序输出时使用它有点令人困惑。 有了这段代码,如果你从控制台窗口启动你的应用程序至少有一个参数,它会将Console.Write附加到它,如果你使用参数/ debug启动应用程序,那么它甚至会将De ...
-
编写一个控制台处理程序例程来检测CTRL_CLOSE_EVENT(和CTRL_C_EVENT,如果需要),并使用SetConsoleCtrlHandler将处理程序例程添加到您的进程中。 Write a console handler routine that detects CTRL_CLOSE_EVENT (and CTRL_C_EVENT, if desired), and use SetConsoleCtrlHandler to add the handler routine to your pro ...