Create a client shortcut on the Desktop
Emacs ships with several executables for Windows. The emacsclientw.exe
binary is used to connect to a running Emacs server (i.e. daemon).
- Create a shortcut to the client executable.
Right click on the desktop and select "Shortcut".

- Define the client shortcut.
Set Target:
as C:\path\to\emacsclientw.exe -n -c --a ""
.

This creates a new frame (-c
) without waiting for the server to respond (-n
). It has an EDITOR fallback (-a
) that is blank which means Emacs will try to start Emacs in daemon mode on failure before trying to connect again.
Use the "Start in" field to define where the default-directory
should be. Note, this may be somewhere different from where your init.el lives. The "Start in" field defines what directory shows up when you go to find a file (M-x find-file
).
I also like to define a shortcut key in order to open new client frames.
Windows startup script for starting the server
- Goto the startup folder.
This can be done with shell:startup
in File Explorer:

- Create a new text file.
Right click in the folder and select "New > Text Document".

- Change the text file to a batch file.
Right click or press F2 to rename the file as a .bat
(e.g. StartEmacsServer.bat
).

- Define the script.
Put the following code into the batch file.
rem Sets HOME for current shell
set HOME=%APPDATA%
rem Clean previous server file info first
del /q ""%HOME%\\.emacs.d\\server\\*""
rem Start the Emacs daemon/server with HOME as the default directory
C:\path\to\bin\runemacs.exe --daemon
rem Open a client frame
start "" "C:\Users\%USERNAME%\Desktop\emacsclientw.exe - Shortcut.lnk"
REM
(for "remark") is a comment describing the next command.
First, we define an environment variable HOME
. The GNU/Linux equivalent to "HOME" is something like "My Documents" or "AppData\Roaming". Since HOME doesn't exist on Windows systems and Emacs kind of expects it (or is more friendly when it's defined), we call set
to define it in whatever shell instance runs the batch file. The variable %APPDATA%
expands to something like "C:\Users<username>\AppData\Roaming". This is typically where the .emacs.d
directory lives (or at least where I keep mine).
Next, we clear out any old data from previous runs. Emacs stores server/daemon data in the .emacs.d
directory. The del
command removes any copies that may exist.
Another executable shipped with Emacs is runemacs.exe
. This runs a standalone Emacs instance. Here Emacs is started as a server (--daemon
). Since HOME was just defined, the Emacs daemon will read the init.el from that location.
Finally, we call the client shortcut that we previously created.
All together, when Windows starts up, the Emacs server will spin up automatically and, once up, a new frame will appear (eventually. Windows is slow).
Server startup shortcut
- Create a shortcut to the server startup script.
I like to create a shortcut to the server startup script. This is useful when I want to have a clean server instance. I kill the server with something like my-suicide
, then can click the shortcut to get the server going.
(defun my-suicide ()
"Kill all Emacs processes."
(interactive)
(let ((cmd "taskkill /f /fi \"IMAGENAME eq emacs.exe\" /fi \"MEMUSAGE gt 15000\""))
(shell-command cmd)))
