I am trying to set up the emacs server daemon and use emacsclient on MS Windows so that files can be opened quickly without the delay and overhead associated with starting additional instances of emacs for each file opened. I am following the specific instructions provided in emacswiki for MS Windows which involves:

  1. Running emacs as a daemon, runemacs.exe --daemon
  2. Followed by invoking emacsclientw.exe with the appropriate options.

Starting the daemon succeeds (I see emacs.exe in the process list), but invoking emacsclient produces errors. The wiki says to create a shortcut to emacsclientw.exe and change the target to

X:\path\to\emacs\bin\emacsclientw.exe -na "X:\path\to\emacs\bin\emacsclientw.exe" -c -n

Is this correct? It looks like the client is invoked twice. Using the target as shown does not run the program and produces the error "file name or argument required". Using only the first part of the target shown above

X:\path\to\emacs\bin\emacsclientw.exe -na

produces a generic error. Using only the second part

X:\path\to\emacs\bin\emacsclientw.exe -c -n

produces the error "No socket or alternate editor." (The official emacsclient options are described here.)

Any suggestions? Emacs runs fine in standard mode, that is, not in daemon mode. Version 25.1. I would prefer to run the daemon rather than starting the server in my initialization file.


I am not so sure about the advice in the emacswiki page. What you want to do is to the following:

  • Launch an emacs client connected to the running emacs server.
  • If the emacs server is not running, start it, and then connect the emacs client.
  • Don't wait for the client to finish (if you're starting from a command line).

The command I use is

C:\emacs\bin\emacsclientw.exe -n -c -a ""

The -n means don't wait for the client to finish when you're launching from command line. The -a allows you to specify an alternative editor if the emacs server isn't running, but if you give it an empty string, it will try to start the emacs server and connect to it. Finally, if you're putting this in a windows shortcut, you want to also add a -c which will open a new frame (see emacsclient options).

Here's my shortcut, it works for me (on windows 7, emacs 25.3). I don't know why the emacswiki page put another invocation of emacsclientw as the alternative editor that makes no sense.

I should add that when I try to omit the -c option when running as a shortcut, it gives an error.

emacsclientw shortcut

  • 1
    Configuring the emacsclientw.exe shortcut in the way shown produces: Error: Cannot connect even after starting the Emacs daemon Confirmed this shortcut does launch the daemon process, but files still open in their own emacs instance. Tested with and without administrator priveleges. Emacs 25.1, Windows 7.
    – Snelephant
    Feb 4 '18 at 1:14
  • @Snelephant, hmm, I don't know what could be wrong. I even downgraded to emacs 25.1 and my shortcut still worked. How are you opening files through a context menu or with the command in the shortcut followed by the filename?
    – Angelo
    Feb 4 '18 at 14:07
  • The error occurs both when I click the shortcut to emacsclientw.exe itself with no file specified and when I click a shortcut to a text file with the emacsclientw.exe and file name specified in the Target field. Actually, I am not clear on the intended method for opening files into the client on Windows? I would like to just click the file in Windows Explorer. Clicking a file in OSX seems to open the file in an existing instance, but clicking a file in Windows creates a separate instance. Note I have configured Windows to open text files using the runemacs.exe provided with emacs.
    – Snelephant
    Feb 5 '18 at 2:39
  • If you have configured Windows to open text files with runemacs.exe, then they will open in separate Emacs processes. You'd want to change that association to use emacsclientw instead.
    – glucas
    Jun 1 '18 at 5:03
  • @glucas Changed text file associations to the shortcut to emacsclientw.exe as Angelo described. Clicking a text file produces the same Error: Cannot connect even after starting the Emacs daemon.
    – Snelephant
    Jun 13 '18 at 17:56

For Emacs 26.3 and Windows 10 works:

Daemon: C:\YOUR_EMACS\emacs-26.3\bin\emacs.exe "--daemon"

Client: e.g: C:\YOUR_EMACS\emacs-26.3\bin\emacsclientw.exe "temp.org"

