Coding and Dismantling Stuff

Don't thank me, it's what I do.

About the author

Russell is a .Net developer based in Lancashire in the UK.  His day job is as a C# developer for the UK's largest online white-goods retailer, DRL Limited.

His weekend job entails alternately demolishing and constructing various bits of his home, much to the distress of his fiance Kelly, 3-year-old daughter Amelie, and menagerie of pets.


  1. Fix dodgy keywords Google is scraping from my blog
  2. Complete migration of NHaml from Google Code to GitHub
  3. ReTelnet Mock Telnet Server à la Jetty
  4. Learn to use Git
  5. Complete beta release FHEMDotNet
  6. Publish FHEMDotNet on Google Code
  7. Learn NancyFX library
  8. Pull RussPAll/NHaml into NHaml/NHaml
  9. Open Source Blackberry Twitter app
  10. Other stuff

Configuring FHEM To Run as a Windows Service

So that FHEM is running constantly, even when noone is logged into my server, I'm going to try to get it running as a Windows Service, which I can configure to run as a particular user as soon as the server boots.

I'm going to base the some of the following on the excellent tutorial to install uTorrent as a service -, so many thanks to the original author.


Remote into your Windows Home Server box as the administrator. Download and install the Windows Server 2003 Resource Tools from, using default installation settings.

Create Service User

  1. On your home server, click Start, right-click My Computer and select Manage
  2. Open Local Users and Groups, select Users then right-click and add a new user
  3. I've called my user FHEMService, make sure you:
    1. Uncheck "User must change password at next logon"
    2. Check "User cannot change password"
    3. Check "Password never expires"
  4. After you've created your new user, we need to temporarily give the user access to log on remotely:
    1. Double click on the newly created user account
    2. Select the Member Of tab and click Add
    3.  Type in the group name "Administrators" then click OK
    4. Click OK again to apply the changes to the user account then log out of the remote session.

Log In as New User

So that we can be sure the new user has enough permission to execute the FHEM server, let's log into the 

  1. Log out of the remote desktop session
  2. Log in as your new user
  3. Give the new user full access to the FHEM folder:
    1. Open Windows Exporer and browse to your FHEM folder, in my case "c:\strawberry\FHEM"
    2. Right-click the FHEM folder and click Properties
    3. In the Folder Properties window, select the Security tab then click Add
    4. Type in the name of the new user then click OK
    5. Select the added user and make sure the user has Modify, Read & Execute and Write access.
    6. Click OK when done.
  4. Create the new Windows Service:
    1. Open command prompt (Start > Run > cmd)
    2. Enter the following commands to create an empty windows service:
      • "c:\Program Files\Windows Resource Kits\Tools\instsrv.exe" FHEM "c:\Program Files\Windows Resource Kits\Tools\srvany.exe"
      • Exit
  5. Configure the service to run FHEM
    1. We now need to configure our new service with the correct command
    2. Open the registry editor (Start > Run > RegEdit)
    3. Locate the key HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet >Services > FHEM
    4. Add a new key called "Parameters"
    5. Add the following two string values to your new key:
      • "Application" with a value point to your perl.exe, for example on my machine "c:\strawberry\perl\bin\"
      • "AppParameters" with a value pointing to your and config files, eg "c:\strawberry\fhem\ config.txt"
    6. Close the Registry editor
  6. Configure the service security and test it:
    1. Open the Services management console (Start > Run > Service.msc)
    2. Double-click the new FHEM service
    3. Click the Log On tab and enter the FHEMService account details
    4. Click OK and attempt to run your service
    5. Check your log file to make sure the service is running successfully.
  7. Finally, connect to your server from a remote machine, and then fully log out from your server - you should be able to carry on using FHEM.

Remove Admin Privileges From FHEMService User

Don't forget to go back in as the server administrator and remove admin privileges from the FHEMService user - in theory this means if anyone finds a way to hack into your FHEM server remotely, there's very little they can do to the Windows environment.

It Didn't Work!

If you've run your service, and you either can't see your log file or your log file isn't updating correctly, there are a few gotchas to bear in mind:

  • Because you're running the service using an absolute path, you can't rely on relative path references in your config file - I had to change my modpath from "." to "c:\strawberry\fhem" (make sure there's no trailing backslash)
  • Try opening a command prompt, and copy-and-pasting the two registry entries you entered in step 5 above into a single command - does your server run or not?
  • If all else fails, it may be possible to create a batch file in your fhem folder with the full command, and point your service to this batch file, but I've not tried this!

Good luck,


Permalink | Comments (0)

Add comment

  Country flag

  • Comment
  • Preview