我想实现windows锁屏功能,网上说可以调用LockWorkStation方法,可以实现。
我在vs中创建了 private static extern bool LockWorkStation(); 调用了该方法,可以实现。
但是我把相同的代码放到windows服务中却实现不了,这是为什么?还能是服务没用相关执行权限?请高手解答,在线等!!!!!!!!
或者有没有其他方法可以在windows服务中实现锁屏?
我是使用c#进行编写的。
尝试用完整路径来创建即可 即输入?:\Windows\System32\rundll32.exe user32.dll,LockWorkStation 注意:?代表你的系统盘,如果是C盘就把?改成C
没做过windows服务器相关的,,做过别的,,我猜一下原因
服务器运行的平台和本地程序运行平台可能有差异,,windows服务器,,
有木有用到什么.net,,之类的看看版本是否一致什么的
还有这个锁屏功能有没有涉及本地方法(C#里面可能叫动态链接库),如果涉及到了,需要在windows服务器上添加相应的,dill
说了这么多,一句话“运行环境不一样”,,,,有问题还可以追问,,知无不言。
是否是因为路径问题呢?你完全可以用vs写一个项目来实现你的目的,写完后生成一下,运行bin/debug里面的exe就可以了
服务启动不了。
Remarks
**The LockWorkStation function is callable only by processes running on the interactive desktop**. In addition, the user must be logged on, and the workstation cannot already be locked.
Common reasons the workstation might not be locked even if the function succeeds include the following: no user is logged on, the workstation is already locked, the process is not running on the interactive desktop, or the request is denied by the Graphical Identification and Authentication (GINA) DLL.