When you add Emacs executable into PATH, you can easily open emacsclientw.exe from anywhere. Also you can add daemon in startup folder: C:\Windows\System32\cmd.exe /c start /high emacs.exe "--daemon"

  • 1
    Thank you so much this worked great for me when nothing else seemed like it was. I will also say I had to create a shortcut for the client to actually launch it. For some reason emacsclientw.exe "temp.org" wasn't working from the cmd line with my emacs config. That said with no config it did work to launch from the cmd line like that. :/
    – nmu
    Aug 13 '20 at 13:00

The command I use is:

emacsclientw.exe --create-frame --no-wait --alternate-editor runemacs.exe --server-file %APPDATA%\.emacs.d\server\server

(If the Emacs bin folder is not on your PATH, use the full paths for emacsclientw.exe and runemacs.exe.)

or with the short option names and the empty string trick,

emacsclientw.exe -c -n -a "" -f %APPDATA%\.emacs.d\server\server

Note that the empty string trick for -a will start the daemon if it isn't running, but this isn't supposed work until Emacs 26 (I'm still on 25). Before 26 you have to specify the alternative editor explicitly. I used runemacs.exe, but my Emacs is configured to start the server and leave it running.

Because Windows lacks the local Unix domain sockets emacsclient normally would have used to connect to the server, it has to fall back to using a network TCP socket. For obvious security reasons, you don't want just anyone on your network to access your whole file system via the Emacs server. Thus, emacsclient must know the right (ephemeral) port and security token written in the server file before the server will allow it to connect.

If the server is already running, then you shouldn't need the -a (but it doesn't hurt). You could set the ALTERNATE_EDITOR environment variable instead of using -a.

If you set the EMACS_SERVER_FILE environment variable, then you don't need to specify it again with -f.


I encountered the connection problem too. And I try to fix it by the steps below.

  1. Checks if the environment variable EMACS_SERVER_FILE exists.

    • A. If the variable exists, go to step 2
    • B. If not, go to step 5
  2. Checks if the EMACS_SERVER_FILE pointed file exists. It is normally %USERPROFILE%\.emacs.d\server\server.

    • A. If it exists, remove it and go to step 3
    • B. If not, go to step 5
  3. Closes all Emacs processes and run emacs --daemon in the cmd or PowerShell. Checks if EMACS_SERVER_FILE file generates.

    • A. If the file generates, go to step 4
    • B. If not, go to step 5
  4. Uses this command emacsclientw -c -n -a= to connect the server and cross your fingers.

    • A. If it can connect to the server, congratulations to you.
    • B. If not, go to step 5.
  5. Uses a file search tool to monitor all server files on your machine. I'm using Everything to monitor files with this filter regex:^server$ ext:. Keep the search results on top. Then close all Emacs processes and rerun emacs --daemon.

    • A. If the search results doesn't change, go to step 6
    • B. If the results changes, find out changed one and set its path as EMACS_SERVER_FILE, redo step 4 to see if the problem solves
  6. Uses emacs --daemon --debug-init to enable Emacs Lisp debugger for init file. See the printed logs and figure out which one causes the server down.

This picture is the search results on my machine: the search results on my machine

In my machine, the reason causes the connection problem is the EMACS_SERVER_FILE pointed file does not the actual used file.

Hopefully, my course of debugging can help you fix it.

  • It took me a while to find that darn server file too! In the end, on Emacs 27 and Windows 7, I found it in C:\path\to\emacs\.emacs.d\.local\etc\server\server. After I set EMACS_SERVER_FILE to this (AND restarted my machine), everything worked okay. Jun 11 at 8:49

Two steps are necessary:

1. Emacs.vbs

Create Emacs.vbs, content:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /c emacs --daemon", 0, True 

Open autostart folder (Win + R, type shell:startup RET) and put Emacs.vbs into it.

2. Emacsclientw.bat

Create Emacsclientw.bat, content:

@echo off
start /b emacsclientw.exe -c -a ""

Safe somewhere, create link, move link to desktop.

After next reboot plus a few seconds, doubleclick on link, here you are.

Works on Win 8.1.

I found the code of Emacs.vbs somewhere, but lost the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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