computer-vitals 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +167 -2
- package/package.json +48 -4
- package/src/data/os-support.json +33 -0
- package/src/index.js +160 -0
- package/src/lib/apps.js +211 -0
- package/src/lib/diagnose.js +287 -0
- package/src/lib/disk.js +346 -0
- package/src/lib/gather.js +358 -0
- package/src/lib/parse.js +328 -0
- package/src/lib/report.js +70 -0
- package/src/lib/run.js +79 -0
- package/src/lib/safety.js +445 -0
- package/src/lib/startup.js +255 -0
- package/src/lib/text.js +16 -0
- package/src/lib/units.js +16 -0
- package/src/lib/win.js +40 -0
- package/src/win/computer.ps1 +95 -0
- package/src/win/folders.ps1 +29 -0
- package/src/win/safety.ps1 +64 -0
- package/src/win/startup.ps1 +54 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// check_startup: what starts by itself with the computer. Read-only: it lists, it never turns
|
|
2
|
+
// anything on or off. Only program names are reported, never full command lines or file paths.
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
import { readText } from "./run.js";
|
|
8
|
+
import { runWinScript, arr } from "./win.js";
|
|
9
|
+
import { parseDesktopEntry } from "./parse.js";
|
|
10
|
+
import { cleanText } from "./text.js";
|
|
11
|
+
|
|
12
|
+
const PLATFORM = process.platform;
|
|
13
|
+
|
|
14
|
+
const ADVICE = {
|
|
15
|
+
keep: "Part of the system or a hardware driver. Leave it on.",
|
|
16
|
+
security: "Security software. Leave it on.",
|
|
17
|
+
sync: "Keeps cloud files in sync. Turn it off only if you do not use it.",
|
|
18
|
+
updater: "Checks for updates to that program. Fine to leave on; turning it off means updating by hand.",
|
|
19
|
+
optional: "Only needed if you want it running all the time. Safe to turn off: it still works when you open it yourself.",
|
|
20
|
+
vpn: "Keeps a VPN ready. Leave it on if you use that VPN.",
|
|
21
|
+
work: "Installed by a workplace or school to manage this computer. Leave it on.",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// [pattern matched against a lower-case name, display name, advice]
|
|
25
|
+
const KNOWN = [
|
|
26
|
+
[/^securityhealth/, "Windows Security icon", "keep"],
|
|
27
|
+
[/^rtkaud|realtek/, "Realtek audio (sound driver)", "keep"],
|
|
28
|
+
[/^rtk|^igfx|^nvidia|^nvbackend|^amd|radeon|^intel|synaptics|^elan|dolby|^waves|conexant|displaylink|logitech|^logi|wacom/, null, "keep"],
|
|
29
|
+
[/^onedrive(setup)?$/, "OneDrive", "sync"],
|
|
30
|
+
[/dropbox/, "Dropbox", "sync"],
|
|
31
|
+
[/googledrive|google drive/, "Google Drive", "sync"],
|
|
32
|
+
[/icloud/, "iCloud", "sync"],
|
|
33
|
+
[/^googlechromeautolaunch/, "Google Chrome, starting in the background", "optional"],
|
|
34
|
+
[/^microsoftedgeautolaunch/, "Microsoft Edge, starting in the background", "optional"],
|
|
35
|
+
[/keystone|googleupdater|google software update/, "Google updater for Chrome", "updater"],
|
|
36
|
+
[/edgeupdate/, "Microsoft Edge updater", "updater"],
|
|
37
|
+
[/microsoft\.?(auto)?update|autoupdate\.helper|msupdate/, "Microsoft AutoUpdate for Office", "updater"],
|
|
38
|
+
[/adobe|acrotray|creative cloud/, "Adobe software", "updater"],
|
|
39
|
+
[/teams/, "Microsoft Teams", "optional"],
|
|
40
|
+
[/yourphone|phone link|crossdevice/, "Phone Link", "optional"],
|
|
41
|
+
[/copilot/, "Copilot", "optional"],
|
|
42
|
+
[/skype/, "Skype", "optional"],
|
|
43
|
+
[/spotify/, "Spotify", "optional"],
|
|
44
|
+
[/discord/, "Discord", "optional"],
|
|
45
|
+
[/^steam|valvesoftware/, "Steam", "optional"],
|
|
46
|
+
[/epicgames/, "Epic Games Launcher", "optional"],
|
|
47
|
+
[/^eadm$|^eadesktop|electronic arts/, "EA app", "optional"],
|
|
48
|
+
[/battle\.net/, "Battle.net", "optional"],
|
|
49
|
+
[/gamingapp|xbox/, "Xbox app", "optional"],
|
|
50
|
+
[/zoom/, "Zoom", "optional"],
|
|
51
|
+
[/slack/, "Slack", "optional"],
|
|
52
|
+
[/windowsterminal/, "Windows Terminal", "optional"],
|
|
53
|
+
[/microsoftofficehub|officehub/, "Microsoft 365 app", "optional"],
|
|
54
|
+
[/itunes|apple.?mobile/, "Apple device helper", "optional"],
|
|
55
|
+
[/docker/, "Docker", "optional"],
|
|
56
|
+
[/ollama/, "Ollama", "optional"],
|
|
57
|
+
[/claude/, "Claude", "optional"],
|
|
58
|
+
[/lenovo|vantage|supportassist|^(hp|dell|asus|acer|msi|samsung)/, null, "optional"],
|
|
59
|
+
[/mcafee|norton|avast|avg|kaspersky|bitdefender|malwarebytes|eset|sophos|sentinel|crowdstrike|defender/, null, "security"],
|
|
60
|
+
[/mullvad|nordvpn|expressvpn|proton|tailscale|wireguard|anyconnect|secureclient|globalprotect|paloalto|forticlient|openvpn/, null, "vpn"],
|
|
61
|
+
[/jamf|intune|kandji|mosyle|addigy|munki/, null, "work"],
|
|
62
|
+
[/brother|epson|canon|^hp\b|printer/, null, "optional"],
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const camelWords = (s) => s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_.]+/g, " ").replace(/\s+/g, " ").trim();
|
|
66
|
+
// "LenovoVantageToolbar" -> "Lenovo Vantage Toolbar", but "iTunesHelper" keeps its "iTunes".
|
|
67
|
+
const splitCaps = (s) => (/\s/.test(s) ? s : s.replace(/([a-z]{3,})([A-Z])/g, "$1 $2"));
|
|
68
|
+
|
|
69
|
+
/** Startup items a person could reasonably switch off (everything except system parts and security software). */
|
|
70
|
+
export const optionalCount = (items) => (items || []).filter((x) => x.enabled && x.advice !== "keep" && x.advice !== "security" && x.advice !== "work").length;
|
|
71
|
+
|
|
72
|
+
/** A display name and advice for one startup entry. */
|
|
73
|
+
export function describe(rawName) {
|
|
74
|
+
const cleaned = cleanText(
|
|
75
|
+
String(rawName || "")
|
|
76
|
+
.replace(/_[0-9A-F]{16,}$/i, "")
|
|
77
|
+
.replace(/\.(lnk|exe|desktop|plist)$/i, ""),
|
|
78
|
+
60,
|
|
79
|
+
);
|
|
80
|
+
const key = cleaned.toLowerCase();
|
|
81
|
+
for (const [re, title, advice] of KNOWN) if (re.test(key)) return { name: title || splitCaps(cleaned), advice, titled: Boolean(title) };
|
|
82
|
+
return { name: splitCaps(cleaned) || "unnamed", advice: null, titled: false };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---------- Windows ---------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
const offByte = (b) => Number.isFinite(b) && (b & 1) === 1;
|
|
88
|
+
|
|
89
|
+
/** The JSON from src/win/startup.ps1 -> a list of startup items. */
|
|
90
|
+
export function normalizeWinStartup(j) {
|
|
91
|
+
if (!j || (j.commands === null && j.tasks === null)) return { readable: false, items: [], limits: [] };
|
|
92
|
+
const approved = j.approved && typeof j.approved === "object" ? j.approved : {};
|
|
93
|
+
const state = (name) => {
|
|
94
|
+
for (const k of Object.keys(approved)) if (k.toLowerCase() === name.toLowerCase() || k.toLowerCase() === `${name.toLowerCase()}.lnk`) return approved[k];
|
|
95
|
+
return undefined;
|
|
96
|
+
};
|
|
97
|
+
const seen = new Map();
|
|
98
|
+
for (const c of arr(j.commands)) {
|
|
99
|
+
if (!c || c.kind === "other" || c.kind === "system") continue; // other people's accounts, and Windows' own service accounts
|
|
100
|
+
const d = describe(c.name || c.exe);
|
|
101
|
+
const enabled = !offByte(state(String(c.name || "")));
|
|
102
|
+
const prev = seen.get(d.name);
|
|
103
|
+
if (!prev) seen.set(d.name, { name: d.name, advice: d.advice, enabled, scope: c.kind === "all" ? "everyone" : "you" });
|
|
104
|
+
else prev.enabled = prev.enabled || enabled;
|
|
105
|
+
}
|
|
106
|
+
for (const t of arr(j.tasks)) {
|
|
107
|
+
if (!t?.pkg) continue;
|
|
108
|
+
const base = String(t.pkg).replace(/_[a-z0-9]{13}$/i, "");
|
|
109
|
+
const short = base.includes(".") ? base.slice(base.lastIndexOf(".") + 1) : base;
|
|
110
|
+
const d = describe(short);
|
|
111
|
+
const name = d.titled ? d.name : camelWords(short);
|
|
112
|
+
const enabled = t.state === 2 || t.state === 4;
|
|
113
|
+
const prev = seen.get(name);
|
|
114
|
+
if (!prev) seen.set(name, { name, advice: d.advice, enabled, scope: "you" });
|
|
115
|
+
else prev.enabled = prev.enabled || enabled;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
readable: true,
|
|
119
|
+
items: [...seen.values()],
|
|
120
|
+
limits: ["Windows services and scheduled tasks also start in the background. They are not listed here."],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ---------- macOS ---------------------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
/** File names in the LaunchAgents and LaunchDaemons folders -> grouped startup items. Apple's own are skipped. */
|
|
127
|
+
export function normalizeMacStartup(dirs) {
|
|
128
|
+
const groups = new Map();
|
|
129
|
+
let readable = false;
|
|
130
|
+
for (const { files, scope } of dirs) {
|
|
131
|
+
if (!files) continue;
|
|
132
|
+
readable = true;
|
|
133
|
+
for (const f of files) {
|
|
134
|
+
if (!f.endsWith(".plist") || f.startsWith("com.apple.") || f.startsWith(".")) continue;
|
|
135
|
+
const label = f.slice(0, -".plist".length);
|
|
136
|
+
const words = label.split(".");
|
|
137
|
+
const brew = /^homebrew\.mxcl\.(.+)$/.exec(label);
|
|
138
|
+
// Labels read "com.maker.product"; the part after the first dot is what the patterns look at.
|
|
139
|
+
const d = describe(brew ? brew[1] : words.slice(1).join(".") || label);
|
|
140
|
+
const maker = words.length > 1 ? words[1].charAt(0).toUpperCase() + words[1].slice(1) : label;
|
|
141
|
+
let name = d.name;
|
|
142
|
+
if (brew) name = `${d.name} (installed with Homebrew)`;
|
|
143
|
+
else if (!d.titled && d.advice) name = maker; // a known kind of software: group it under its maker
|
|
144
|
+
else if (!d.titled) name = words.slice(1).join(" ") || label; // unknown: maker and product words
|
|
145
|
+
const g = groups.get(name) || { name, advice: d.advice, enabled: true, scope, parts: 0 };
|
|
146
|
+
g.parts += 1;
|
|
147
|
+
if (scope === "everyone") g.scope = "everyone";
|
|
148
|
+
groups.set(name, g);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
readable,
|
|
153
|
+
items: [...groups.values()],
|
|
154
|
+
limits: [
|
|
155
|
+
"Apps you chose under \"Open at Login\" are not listed: macOS does not let other programs read that list without asking you. Look in System Settings > General > Login Items & Extensions.",
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function macStartup() {
|
|
161
|
+
const list = (dir) => {
|
|
162
|
+
try {
|
|
163
|
+
return fs.readdirSync(dir);
|
|
164
|
+
} catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return normalizeMacStartup([
|
|
169
|
+
{ files: list("/Library/LaunchAgents"), scope: "everyone" },
|
|
170
|
+
{ files: list("/Library/LaunchDaemons"), scope: "everyone" },
|
|
171
|
+
{ files: list(path.join(os.homedir(), "Library/LaunchAgents")), scope: "you" },
|
|
172
|
+
]);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ---------- Linux -------------------------------------------------------------------------------
|
|
176
|
+
|
|
177
|
+
function linuxStartup() {
|
|
178
|
+
const items = [];
|
|
179
|
+
let readable = false;
|
|
180
|
+
let systemParts = 0;
|
|
181
|
+
const userDir = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config"), "autostart");
|
|
182
|
+
const read = (dir) => {
|
|
183
|
+
try {
|
|
184
|
+
return fs.readdirSync(dir).filter((f) => f.endsWith(".desktop"));
|
|
185
|
+
} catch {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const user = read(userDir);
|
|
190
|
+
if (user) {
|
|
191
|
+
readable = true;
|
|
192
|
+
for (const f of user) {
|
|
193
|
+
const e = parseDesktopEntry(readText(path.join(userDir, f)));
|
|
194
|
+
const d = describe(e.name || f);
|
|
195
|
+
items.push({ name: d.name, advice: d.advice, enabled: e.enabled, scope: "you" });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const system = read("/etc/xdg/autostart");
|
|
199
|
+
if (system) {
|
|
200
|
+
readable = true;
|
|
201
|
+
systemParts = system.length;
|
|
202
|
+
}
|
|
203
|
+
const limits = ["Background services managed by systemd are not listed."];
|
|
204
|
+
if (systemParts) limits.unshift(`${systemParts} standard parts of the desktop also start at login. They are part of the system and are not listed.`);
|
|
205
|
+
return { readable, items, limits };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ---------- gather and report -------------------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
export async function gatherStartup() {
|
|
211
|
+
if (PLATFORM === "win32") return { platform: PLATFORM, ...normalizeWinStartup(await runWinScript("startup")) };
|
|
212
|
+
if (PLATFORM === "darwin") return { platform: PLATFORM, ...macStartup() };
|
|
213
|
+
if (PLATFORM === "linux") return { platform: PLATFORM, ...linuxStartup() };
|
|
214
|
+
return { platform: PLATFORM, readable: false, items: [], limits: [] };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const HOW_OFF = {
|
|
218
|
+
win32: "Open Settings > Apps > Startup and switch off the ones you do not need. (Or press Ctrl+Shift+Esc and open \"Startup apps\".)",
|
|
219
|
+
darwin: "Open System Settings > General > Login Items & Extensions. Remove apps from \"Open at Login\", and switch off background items you do not need.",
|
|
220
|
+
linux: "Open the \"Startup Applications\" app (or your desktop's settings for startup programs) and untick the ones you do not need.",
|
|
221
|
+
};
|
|
222
|
+
export const MANY_STARTUP = { win32: 10, darwin: 15, linux: 10 };
|
|
223
|
+
|
|
224
|
+
export function renderStartup(s) {
|
|
225
|
+
const head = "Computer Vitals: startup check";
|
|
226
|
+
if (!s.readable) return `${head}\n\nI could not read the list of startup programs on this computer.\n\n${HOW_OFF[s.platform] ? `To look yourself: ${HOW_OFF[s.platform]}` : ""}`.trim();
|
|
227
|
+
const on = s.items.filter((x) => x.enabled).sort((a, b) => a.name.localeCompare(b.name));
|
|
228
|
+
const off = s.items.filter((x) => !x.enabled);
|
|
229
|
+
const lines = [head, ""];
|
|
230
|
+
const one = on.length === 1;
|
|
231
|
+
const what = s.platform === "darwin" ? (one ? "background helper installed by an app starts by itself" : "background helpers installed by apps start by themselves") : `program${one ? "" : "s"} start${one ? "s" : ""} by ${one ? "itself" : "themselves"} when you sign in`;
|
|
232
|
+
lines.push(`${on.length === 0 ? "No" : on.length} ${what}.${off.length ? ` ${off.length} more ${off.length === 1 ? "is" : "are"} turned off.` : ""}`);
|
|
233
|
+
if (on.length) {
|
|
234
|
+
lines.push("", "Starts by itself");
|
|
235
|
+
for (const x of on) {
|
|
236
|
+
const parts = x.parts > 1 ? ` (${x.parts} background parts)` : "";
|
|
237
|
+
lines.push(`- ${x.name}${parts}${x.advice ? `: ${ADVICE[x.advice]}` : ""}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
lines.push("", "What this means");
|
|
241
|
+
const many = MANY_STARTUP[s.platform] ?? 10;
|
|
242
|
+
const optional = optionalCount(s.items);
|
|
243
|
+
const could = optional === 1 ? "1 of them is something you could turn off" : `${optional} of them are things you could turn off`;
|
|
244
|
+
if (optional >= many) lines.push(`That is a lot. Each one makes the computer take longer to be ready after you sign in, and keeps using memory afterwards. ${could}.`);
|
|
245
|
+
else if (on.length) lines.push(`That is a normal amount. Each one adds a little to how long the computer takes to be ready after you sign in.${optional ? ` ${could} if you do not need them running all the time.` : ""}`);
|
|
246
|
+
else lines.push("Nothing extra is slowing down sign-in.");
|
|
247
|
+
lines.push("Turning a program off here does not remove it. It only stops it from starting by itself.");
|
|
248
|
+
if (HOW_OFF[s.platform]) lines.push("", "How to turn one off", HOW_OFF[s.platform]);
|
|
249
|
+
if (s.limits?.length) {
|
|
250
|
+
lines.push("", "What I can't see");
|
|
251
|
+
for (const l of s.limits) lines.push(`- ${l}`);
|
|
252
|
+
}
|
|
253
|
+
lines.push("", "Nothing was changed.");
|
|
254
|
+
return lines.join("\n");
|
|
255
|
+
}
|
package/src/lib/text.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Program names, file names and product names come from this computer's files and from whatever
|
|
2
|
+
// is installed or downloaded on it, and they end up in a report that an AI assistant reads. They
|
|
3
|
+
// are kept short and on one line, so a file or a program cannot smuggle a paragraph of
|
|
4
|
+
// "instructions" into the report through its name.
|
|
5
|
+
|
|
6
|
+
// Control characters, line and paragraph separators, zero-width and text-direction marks.
|
|
7
|
+
const INVISIBLE = /[\u0000-\u001f\u007f-\u009f\u00ad\u200b-\u200f\u2028-\u202f\u2060-\u206f\ufeff]/g;
|
|
8
|
+
|
|
9
|
+
/** One line of plain text, trimmed and cut to `max` characters. Never returns null. */
|
|
10
|
+
export function cleanText(value, max = 64) {
|
|
11
|
+
const s = String(value ?? "")
|
|
12
|
+
.replace(INVISIBLE, " ")
|
|
13
|
+
.replace(/\s+/g, " ")
|
|
14
|
+
.trim();
|
|
15
|
+
return s.length > max ? `${s.slice(0, max - 1).trimEnd()}\u2026` : s;
|
|
16
|
+
}
|
package/src/lib/units.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Sizes in the units each system shows its own users, so the numbers match what they see.
|
|
2
|
+
// Memory is always counted in steps of 1024 ("16 GB of memory"). Disk space is counted in steps
|
|
3
|
+
// of 1024 on Windows and steps of 1000 on macOS and Linux, the same as Explorer, Finder and Files.
|
|
4
|
+
|
|
5
|
+
function format(bytes, k) {
|
|
6
|
+
if (bytes === null || bytes === undefined || !Number.isFinite(bytes)) return "?";
|
|
7
|
+
const gb = bytes / k ** 3;
|
|
8
|
+
if (gb >= 100) return `${Math.round(gb)} GB`;
|
|
9
|
+
if (gb >= 1) return `${Math.round(gb * 10) / 10} GB`;
|
|
10
|
+
const mb = bytes / k ** 2;
|
|
11
|
+
if (mb >= 1) return `${Math.round(mb)} MB`;
|
|
12
|
+
return bytes > 0 ? "under 1 MB" : "0 MB";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const memSize = (bytes) => format(bytes, 1024);
|
|
16
|
+
export const diskSize = (bytes, platform = process.platform) => format(bytes, platform === "win32" ? 1024 : 1000);
|
package/src/lib/win.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Windows facts come from a few fixed PowerShell scripts in src/win/. Each one only reads, takes
|
|
2
|
+
// no input, and prints one line of JSON, so the same code works in every display language.
|
|
3
|
+
//
|
|
4
|
+
// A script is handed to PowerShell as plain text (-Command), where anyone can read it in the
|
|
5
|
+
// process list, not as an encoded blob. That is why the scripts contain no double quotes: with
|
|
6
|
+
// none in the text, Windows passes it through unchanged. A test checks this.
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
|
|
9
|
+
import { run } from "./run.js";
|
|
10
|
+
|
|
11
|
+
const texts = new Map();
|
|
12
|
+
|
|
13
|
+
export function winScript(name) {
|
|
14
|
+
if (!texts.has(name)) texts.set(name, fs.readFileSync(new URL(`../win/${name}.ps1`, import.meta.url), "utf8"));
|
|
15
|
+
return texts.get(name);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The JSON object a script printed, or null when PowerShell is missing, failed or printed something else. */
|
|
19
|
+
export function parseWinJson(text) {
|
|
20
|
+
const line = String(text || "")
|
|
21
|
+
.split(/\r?\n/)
|
|
22
|
+
.map((l) => l.trim())
|
|
23
|
+
.reverse()
|
|
24
|
+
.find((l) => l.startsWith("{") && l.endsWith("}"));
|
|
25
|
+
if (!line) return null;
|
|
26
|
+
try {
|
|
27
|
+
const v = JSON.parse(line);
|
|
28
|
+
return v && typeof v === "object" ? v : null;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function runWinScript(name, { timeoutMs = 30000 } = {}) {
|
|
35
|
+
const r = await run("powershell", ["-NoProfile", "-NonInteractive", "-Command", winScript(name)], { timeoutMs });
|
|
36
|
+
return parseWinJson(r.stdout);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** PowerShell prints a one-item list as the item itself; this always gives a list back. */
|
|
40
|
+
export const arr = (x) => (Array.isArray(x) ? x : x === null || x === undefined ? [] : [x]);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Computer Vitals, facts for check_computer on Windows.
|
|
2
|
+
# Read-only: it asks Windows for numbers and reads a few settings. It changes nothing and
|
|
3
|
+
# takes no input. It prints one line of JSON. This file must not contain double quotes
|
|
4
|
+
# (see src/lib/win.js for why).
|
|
5
|
+
$ErrorActionPreference = 'Stop'
|
|
6
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
7
|
+
$r = @{}
|
|
8
|
+
function Step([string]$name, [scriptblock]$block) { try { $script:r[$name] = & $block } catch { $script:r[$name] = $null } }
|
|
9
|
+
# When WMI refuses or is broken, every WMI question takes seconds to fail, and enough of them run
|
|
10
|
+
# past the time limit, which loses the readings that do work. So ask once, and if WMI does not
|
|
11
|
+
# answer, skip the WMI questions (CimStep) and keep the rest.
|
|
12
|
+
$cim = $true
|
|
13
|
+
try { $null = Get-CimInstance -ClassName Win32_OperatingSystem -Property Caption } catch { $cim = $false }
|
|
14
|
+
$r['wmi'] = $cim
|
|
15
|
+
function CimStep([string]$name, [scriptblock]$block) { if ($script:cim) { Step $name $block } else { $script:r[$name] = $null } }
|
|
16
|
+
|
|
17
|
+
# Two readings of every program's processor time, about 1.5 seconds apart. The gap is filled
|
|
18
|
+
# with the other questions below.
|
|
19
|
+
$pq = 'SELECT Name,IDProcess,PercentProcessorTime,Timestamp_Sys100NS,WorkingSetPrivate FROM Win32_PerfRawData_PerfProc_Process'
|
|
20
|
+
$dq = 'SELECT Name,PercentIdleTime,Timestamp_Sys100NS FROM Win32_PerfRawData_PerfDisk_PhysicalDisk'
|
|
21
|
+
$p1 = @(); $d1 = @()
|
|
22
|
+
if ($cim) { try { $p1 = @(Get-CimInstance -Query $pq) } catch { } }
|
|
23
|
+
if ($cim) { try { $d1 = @(Get-CimInstance -Query $dq) } catch { } }
|
|
24
|
+
$clock = [Diagnostics.Stopwatch]::StartNew()
|
|
25
|
+
|
|
26
|
+
CimStep 'os' {
|
|
27
|
+
$o = Get-CimInstance Win32_OperatingSystem
|
|
28
|
+
@{ caption = [string]$o.Caption; build = [string]$o.BuildNumber; totalKb = [double]$o.TotalVisibleMemorySize; freeKb = [double]$o.FreePhysicalMemory; commitLimitKb = [double]$o.TotalVirtualMemorySize; commitFreeKb = [double]$o.FreeVirtualMemory; boot = $o.LastBootUpTime.ToUniversalTime().ToString('o') }
|
|
29
|
+
}
|
|
30
|
+
CimStep 'model' { [string](Get-CimInstance Win32_ComputerSystem).Model }
|
|
31
|
+
CimStep 'disks' {
|
|
32
|
+
@(Get-CimInstance -Namespace root/Microsoft/Windows/Storage -ClassName MSFT_PhysicalDisk | ForEach-Object { @{ id = [string]$_.DeviceId; media = [int]$_.MediaType; health = [int]$_.HealthStatus; bus = [int]$_.BusType } })
|
|
33
|
+
}
|
|
34
|
+
CimStep 'drives' { @(Get-CimInstance Win32_DiskDrive | ForEach-Object { @{ index = [int]$_.Index; status = [string]$_.Status } }) }
|
|
35
|
+
CimStep 'sysDisk' {
|
|
36
|
+
$ld = Get-CimInstance Win32_LogicalDisk -Filter ('DeviceID=''' + $env:SystemDrive + '''')
|
|
37
|
+
$p = Get-CimAssociatedInstance -InputObject $ld -ResultClassName Win32_DiskPartition | Select-Object -First 1
|
|
38
|
+
[int]$p.DiskIndex
|
|
39
|
+
}
|
|
40
|
+
Step 'restartUpdate' { Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' }
|
|
41
|
+
Step 'restartServicing' { Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending' }
|
|
42
|
+
Step 'fastStartup' { [int](Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power').HiberbootEnabled }
|
|
43
|
+
CimStep 'battery' {
|
|
44
|
+
$b = Get-CimInstance Win32_Battery | Select-Object -First 1
|
|
45
|
+
if ($null -eq $b) { return @{ present = $false } }
|
|
46
|
+
$out = @{ present = $true; percent = [int]$b.EstimatedChargeRemaining; status = [int]$b.BatteryStatus }
|
|
47
|
+
try { $out.full = [double](Get-CimInstance -Namespace root/WMI -ClassName BatteryFullChargedCapacity | Select-Object -First 1).FullChargedCapacity } catch { }
|
|
48
|
+
try { $out.design = [double](Get-CimInstance -Namespace root/WMI -ClassName BatteryStaticData | Select-Object -First 1).DesignedCapacity } catch { }
|
|
49
|
+
try { $out.cycles = [int](Get-CimInstance -Namespace root/WMI -ClassName BatteryCycleCount | Select-Object -First 1).CycleCount } catch { }
|
|
50
|
+
$out
|
|
51
|
+
}
|
|
52
|
+
Step 'power' {
|
|
53
|
+
$p = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes'
|
|
54
|
+
@{ scheme = [string]$p.ActivePowerScheme; overlayAc = [string]$p.ActiveOverlayAcPowerScheme; overlayDc = [string]$p.ActiveOverlayDcPowerScheme }
|
|
55
|
+
}
|
|
56
|
+
Step 'energySaver' {
|
|
57
|
+
$null = [Windows.System.Power.PowerManager, Windows.System.Power, ContentType = WindowsRuntime]
|
|
58
|
+
[string][Windows.System.Power.PowerManager]::EnergySaverStatus
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
$wait = 1500 - $clock.ElapsedMilliseconds
|
|
62
|
+
if ($wait -gt 0) { Start-Sleep -Milliseconds $wait }
|
|
63
|
+
|
|
64
|
+
CimStep 'procs' {
|
|
65
|
+
$p2 = @(Get-CimInstance -Query $pq)
|
|
66
|
+
$prev = @{}
|
|
67
|
+
foreach ($p in $p1) { $prev[[string]$p.IDProcess + '|' + $p.Name] = $p }
|
|
68
|
+
@(foreach ($p in $p2) {
|
|
69
|
+
if ($p.Name -eq '_Total' -or $p.Name -eq 'Idle' -or $p.IDProcess -eq $PID) { continue }
|
|
70
|
+
$o = $prev[[string]$p.IDProcess + '|' + $p.Name]
|
|
71
|
+
$c = 0
|
|
72
|
+
if ($o) {
|
|
73
|
+
$dt = [double]$p.Timestamp_Sys100NS - [double]$o.Timestamp_Sys100NS
|
|
74
|
+
if ($dt -gt 0) { $c = [math]::Round(100 * ([double]$p.PercentProcessorTime - [double]$o.PercentProcessorTime) / $dt, 1) }
|
|
75
|
+
}
|
|
76
|
+
@{ n = [string]$p.Name; c = $c; m = [double]$p.WorkingSetPrivate }
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
CimStep 'diskBusy' {
|
|
80
|
+
$d2 = @(Get-CimInstance -Query $dq)
|
|
81
|
+
$want = '* ' + $env:SystemDrive + '*'
|
|
82
|
+
$a = $d1 | Where-Object { $_.Name -like $want } | Select-Object -First 1
|
|
83
|
+
$b = $d2 | Where-Object { $_.Name -like $want } | Select-Object -First 1
|
|
84
|
+
if ($null -eq $a -or $null -eq $b) {
|
|
85
|
+
$a = $d1 | Where-Object { $_.Name -eq '_Total' } | Select-Object -First 1
|
|
86
|
+
$b = $d2 | Where-Object { $_.Name -eq '_Total' } | Select-Object -First 1
|
|
87
|
+
}
|
|
88
|
+
$dt = [double]$b.Timestamp_Sys100NS - [double]$a.Timestamp_Sys100NS
|
|
89
|
+
if ($dt -le 0) { return $null }
|
|
90
|
+
$busy = 100 * (1 - (([double]$b.PercentIdleTime - [double]$a.PercentIdleTime) / $dt))
|
|
91
|
+
[math]::Round([math]::Max(0, [math]::Min(100, $busy)), 1)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
$json = ConvertTo-Json -InputObject $r -Depth 6 -Compress
|
|
95
|
+
[regex]::Replace($json, '[^\x00-\x7F]', { param($m) '\u{0:x4}' -f [int][char]$m.Value })
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Computer Vitals, where this person's standard folders and drives are on Windows.
|
|
2
|
+
# Read-only. The folder locations are used to measure sizes and are never shown.
|
|
3
|
+
# One line of JSON. No double quotes in this file.
|
|
4
|
+
$ErrorActionPreference = 'Stop'
|
|
5
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
6
|
+
$r = @{}
|
|
7
|
+
function Step([string]$name, [scriptblock]$block) { try { $script:r[$name] = & $block } catch { $script:r[$name] = $null } }
|
|
8
|
+
|
|
9
|
+
Step 'folders' {
|
|
10
|
+
$f = @{}
|
|
11
|
+
$f.documents = [Environment]::GetFolderPath('MyDocuments')
|
|
12
|
+
$f.desktop = [Environment]::GetFolderPath('Desktop')
|
|
13
|
+
$f.pictures = [Environment]::GetFolderPath('MyPictures')
|
|
14
|
+
$f.videos = [Environment]::GetFolderPath('MyVideos')
|
|
15
|
+
$f.music = [Environment]::GetFolderPath('MyMusic')
|
|
16
|
+
$f.profile = [Environment]::GetFolderPath('UserProfile')
|
|
17
|
+
$f.localAppData = [Environment]::GetFolderPath('LocalApplicationData')
|
|
18
|
+
$f.appData = [Environment]::GetFolderPath('ApplicationData')
|
|
19
|
+
$f.temp = [IO.Path]::GetTempPath()
|
|
20
|
+
try { $f.downloads = [string](New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path } catch { }
|
|
21
|
+
$f
|
|
22
|
+
}
|
|
23
|
+
Step 'oneDrive' { @(@($env:OneDrive, $env:OneDriveConsumer, $env:OneDriveCommercial) | Where-Object { $_ } | Select-Object -Unique) }
|
|
24
|
+
Step 'sid' { [string][Security.Principal.WindowsIdentity]::GetCurrent().User.Value }
|
|
25
|
+
Step 'drives' { @(Get-CimInstance Win32_LogicalDisk | Where-Object { $_.DriveType -eq 2 -or $_.DriveType -eq 3 } | ForEach-Object { @{ letter = [string]$_.DeviceID; size = [double]$_.Size; free = [double]$_.FreeSpace; type = [int]$_.DriveType } }) }
|
|
26
|
+
Step 'systemDrive' { [string]$env:SystemDrive }
|
|
27
|
+
|
|
28
|
+
$json = ConvertTo-Json -InputObject $r -Depth 6 -Compress
|
|
29
|
+
[regex]::Replace($json, '[^\x00-\x7F]', { param($m) '\u{0:x4}' -f [int][char]$m.Value })
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Computer Vitals, facts for check_safety on Windows.
|
|
2
|
+
# Read-only: reads security settings. It changes nothing, scans no files and contacts nothing.
|
|
3
|
+
# One line of JSON. No double quotes in this file.
|
|
4
|
+
$ErrorActionPreference = 'Stop'
|
|
5
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
6
|
+
$r = @{}
|
|
7
|
+
function Step([string]$name, [scriptblock]$block) { try { $script:r[$name] = & $block } catch { $script:r[$name] = $null } }
|
|
8
|
+
# When WMI refuses or is broken, every WMI question takes seconds to fail, and enough of them run
|
|
9
|
+
# past the time limit, which loses the readings that do work. So ask once, and if WMI does not
|
|
10
|
+
# answer, skip the WMI questions (CimStep) and keep the rest.
|
|
11
|
+
$cim = $true
|
|
12
|
+
try { $null = Get-CimInstance -ClassName Win32_OperatingSystem -Property Caption } catch { $cim = $false }
|
|
13
|
+
$r['wmi'] = $cim
|
|
14
|
+
function CimStep([string]$name, [scriptblock]$block) { if ($script:cim) { Step $name $block } else { $script:r[$name] = $null } }
|
|
15
|
+
|
|
16
|
+
Step 'firewall' {
|
|
17
|
+
$base = 'HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\'
|
|
18
|
+
@{ domain = [int](Get-ItemProperty ($base + 'DomainProfile')).EnableFirewall; private = [int](Get-ItemProperty ($base + 'StandardProfile')).EnableFirewall; public = [int](Get-ItemProperty ($base + 'PublicProfile')).EnableFirewall }
|
|
19
|
+
}
|
|
20
|
+
CimStep 'firewallProducts' { @(Get-CimInstance -Namespace root/SecurityCenter2 -ClassName FirewallProduct | ForEach-Object { @{ name = [string]$_.displayName; state = [double]$_.productState } }) }
|
|
21
|
+
CimStep 'antivirus' { @(Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntiVirusProduct | ForEach-Object { @{ name = [string]$_.displayName; state = [double]$_.productState } }) }
|
|
22
|
+
CimStep 'defender' {
|
|
23
|
+
$d = Get-CimInstance -Namespace root/Microsoft/Windows/Defender -ClassName MSFT_MpComputerStatus
|
|
24
|
+
@{ enabled = [bool]$d.AntivirusEnabled; realtime = [bool]$d.RealTimeProtectionEnabled; signatureAgeDays = [double]$d.AntivirusSignatureAge }
|
|
25
|
+
}
|
|
26
|
+
Step 'bitlocker' {
|
|
27
|
+
$v = (New-Object -ComObject Shell.Application).NameSpace(17).ParseName($env:SystemDrive).ExtendedProperty('System.Volume.BitLockerProtection')
|
|
28
|
+
if ($null -eq $v) { return $null }
|
|
29
|
+
[int]$v
|
|
30
|
+
}
|
|
31
|
+
Step 'version' {
|
|
32
|
+
$v = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
|
|
33
|
+
@{ display = [string]$v.DisplayVersion; build = [string]$v.CurrentBuild; ubr = [int]$v.UBR; edition = [string]$v.EditionID; type = [string]$v.InstallationType }
|
|
34
|
+
}
|
|
35
|
+
CimStep 'lastUpdate' {
|
|
36
|
+
$d = Get-CimInstance Win32_QuickFixEngineering | Where-Object { $_.InstalledOn } | Sort-Object InstalledOn | Select-Object -Last 1
|
|
37
|
+
if ($null -eq $d) { return $null }
|
|
38
|
+
$d.InstalledOn.ToString('yyyy-MM-dd')
|
|
39
|
+
}
|
|
40
|
+
Step 'pausedUntil' { [string](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' -ErrorAction SilentlyContinue).PauseUpdatesExpiryTime }
|
|
41
|
+
Step 'noAutoUpdate' { [int](Get-ItemProperty 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' -ErrorAction SilentlyContinue).NoAutoUpdate }
|
|
42
|
+
Step 'autoLogon' { [string](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon').AutoAdminLogon }
|
|
43
|
+
Step 'uac' { [int](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System').EnableLUA }
|
|
44
|
+
Step 'remoteDesktop' { [int](Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server').fDenyTSConnections }
|
|
45
|
+
Step 'sshServer' {
|
|
46
|
+
$s = Get-Service -Name sshd -ErrorAction SilentlyContinue
|
|
47
|
+
if ($null -eq $s) { return $false }
|
|
48
|
+
[string]$s.Status -eq 'Running'
|
|
49
|
+
}
|
|
50
|
+
# Folders shared from this computer. Only the count is reported, never their names.
|
|
51
|
+
CimStep 'sharedFolders' { @(Get-CimInstance Win32_Share | Where-Object { $_.Type -eq 0 }).Count }
|
|
52
|
+
CimStep 'networkCategory' { @(Get-CimInstance -Namespace root/StandardCimv2 -ClassName MSFT_NetConnectionProfile | ForEach-Object { [int]$_.NetworkCategory }) }
|
|
53
|
+
CimStep 'laptop' { [bool](Get-CimInstance Win32_Battery | Select-Object -First 1) }
|
|
54
|
+
Step 'backup' {
|
|
55
|
+
$docs = [Environment]::GetFolderPath('MyDocuments')
|
|
56
|
+
$roots = @($env:OneDrive, $env:OneDriveConsumer, $env:OneDriveCommercial) | Where-Object { $_ }
|
|
57
|
+
$inside = $false
|
|
58
|
+
foreach ($x in $roots) { if ($docs.StartsWith($x, [StringComparison]::OrdinalIgnoreCase)) { $inside = $true } }
|
|
59
|
+
$prof = [Environment]::GetFolderPath('UserProfile')
|
|
60
|
+
@{ oneDrive = [bool]$roots; documentsInOneDrive = $inside; dropbox = (Test-Path (Join-Path $prof 'Dropbox')); iCloudDrive = (Test-Path (Join-Path $prof 'iCloudDrive')) }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
$json = ConvertTo-Json -InputObject $r -Depth 6 -Compress
|
|
64
|
+
[regex]::Replace($json, '[^\x00-\x7F]', { param($m) '\u{0:x4}' -f [int][char]$m.Value })
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Computer Vitals, facts for check_startup on Windows.
|
|
2
|
+
# Read-only: lists what Windows starts at sign-in and whether each one is turned on. It prints
|
|
3
|
+
# program names only, never the full command lines. One line of JSON. No double quotes in this file.
|
|
4
|
+
$ErrorActionPreference = 'Stop'
|
|
5
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
6
|
+
$r = @{}
|
|
7
|
+
function Step([string]$name, [scriptblock]$block) { try { $script:r[$name] = & $block } catch { $script:r[$name] = $null } }
|
|
8
|
+
|
|
9
|
+
$me = ''
|
|
10
|
+
try { $me = [Security.Principal.WindowsIdentity]::GetCurrent().User.Value } catch { }
|
|
11
|
+
|
|
12
|
+
Step 'commands' {
|
|
13
|
+
@(Get-CimInstance Win32_StartupCommand | ForEach-Object {
|
|
14
|
+
$loc = [string]$_.Location
|
|
15
|
+
$kind = 'user'
|
|
16
|
+
if ($loc -match '^HKLM' -or $loc -match 'Common Startup') { $kind = 'all' }
|
|
17
|
+
elseif ($loc -match 'S-1-5-(18|19|20)(\\|$)') { $kind = 'system' }
|
|
18
|
+
elseif ($loc -match 'S-1-5-21-' -and $me -and $loc -notmatch [regex]::Escape($me)) { $kind = 'other' }
|
|
19
|
+
$exe = $null
|
|
20
|
+
$m = [regex]::Match([string]$_.Command, '([^\\/]+?)\.exe', 'IgnoreCase')
|
|
21
|
+
if ($m.Success) { $exe = $m.Groups[1].Value }
|
|
22
|
+
@{ name = [string]$_.Name; kind = $kind; exe = $exe }
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
# The on/off switches behind Settings > Apps > Startup. First byte: even = on, odd = off.
|
|
26
|
+
Step 'approved' {
|
|
27
|
+
$out = @{}
|
|
28
|
+
$skip = 'PSPath', 'PSParentPath', 'PSChildName', 'PSDrive', 'PSProvider'
|
|
29
|
+
foreach ($root in 'HKCU:', 'HKLM:') {
|
|
30
|
+
foreach ($leaf in 'Run', 'Run32', 'StartupFolder') {
|
|
31
|
+
$p = Get-ItemProperty -Path ($root + '\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\' + $leaf) -ErrorAction SilentlyContinue
|
|
32
|
+
if ($p) {
|
|
33
|
+
foreach ($v in $p.PSObject.Properties) {
|
|
34
|
+
if ($skip -notcontains $v.Name -and $v.Value -is [byte[]] -and $v.Value.Length -gt 0) { $out[[string]$v.Name] = [int]$v.Value[0] }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
$out
|
|
40
|
+
}
|
|
41
|
+
# Store apps register their own startup tasks. State: 2 or 4 = on, anything else = off.
|
|
42
|
+
Step 'tasks' {
|
|
43
|
+
$base = 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData'
|
|
44
|
+
@(Get-ChildItem -Path $base -ErrorAction SilentlyContinue | ForEach-Object {
|
|
45
|
+
$pkg = [string]$_.PSChildName
|
|
46
|
+
Get-ChildItem -Path $_.PSPath -ErrorAction SilentlyContinue | ForEach-Object {
|
|
47
|
+
$s = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).State
|
|
48
|
+
if ($null -ne $s) { @{ pkg = $pkg; state = [int]$s } }
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
$json = ConvertTo-Json -InputObject $r -Depth 6 -Compress
|
|
54
|
+
[regex]::Replace($json, '[^\x00-\x7F]', { param($m) '\u{0:x4}' -f [int][char]$m.Value })
|