     when '--squirrel-install', '--squirrel-updated'
       exports.spawn ['--createShortcut', exeName], ->
         installContextMenu ->
-          updatePath ->
+          addCommandsToPath ->
             app.quit()
       true
     when '--squirrel-uninstall'
       exports.spawn ['--removeShortcut', exeName], ->
         uninstallContextMenu ->
-          app.quit()
+          removeCommandsFromPath ->
+            app.quit()
       true
     when '--squirrel-obsolete'
       app.quit()

      fs.writeFile apmCommandPath, apmCommand, ->
        callback()

  getPath = (callback) ->
    spawnReg ['query', environmentKeyPath, '/v', 'Path'], (error, stdout) ->
      if error?
        if error.code is 1
          # The query failed so the Path does not exist yet in the registry
          return callback(null, '')
        else
          return callback(error)

      lines = stdout.split(/[\r\n]+/).filter (line) -> line
      segments = lines[lines.length - 1]?.split('    ')
      if segments[1] is 'Path' and segments.length >= 3
        pathEnv = segments?[3..].join('    ')
        callback(null, pathEnv)
      else
        callback(new Error('Registry query for PATH failed'))

  addBinToPath = (pathSegments, callback) ->
    pathSegments.push(binFolder)
    newPathEnv = pathSegments.join(';')

    installMenu directoryKeyPath, ->
      installMenu(backgroundKeyPath, callback)

# Get the user's PATH environment variable registry value.
getPath = (callback) ->
  spawnReg ['query', environmentKeyPath, '/v', 'Path'], (error, stdout) ->
    if error?
      if error.code is 1
        # The query failed so the Path does not exist yet in the registry
        return callback(null, '')
      else
        return callback(error)

    lines = stdout.split(/[\r\n]+/).filter (line) -> line
    segments = lines[lines.length - 1]?.split('    ')
    if segments[1] is 'Path' and segments.length >= 3
      pathEnv = segments?[3..].join('    ')
      callback(null, pathEnv)
    else
      callback(new Error('Registry query for PATH failed'))

# Uninstall the Open with Atom explorer context menu items via the registry.
uninstallContextMenu = (callback) ->
  deleteFromRegistry = (keyPath, callback) ->
