qsu
Version:
qsu is a utility library that contains useful and frequently used functions. Start with your preferred language and the modern development environment.
1 lines • 1.04 kB
JavaScript
import{homedir as r,platform as t,userInfo as o}from"os";import{runCommand as e}from"./runCommand.js";export async function getSid(){const n=t();if("win32"===n){try{const t=await e('REG QUERY "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList" /s');if(!t)throw new Error("Failed to get machine id");const o={};t.split("HKEY_LOCAL_MACHINE\\").forEach(r=>{const t=r.split("\n").map(r=>r.trim()).filter(r=>r);if(t.length>0){const r=t[0].split("\\").pop()||"Unknown",e=t.find(r=>r.startsWith("ProfileImagePath"));e&&(o[r]=e.split(" ").pop()||"Unknown")}});for(let t=0;t<Object.keys(o).length;t+=1){const e=Object.keys(o)[t];if(o[e]===r())return e}}catch(r){if(r instanceof Error)throw new Error(r?.message)}throw new Error("Failed to get machine id")}if("darwin"===n){try{const r=await e(`dsmemberutil getsid -U ${o().username}`);if(r)return r.replace(/\r?\n/g,"")}catch(r){if(r instanceof Error)throw new Error(r?.message)}throw new Error("Failed to get machine id")}throw new Error("Not supported on this operating system.")}