Control-Alt-Delete from python or command line

后端 未结 6 547
暖寄归人
暖寄归人 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 14:51

    On reading OP's comments, his/her original need was to change the user's password. In fact, this can be done with:

    from win32com import adsi
    ads_obj = adsi.ADsGetObject("WinNT://localhost/%s,user" % username)
    ads_obj.SetPassword(password)
    
    0 讨论(0)
  • 2021-01-28 14:54

    As far as I know, Ctrl-Alt-Delete is protected for security reasons, so programs cannot use it. (At least in Windows 7 and before.)

    0 讨论(0)
  • 2021-01-28 15:05

    If what you want to do is to shutdown or restart the system, Windows has a 'shutdown' command and linux's typically have 'shutdown' and 'reboot' commands.

    0 讨论(0)
  • 2021-01-28 15:05

    Check out the following thread:

    • http://forums.codeguru.com/showthread.php?330557-Ctrl-alt-delete

    According to it, VNC uses something like this:

    PostMessage HWND_BROADCAST, WM_HOTKEY, 0, MakeLong(MOD_ALT Or MOD_CONTROL, VK_DELETE)
    

    I suspect you would need to use ctypes or PyWin32 to do something like this. I would probably go with ctypes since it's cross-platform, however, even with ctypes you would probably need to write a special method for each OS that you support.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-28 15:12

    You can use vncdotool library At:

    lib

    And use vncdotool by:

    os.system("vncdotool key ctrl-alt-del")
    
    0 讨论(0)
提交回复
热议问题