Microsoft products have a folder which contains commands to be run for each user as they log in. Commands in these folders automatically run on login. Commands in the global startup directory run every time any user logs in.
Each login has a customizable folder that will be run only when they log in. On Windows Server 2022, this folder is:
C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
where USERNAME is the name of the user you want to have the command. Any commands located in that folder are executed when user USERNAME user logs in.
To avoid this folder being moved around in past/future versions of Windows, the shortcut shell:startup can be used, either by entering it in the the location bar of File Explorer, or by accessing the Run command (see below)
Windows File Explorer will open with the (usually empty) startup folder for the current user.
There is a global startup folder also, which is executed for any user when they log in. Again, in Server 2022, this is located in
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
, but and administrator can use the command Shell:Common Startup to locate this.
We have a client on as Windows Terminal Server that was constantly frustrated saving files to a shared folder. In this case, it was Public Documents (c:\users\public\documents), so we created a “p” drive (for Public Drive) for them. This was created as a shortcut to the command
C:\Windows\System32\subst.exe P: "C:\Users\Public\Documents"
which we created as follows
C:\Windows\System32\subst.exe P: "C:\Users\Public\Documents"
, then click Next
Shell:Common Startup
in the location bar
Another need we found was to have NextCloud run as an individual user, even if no one was specifically logged into it. A common problem on a multi-user system like Windows Terminal Server, when multiple people share a common area (Public Documents) which need to be sync'd in real time.
Windows allows us to automatically log in a user when the server starts up, but it would be a security breach if a user session was always available, so that user should automatically have their session locked after auto login.
The procedure is documented in Using Nextcloud with Windows Terminal Server, but uses the Shell:Startup folder for that user.