我如何锁定从窗口服务的工作站? [英] How do I lock the workstation from a windows service?

查看:407
本文介绍了我如何锁定从窗口服务的工作站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从写在VB.Net一个窗口服务锁定工作站。我写的应用程序在Windows 7上,但它需要在Vista和XP下正常工作。

I need to lock the workstation from a windows service written in VB.Net. I am writing the app on Windows 7 but it needs to work under Vista and XP as well.

USER32 API LockWorkStation不起作用,因为它需要一个交互式桌面和我得到的返回值为0。

User32 API LockWorkStation does not work as it requires an interactive desktop and I get return value of 0.

我打过电话%WINDIR%\ SYSTEM32 \ RUNDLL32.EXE user32.dll中,无论从工艺和壳牌LockWorkStation,但还是没有任何反应。

I tried calling %windir%\System32\rundll32.exe user32.dll,LockWorkStation from both a Process and from Shell, but still nothing happens.

设置为与桌面交互的服务是一个没有去,因为我正在运行的管理员帐户下的服务,使其能够做到这一点,需要管理员权限一些其他的东西 - 就像禁用网络,你只能选择互动与桌面选项,如果运行在本地系统帐户。

Setting the service to interact with the desktop is a no-go as I am running the service under the admin account so it can do some other stuff that requires admin rights - like disabling the network, and you can only select the interact with desktop option if running under Local System Account.

这将是次要的问题 - 如何在不窃听用户运行与在本地系统帐户运行的服务管理权限的另一个应用程序

That would be secondary question - how to run another app with admin rights from a service running under Local System Account without bugging the user.

我在写一个应用程序来控制我的孩子们电脑/上网(我打算开源做的时候),所以我需要的一切发生,因为悄悄地。

I am writing an app to control my kids computer/internet access (which I plan to open source when done) so I need everything to happen as stealthily as possible.

我有一个处理在任务栏的设置和状态通知的用户界面,但就是容易杀死,从而打败锁定。我可以做另一个隐藏的Windows窗体应用程序处理的锁定,但是这似乎只是一个相当不雅的解决方案。

I have a UI that handles settings and status notifications in the taskbar, but that is easy to kill and thus defeat the locking. I could make another hidden Windows Forms app to handle the locking, but that just seems a rather inelegant solution.

更好的想法吗?

推荐答案

上午我不是完全满意我的回答,但Windows的安全性让我别无选择。凡是开府服务(通过流程,壳牌等等)将不会有桌面访问。我理解其背后微软已经创建了限制,但仍然令人沮丧的原因!

Am am not totally satisfied with my answer but Window's security leaves me little alternative. Anything opened bu the service (through Process, Shell whatever) will not have desktop access. I understand the reasons behind the limitations Microsoft has created but still frustrating!

我的服务使用IPC告诉我的UI来锁定计算机。这是做一个基本的链接:

My Service uses IPC to tell my UI to lock the computer. Here is a basic link on doing that:

http://anoriginalidea.word$p$pss.com/2007/08/09/simple-inter-process-communication-in-vbnet/

见他引用链接其他数据。

See his reference links for additional data.

不过,仍然完全不是那么回事。也看到这个链接,如何做到这一点没有访问被拒绝的消息:

However, that still does not quite work. Also see this link for how to do it without the Access Is Denied messages:

<一个href="http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/ce968b5b-04fe-46d2-bb75-73e367a8b0c3" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/ce968b5b-04fe-46d2-bb75-73e367a8b0c3

请确保您的URI是正确的。在服务器端的端口名属性是GetObject方法调用的IPC路径的第一部分。第二部分映射到服务器端的RegisterWellKnownServiceType调用的第二个参数。

Make sure your URIs are correct. The portName property on the server side is the first part of the IPC path in the GetObject method call. The second part maps to the second parameter of the RegisterWellKnownServiceType call on the server side.

和明显的PORTNAME属性需要在不同的服务器版和客户端方面。

And apparently the portName properties need to be DIFFERENT on the sever and client sides.

如果你得到无法连接到IPC端口:系统找不到指定的文件。您的客户端上,然后在服务器尚未启动所以没有什么可听到你的尖叫。

If you get "Failed to connect to an IPC Port: The system cannot find the file specified." on your client then the server has not started yet so there is nothing to hear you scream.

这篇关于我如何锁定从窗口服务的工作站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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