以 SYSTEM 身份运行并注销用户“USER”别针

发布于 2024-09-13 08:14:25 字数 325 浏览 10 评论 0原文

我有一个作为计划任务运行的程序。该程序在 XP 上作为 SYSTEM 运行。 这个想法是,当 USER 处于活动状态时,程序将在后台运行。

我需要程序在发生特定情况时注销用户。

我尝试使用:

[DllImport("user32.dll")]
public static extern int ExitWindowsEx(int uFlags, int dwReason);

但这似乎没有注销用户。

我想也许它正在注销系统,因为它是以系统身份运行的。

我如何登录用户?

谢谢, 夏季灯泡。

I have a program that runs as a scheduled task. The program runs on XP as SYSTEM.
The idea is that the program will run in the background, while USER is active.

I need the program to logoff USER when specific conditions occur.

I tried using:

[DllImport("user32.dll")]
public static extern int ExitWindowsEx(int uFlags, int dwReason);

but that appears to not log USER off.

I think maybe it's logging SYSTEM off, as it is running as SYSTEM.

How can i logogg USER?

Thanks,
SummerBulb.

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

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

发布评论

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

评论(2

掩于岁月 2024-09-20 08:14:25

我认为您需要以该用户身份运行一些代码。创建一个在用户登录时运行的应用程序,然后监视事件。让您的服务设置事件,然后代码将调用 ExitWindowsEx 方法。正如 James 提到的,您仍然需要使用 forceifhung 和 logoff 参数。

I think that you will need to run some code as that user. Create an app that runs when a user logs in and then monitors an event. Have your service set the event and then the code will call the ExitWindowsEx method. You will still need to use the forceifhung and logoff params as James mentioned.

帅的被狗咬 2024-09-20 08:14:25

如果您显示 ExitWindowsEx 的标志将会有所帮助,但您可能需要模拟用户,尽管我认为这不太可能。如果我记得注销当前用户就足够了,但您可能必须强制注销,因为如果用户尚未保存某些更改,则可以取消注销。


但要冒充用户,你可以看看这个:
http://www.codeproject.com/KB/system/UserImpersonation.aspx

我将从这里开始查看,并包括 logoff 和 forceifhung 值:
http://msdn.microsoft.com/en-us /library/aa376868(VS.85).aspx

它类似于 EWX_FORCEIFHUNG | EWX_LOGOFF 作为参数。

更新:

我希望迈克是正确的,冒充在这里没有帮助。

It would help if you showed the flags for ExitWindowsEx, but you may need to impersonate the user, though I think this is unlikely. If I remember logging off the current user was enough, but you may have to force the logoff, as it can be cancelled otherwise, if the user hasn't saved some changes for example.


But to impersonate a user you can look at this:
http://www.codeproject.com/KB/system/UserImpersonation.aspx

I would start with looking here, and include both the logoff and forceifhung values:
http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx

It would be similar to EWX_FORCEIFHUNG | EWX_LOGOFF as the parameter.

UPDATE:

I expect Mike is correct that impersonation won't help here.

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