Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a python script , which I want to run , when user unlocks the machine ie; When users presses Cntl-Alt-Delete and enters username and password and logs in.

How can I do this ? . Is there any registry value , I can add that

pythonw.exe C:\myscript.py to that so that , it runs myscript.py everytime , user unlocks the machine ?

share|improve this question

migrated from stackoverflow.com Mar 31 '11 at 16:39

This question came from our site for professional and enthusiast programmers.

3 Answers 3

You can use the Windows Task Scheduler (Vista and higher) or the Scheduled Tasks control panel (WinXP) to create a scheduled task that triggers "At logon" or "On workstation unlock." I believe such a trigger will cause the task to execute in the scenario you describe.

share|improve this answer
    
Nope. I just tried and it didn't ran. –  Jijoy Mar 31 '11 at 8:49
2  
There's also an "On workstation unlock" trigger. Give that a try. –  Mike Mar 31 '11 at 9:14
1  
in windows xp ? –  Jijoy Mar 31 '11 at 9:28
2  
No, I believe "On workstation unlock" may be limited to Vista and higher. There may be a way to achieve similar results on xp but it's probably not as straightforward. You might want to add "XP" to your original question (or the tags) if "XP" is the required platform. BTW, I just verified that "On workstation unlock" works as expected on Vista by having it send mail to myself. –  Mike Mar 31 '11 at 9:47

For Windows XP, use PyWin32 to:

  • win32gui.CreateWindow() an invisible window
  • call win32ts.WTSRegisterSessionNotification()
  • listen for WM_WTSSESSION_CHANGE window messages having wparam == WTS_SESSION_UNLOCK
    • lparam will be the session ID
  • An example implementation: wtsmonitor.pyw

If you want the script to work for multiple users, convert it to a service (win32serviceutil is handy for this); see wtsmonitor-svc.py at the above address.

share|improve this answer

you should check Schtasks.exe

Enables an administrator to create, delete, query, change, run, and end scheduled tasks on a local or remote computer. Running Schtasks.exe without arguments displays the status and next run time for each registered task.

share|improve this answer
    
it can run only on logon and not on while user unlocks the machine. –  Jijoy Mar 31 '11 at 8:49
    
check here technet.microsoft.com/en-us/library/bb490996.aspx in the "/sc" parameter there is a ONLOGON value that following their description should do what you need –  P2bM Mar 31 '11 at 9:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.