   fs.existsSync(updateDotExe)
 
 installContextMenu = (callback) ->
-  fileKeyPath = 'HKCU\\Software\\Classes\\*\\shell\\Atom'
-  directoryKeyPath = 'HKCU\\Software\\Classes\\directory\\shell\\Atom'
-  backgroundKeyPath = 'HKCU\\Software\\Classes\\directory\\background\\shell\\Atom'
-
-  spawnReg = (args, callback) ->
+  addToRegistry = (args, callback) ->
     args.unshift('add')
-    regProcess = ChildProcess.spawn('reg.exe', args)
-
-    error = null
-    regProcess.on 'error', (processError) -> error ?= processError
-    regProcess.on 'close', (code, signal) ->
-      error ?= new Error("Command failed: #{signal ? code}") if code isnt 0
-      error?.code ?= code
-      callback(error)
+    args.push('/f')
+    spawnReg(args, callback)
 
   installMenu = (keyPath, callback) ->
-    args = [keyPath, '/ve', '/d', 'Open with Atom', '/f']
+    args = [keyPath, '/ve', '/d', 'Open with Atom']
     spawnReg args, ->
-      args = [keyPath, '/v', 'Icon', '/d', process.execPath, '/f']
+      args = [keyPath, '/v', 'Icon', '/d', process.execPath]
       spawnReg args, ->
-        args = ["#{keyPath}\\command", '/ve', '/d', process.execPath, '/f']
+        args = ["#{keyPath}\\command", '/ve', '/d', process.execPath]
         spawnReg(args, callback)
 
   installMenu fileKeyPath, ->
     installMenu directoryKeyPath, ->
       installMenu(backgroundKeyPath, callback)
+
+uninstallContextMenu = (callback) ->
+  deleteFromRegistry = (keyPath, callback) ->
+    spawnReg(['delete', keyPath, '/f'], callback)
+
+  deleteFromRegistry fileKeyPath, ->
+    deleteFromRegistry directoryKeyPath, ->
+      deleteFromRegistry(backgroundKeyPath, callback)
 
 # Handle squirrel events denoted by --squirrel-* command line arguments.
 exports.handleStartupEvent = ->


updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
exeName = path.basename(process.execPath)

# Spawn the Update.exe with the given arguments and invoke the callback when
# the command completes.

          app.quit()
      true
    when '--squirrel-uninstall'
      exports.spawn ['--removeShortcut', exeName], ->
        uninstallContextMenu ->
          app.quit()
      true
    when '--squirrel-obsolete'
      app.quit()
