Control-Alt-Delete from python or command line

后端 未结 6 596
暖寄归人
暖寄归人 2021-01-28 14:13

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 c

6条回答
  •  轮回少年
    2021-01-28 15:08

    You surely mean activating the Windows Security window. In this case:

    import win32com.client
    
    shell = win32com.client.Dispatch("WScript.Shell")
    shell.SendKeys("^(%{DELETE})")
    

    UPDATE

    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.

    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)
    

    I just tested this in my PC, so is final information (though not necessarily correct; this is up to the OP :-) ).

    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.

提交回复
热议问题