Sunday 8 July 2018

login - Programmatically add logon/logoff script on Windows

Is there a way to programmatically add a logon or logoff script in Windows? I don't want to use any graphical programs, everything's supposed to happen without the user noticing anything.


Also, I want to run the scripts only when a certain user logs in/out. It shouldn't trigger for every user on the system.


Attempted solutions:




  1. Adding the command to the registry, as per this answer. It seems that adding the command to HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0\0 isn't enough. I found I also need to add the same command at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-57470242-2825662697-3518406308-1003\Scripts\Logoff\0\0 , and possibly also modify %WINDIR%\System32\GroupPolicy\User\Scripts\scripts.ini, otherwise the command simply isn't executed.


    I've stopped pursuing this solution because I don't know what the registry key S-1-5-21-57470242-2825662697-3518406308-1003 is. Is this a random sequence of digits? Is it always the same text? Will it work if I use this on a different PC?




  2. Modifying %WINDIR%\System32\GroupPolicy\User\Scripts\scripts.ini as per this answer. Something very odd is happening here. I can see this file in explorer. It exists. I can open it, and, with admin privileges, can use notepad to modify it. But when I try to access it from within a python script, I get a FileNotFoundError, even if given admin privileges. (Traceback: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Windows\\System32\\GroupPolicy\\User\\Scripts\\scripts.ini' P.S.: I'm not using double backslashes, python just displays them like that)




  3. Creating a startup task using SCHTASKS. I gave up on this because it looks like SCHTASKS only supports logon tasks, but not logoff tasks.



No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...