getIconByProcessName
getIconByProcessName
Info
Retrieves the application icon for a running process by its name. This function searches for a process with the given name in the system process list and extracts the icon from its executable file. Returns an IconResult containing PNG data, or null if the process is not found.
Signature
function getIconByProcessName(processName: string): IconResult | null;Parameters
| Parameter | Type | Description |
|---|---|---|
processName | string | Process name (with or without .exe extension) |
Usage
The getIconByProcessName function is the simplest way to get an application icon when you know the process name. It is part of the Application Icon Helper plugin.
Typical workflow:
- Call
getIconByProcessName('processName')with the target process name. - Check if the result is
null(process not found or no permission). - Use the returned
IconResult(.datacontains the PNG buffer).
Note
The .exe extension is optional. Both 'chrome' and 'chrome.exe' produce the same result.
Tips
The process name is case-insensitive. You can pass either 'explorer' or 'Explorer' — both work.
Return Value
| Type | Description |
|---|---|
IconResult | null | Icon result object, or null if process not found |
Returns an IconResult object containing PNG icon data, size, and format. Returns null if the process is not found or inaccessible.
Warning
This function only works for processes you have permission to access. System processes (e.g., csrss, lsass) may return null due to access restrictions.
Example
import { getIconByProcessName } from '@eisland/windows-application-icon-helper';
// Get icon for Windows Explorer
const result = getIconByProcessName('explorer');
if (result) {
console.log(`Explorer icon: ${result.size} bytes`);
// Convert to data URL for display in HTML
const dataUrl = `data:image/png;base64,${result.data.toString('base64')}`;
} else {
console.log('Process not found or inaccessible');
}
// Also works with .exe extension
const result2 = getIconByProcessName('chrome.exe');
// Returns null for non-running processes
const result3 = getIconByProcessName('nonexistent');const { getIconByProcessName } = require('@eisland/windows-application-icon-helper');
// Get icon for Windows Explorer
const result = getIconByProcessName('explorer');
if (result) {
console.log(`Explorer icon: ${result.size} bytes`);
// Convert to data URL for display in HTML
const dataUrl = `data:image/png;base64,${result.data.toString('base64')}`;
} else {
console.log('Process not found or inaccessible');
}
// Also works with .exe extension
const result2 = getIconByProcessName('chrome.exe');
// Returns null for non-running processes
const result3 = getIconByProcessName('nonexistent');Notes
Note
The process must be currently running. This function does not look up installed applications — only active processes in the system process list.
Tips
If you have the process ID (PID) instead of the name, use getIconByPid for direct lookup without iterating the process list.
Important
For the best performance when you already know the executable path, use getIconByPath instead. It avoids the process enumeration step.
Danger Avoidance
Caution
Do not call getIconByProcessName in a tight loop for the same process. The function enumerates processes each time, which is expensive. Cache the result if you need to use it multiple times.
Changelog
4f6b6-on

