How to: Run PhotoStructure for Node automatically on Windows startup

This how to is for people who are in the following situation:

  • Using Windows 10 or Windows Server 2016+
  • Running PhotoStructure for Node.js

Who want to have PhotoStructure start automatically as a Windows service.

Limitations

  • You won’t be able to see any error messages that appear on startup.
  • If the service fails to start it’s difficult to troubleshoot why. It’s best to revert to manually running the script to troubleshoot rather than through the service.
  • I’ve only tested this on one machine - there may be gotchas with other environments that this guide doesn’t cover.

Steps

Pre-requisites

  1. Get NSSM from here: NSSM - the Non-Sucking Service Manager
  2. Unzip NSSM to C:\Apps\NSSM or similar. You’ll need to use it from the command-line, so put it somewhere convenient.
  3. Download and install Git from here: Git - Downloads
  4. Make sure you have a working PhotoStructure for Node.js instance already, i.e. one you can start from a .sh script.

NB: I have a “test” PhotoStructure library in addition to my three normal libraries, and would highly recommend this principle in general. My “test” library is simple with a few photos - it’s always safer to try new unproven things on a test library than your real (“production”) library, in case something goes wrong, such as with these steps below…

Setup

  1. Open an Administrative Command Prompt
  2. Change directory to wherever you installed NSSM and the win64 subdirectory, e.g. C:\Apps\NSSM\win64
  3. Run “nssm install PS-Library” (replace “PS-Library” with whatever you want the service to be called)
  4. In the popup window that appears, enter the following:
  • Path: C:\Program Files\Git\bin\sh.exe (if you installed Git to a different path, change this to match)
  • Startup directory: C:\Apps\PhotoStructure (the folder your PhotoStructure start .sh script is in)
  • Arguments: C:\Apps\PhotoStructure\start-test.sh (the path to your PhotoStructure start .sh script)
  1. Go to the Details tab and make sure Startup type is “Automatic”.
  2. Go to the Log on tab and select “This account”, then enter a valid account. This may be a local administrator account, or the same account you use to sign into your computer with. Note - for me, the service did run as “Local system”, but it had some weird issues with settings being lost, I found it worked better signed in as my normal user. If you use a Microsoft account to sign-in that’s fine, enter the email address here and the password as you would normally.
  3. Click “Install Service”.

Last Step: Test it works
To test, either:

  • Run “nssm start PS-Library”, or;
  • Open services.msc, locate your service, and right-click then select Start.

Your service should start and stay started. If it stops, something isn’t working properly.
Wait 10-20 seconds for your library to start (depending on the speed of your computer), then browse to your PhotoStructure library in a web browser and make sure it’s working as expected.

Done! Now if you restart your computer, PhotoStructure should be running and available before you even login - just remember to allow enough time for it to start up before testing it.

Troubleshooting

  • Make sure you didn’t add any double-quotes around the path or arguments for the service.
  • Open services.msc, double-click your service then select the Log On tab, and re-enter the credentials. Click OK to save the service, and try start it again. The account may not have been granted the “Log on as a Service” permission correctly. This should ensure it does get granted the permission.
  • Open a Command Prompt, and run “C:\Program Files\git\bin\sh.exe” and ensure a new $ command prompt appears, like so:
  • If the $ command prompt appears, type “exit” and press Enter to quit. That’s good. Now try run the script to start PhotoStructure directly:
  • In a Command Prompt, run “C:\Program Files\git\bin\sh.exe” “C:\Apps\PhotoStructure\ps-start.sh” (replace with your PhotoStructure start script). Does PhotoStructure start? If so, then there’s a problem with the service. If PhotoStructure doesn’t start, then troubleshoot why PS isn’t starting for you.
  • PhotoStructure now picks up photos from locations I didn’t expect? I had this happen when I ran it under Local System rather than my normal account. If it still happens to you, add a “.nomedia” file to the folder that is unwanted in your library. Check your PhotoStructure settings are still correct too.

To Edit

Should you wish to change the service settings, it’s very easy. Just open an Administrative Command Prompt, and go to the NSSM\win64 folder again, and run:

  • nssm edit PS-Library (again replace with your service name if you changed it)

Then you can edit the existing service without deleting and re-creating it.

Nice work! I just linked to this post in the PhotoStructure for Node instructions.

:warning: Caution

As you should do with all third-party software, you should scan the binary (say, via virustotal) before running it. Virustotal has 11 security vendors that mark nssm as malicious. Here’s the analysis of just the x64 binary, which only has 7 flags. There are a number of community members that have marked the installer and binary as safe, fwiw. Actual badware normally has tens-to-hundreds of community members that vote -1.

I can’t/won’t personally vouch for nssm, but it does seem that these flags are due to nssm being used by badware, not that nssm itself is badware.

It’s up to you to decide what’s safe to run on your own system, of course!