如何以编程方式锁定Windows工作站? [英] How do I lock a windows workstation programmatically?

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

问题描述


可能重复:

我目前正在使用需要锁定工作站功能的Visual Studio Windows窗体应用程序。调用函数时,如何利用user32.dll进行锁定(Windows + L)?

I am currently working on a visual studio windows form application that requires a function that locks the workstation. How can i make use of user32.dll to do a lock (Windows + L) when the function is called?

推荐答案

我自己还没有尝试过,但是我发现在Google上

I haven't tried it myself, but I found this on google

Process.Start( @ C:\WINDOWS\system32\rundll32.exe, user32.dll,LockWorkStation);

编辑:我试过了,它能起作用!

edit: I tried it, and it works!

edit2:这是解决方案,它使用的是 user32.dll ,而不会启动外部进程。

edit2: Here's a solution using user32.dll that doesn't start an external process.

使用System.Runtime.InteropServices;

声明类似

[DllImport("user32.dll")]
public static extern bool LockWorkStation();

,然后调用 LockWorkStation();

Voilà

这篇关于如何以编程方式锁定Windows工作站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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