问题描述
我做了一些研究,但我想能够从python调用control-alt-delete。如果这是不可能的是可能从命令行调用它,因为我可以在python中使用该命令,因为我可以调用python中的命令行。如果有人能指出我的方向是正确的,那将是伟大的。这是一个用wxPython编写的任务管理器。
编辑:
我试图启动Windows安全和从用户回答我尝试
I've done some research but I would like to be able to call control-alt-delete from python. If that is not possible is it possible to call it from command line because then I could just use that command in python because I can call command lines in python. If someone could point me in the right direction that would be great. this is for a task manager written with wxPython.edit:im trying to launch the windows security and from a user answer i tried
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("{CONTROL}{ALT}{DELETE}")
我收到此错误
Traceback (most recent call last):
File "C:/Python27/tescontrol.py", line 4, in <module>
shell.SendKeys("{CONTROL}{ALT}{DELETE}")
File "<COMObject WScript.Shell>", line 2, in SendKeys
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024809), None)
推荐答案
您确定要激活Windows安全窗口。在这种情况下:
You surely mean activating the Windows Security window. In this case:
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("^(%{DELETE})")
UPDATE
上述代码似乎无法工作,因为其他帖子中描述的原因。在这种情况下,另一种方法是创建一个类似的窗口,并从Python调用由真正的Windows安全窗口调用的不同程序/函数。
The above code seems not to work because of the reasons described in other posts. In that case, the alternative is to create a similar window and call from Python the different programs/functions called by the real Windows Security window.
在阅读OP的评论原来的问题,OP的最终需要是更改用户的密码。这可以通过:
On reading OP's comments to the original question, OP's final need is to change a user's password. This can be done with:
from win32com import adsi
ads_obj = adsi.ADsGetObject("WinNT://localhost/%s,user" % username)
ads_obj.SetPassword(password)
在我的电脑中测试这个,所以是最终的信息(虽然不一定正确;这是由OP :-))。
I just tested this in my PC, so is final information (though not necessarily correct; this is up to the OP :-) ).
2:复制后作为单独的答案作为注释似乎表明所有的答案不工作。这对于 SendKeys
命题是正确的,它不起作用。
UPDATE 2: Copying the later as a separate answer as comments seem to indicate that all of the answer doesn't work. This is correct for the SendKeys
proposition, which doesn't work.
这篇关于Control-Alt-Delete从python或命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!