当 Windows 会话断开连接时,如何运行我的应用程序?

发布于 2024-12-16 01:13:08 字数 151 浏览 2 评论 0原文

我用 C# 和 WHITE 制作了一个简单的应用程序,单击按钮即可清除日志。 我使用远程桌面连接连接到我的测试机器并执行该应用程序。当我的会话已连接时,它工作正常,但每当我断开会话时,它就会停止工作。

当 Windows 会话断开连接时,有什么方法可以执行该应用程序吗?

I have made a simple application in C# and WHITE, which click on a button to clear the logs.
I use to connect to my test machine using Remote Desktop Connection and execute that application. It works fine when my session is connected but whenever i disconnect my session, it stops working.

Is there any way to execute that application when windows session is disconnected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

遮了一弯 2024-12-23 01:13:09

取自
https://www.ranorex.com/help/latest/ ranorex-remote/remote-faq#c13444

在远程计算机上创建一个批处理文件并插入以下代码:

for /f "skip=1 tokens=3 usebackq" %%s in (
  `query user %username%`
) do (
 %windir%\System32\tscon.exe %%s /dest:console
)

将此批处理文件保存在远程计算机的桌面上并命名为: “KeepSessionOpen.bat”。
如果您需要断开 RDP 会话,现在只需使用管理员权限运行此批处理文件,您的远程计算机将保持解锁状态。

Taken from
https://www.ranorex.com/help/latest/ranorex-remote/remote-faq#c13444

Create a batch file on your remote machine and insert the code below:

for /f "skip=1 tokens=3 usebackq" %%s in (
  `query user %username%`
) do (
 %windir%\System32\tscon.exe %%s /dest:console
)

Save this batch file on the desktop of your remote machine and name it: 'KeepSessionOpen.bat'.
If you need to disconnect the RDP session, you can now simply run this batch file using administrator privileges and your remote machine will remain unlocked.

白色秋天 2024-12-23 01:13:08

您可以编写一个Windows 服务

You could write a Windows Service.

撕心裂肺的伤痛 2024-12-23 01:13:08

您还可以使用任务计划程序
您可能不需要 C# 包装器,您可以在调度程序中添加自己所需的条目。

You could also use the task scheduler.
You may not need the C# wrapper, you can add yourself the required entry within the scheduler.

不回头走下去 2024-12-23 01:13:08

当我的会话已连接时,它工作正常,但每当我断开会话时,它就会停止工作。

这是设计使然。当您断开会话时,会话将被锁定。当您的会话被锁定时,UI 自动化将无法工作。

您可以通过不锁定会话来解决这个问题,可能通过不同的远程桌面工具(VNC/PcAnywhere)。但这绝对是一个黑客行为。

相反,我建议采用不同的方法。我建议尽可能避免 UI 自动化。我一直发现 UI 自动化不稳定且不可靠。

在对您的问题的评论中,您说您的应用程序只是 UI 自动化,单击按钮即可清除日志。日志由 DebugView 应用程序生成。

我建议您改为登录到文件。 DebugView 的网站上提到了此功能:

http:// /technet.microsoft.com/en-us/sysinternals/bb896647

您还可以考虑使用远程监控。

如果大小是一个问题,您还可以查看“日志文件包装”和“日志文件翻转”功能。

It works fine when my session is connected but whenever i disconnect my session, it stops working.

This is by design. When you disconnect your session, it is locked. When your session is locked, UI automation won't work.

You could hack around this by never locking the session, possibly via different remote desktop tools (VNC/PcAnywhere). But this is definitely a hack.

Instead I suggest a different approach. I recommend avoiding UI automation whenever possible. I have always found UI automation to be flaky and unreliable.

In the comments on your question you said your app is simply UI automation to click a button to clear a log. The logs are generated by the DebugView application.

I suggest you log to a file instead. This feature is mentioned on the web site for DebugView:

http://technet.microsoft.com/en-us/sysinternals/bb896647

You could also look into using remote monitoring.

If size is an issue, you can also look into the "Log file wrapping" and "log-file rollover" features.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文