如何在 Windows 中像 Warp 这样的服务器应用程序中隐藏终端 shell?
How to hide terminal shell on server application like Warp in Windows?
我在 Windows 上有一个小型 warp
服务器项目,它侦听特定端口并在我通过 REST 向它发送命令时执行某些操作(例如:POST http://10.10.10.1:5000/print
) .这是一个直接从另一台计算机打印PDF/收据的小客户端。
有效。但我的问题是当我不得不 package
整个项目时,Rust 编译器给我一个可执行文件 (.exe)。当我 运行 时,应用程序显示一个终端 window。我希望以某种方式隐藏此终端。
我尝试 运行 该程序作为 windows 服务(通过使用 NSSM)。它对我不起作用,因为我必须访问打印机。 Windows 不允许我的应用程序作为 windows 服务访问任何设备或任何其他可执行文件。 (这里解释一下原因:How can I run an EXE program from a Windows Service using C#?)
所以我计划 运行 我的应用程序作为托盘图标应用程序,以便用户可以控制或关闭该应用程序。 (https://github.com/olback/tray-item-rs)
不幸的是,我仍然无法隐藏应用程序的终端 window.
我找到的另一个解决方案是 hstart
(https://www.ntwind.com/software/hstart.html)。但我想将其用作“最后的手段”解决方案,因为许多 antivirus/windows 防御者将其标记为恶意软件。
有谁知道如何隐藏或删除它吗?
经过大量搜索,事实证明它比我想象的要容易。只需添加
#![windows_subsystem = "windows"]
在您的 main.rs
文件之上。 (对于 rust > 1.18),终端不见了。
These control the /SUBSYSTEM flag in the linker. For now, only
"console" and "windows" are supported.
When is this useful? In the simplest terms, if you're developing a
graphical application, and do not specify "windows", a console window
would flash up upon your application's start. With this flag, it
won't.
https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute
https://blog.rust-lang.org/2017/06/08/Rust-1.18.html
https://docs.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170
我在 Windows 上有一个小型 warp
服务器项目,它侦听特定端口并在我通过 REST 向它发送命令时执行某些操作(例如:POST http://10.10.10.1:5000/print
) .这是一个直接从另一台计算机打印PDF/收据的小客户端。
有效。但我的问题是当我不得不 package
整个项目时,Rust 编译器给我一个可执行文件 (.exe)。当我 运行 时,应用程序显示一个终端 window。我希望以某种方式隐藏此终端。
我尝试 运行 该程序作为 windows 服务(通过使用 NSSM)。它对我不起作用,因为我必须访问打印机。 Windows 不允许我的应用程序作为 windows 服务访问任何设备或任何其他可执行文件。 (这里解释一下原因:How can I run an EXE program from a Windows Service using C#?)
所以我计划 运行 我的应用程序作为托盘图标应用程序,以便用户可以控制或关闭该应用程序。 (https://github.com/olback/tray-item-rs) 不幸的是,我仍然无法隐藏应用程序的终端 window.
我找到的另一个解决方案是 hstart
(https://www.ntwind.com/software/hstart.html)。但我想将其用作“最后的手段”解决方案,因为许多 antivirus/windows 防御者将其标记为恶意软件。
有谁知道如何隐藏或删除它吗?
经过大量搜索,事实证明它比我想象的要容易。只需添加
#![windows_subsystem = "windows"]
在您的 main.rs
文件之上。 (对于 rust > 1.18),终端不见了。
These control the /SUBSYSTEM flag in the linker. For now, only "console" and "windows" are supported.
When is this useful? In the simplest terms, if you're developing a graphical application, and do not specify "windows", a console window would flash up upon your application's start. With this flag, it won't.
https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute
https://blog.rust-lang.org/2017/06/08/Rust-1.18.html
https://docs.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170