Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama Cmd Start Windows

From Leeroopedia
Knowledge Sources
Domains CLI, Windows
Last Updated 2025-02-15 00:00 GMT

Overview

Windows-specific logic for auto-starting the Ollama desktop application when the CLI cannot connect to the server, including upgrade detection.

Description

The startApp function first checks if the Ollama installer (OllamaSetup.exe) is currently running via isProcRunning (which enumerates Windows processes using windows.EnumProcesses and windows.GetModuleBaseName). If an upgrade is in progress, it returns an error. Otherwise, it locates ollama app.exe by checking three locations in order: the executable's own directory, %LOCALAPPDATA%\Ollama, and the system PATH via exec.LookPath. It launches the app using cmd.exe /c with CREATE_NO_WINDOW (0x08000000) and HideWindow flags to keep it invisible, then calls waitForServer to block until the server is ready. isProcRunning iterates through all system PIDs, opens each process with QUERY_INFORMATION|VM_READ access, retrieves the module base name, and matches against the target process name.

Usage

Called by the Windows CLI when it detects the Ollama server is not running, automatically starting the desktop application before proceeding with the user's command.

Code Reference

Source Location

  • Repository: Ollama
  • File: cmd/start_windows.go
  • Lines: 1-112

Signature

func startApp(ctx context.Context, client *api.Client) error
func isProcRunning(procName string) []uint32

Import

import "github.com/ollama/ollama/cmd"

I/O Contract

Inputs

Name Type Required Description
ctx context.Context Yes Context for cancellation and timeout
client *api.Client Yes Ollama API client for server readiness check
procName string Yes Process name to search for (e.g., "OllamaSetup.exe")

Outputs

Name Type Description
error error nil on success, error if upgrade in progress or app not found
pids []uint32 List of matching process IDs (for isProcRunning)

Usage Examples

// Check for running installer
if pids := isProcRunning("OllamaSetup.exe"); len(pids) > 0 {
    fmt.Println("Upgrade in progress, please wait...")
    return
}

// Auto-start the Ollama desktop app
err := startApp(ctx, client)
if err != nil {
    fmt.Printf("Failed to start Ollama: %v\n", err)
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment