diff --git a/lib/processes.js b/lib/processes.js index a5879a3..4622683 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -69,16 +69,6 @@ const _winStatusValues = { '9': 'growing', }; - -function parseTimeWin(time) { - time = time || ''; - if (time) { - return (time.substr(0, 4) + '-' + time.substr(4, 2) + '-' + time.substr(6, 2) + ' ' + time.substr(8, 2) + ':' + time.substr(10, 2) + ':' + time.substr(12, 2)); - } else { - return ''; - } -} - function parseTimeUnix(time) { let result = time; let parts = time.replace(/ +/g, ' ').split(' '); @@ -823,7 +813,7 @@ function processes(callback) { }); } else if (_windows) { try { - util.powerShell('Get-CimInstance Win32_Process | select ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage,CreationDate | fl').then((stdout, error) => { + util.powerShell('Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | fl').then((stdout, error) => { if (!error) { let processSections = stdout.split(/\n\s*\n/); let procs = []; @@ -882,7 +872,7 @@ function processes(callback) { memVsz: parseInt(util.getValue(lines, 'PageFileUsage', ':', true), 10), memRss: Math.floor(parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10) / 1024), nice: 0, - started: parseTimeWin(util.getValue(lines, 'CreationDate', ':', true)), + started: util.getValue(lines, 'CreationDate', ':', true), state: (!statusValue ? _winStatusValues[0] : _winStatusValues[statusValue]), tty: '', user: '', diff --git a/lib/system.js b/lib/system.js index 6644b99..5774b99 100644 --- a/lib/system.js +++ b/lib/system.js @@ -506,7 +506,7 @@ function bios(callback) { } if (_windows) { try { - util.powerShell('Get-CimInstance Win32_bios | select Description,Version,Manufacturer,ReleaseDate,BuildNumber,SerialNumber | fl').then((stdout, error) => { + util.powerShell('Get-CimInstance Win32_bios | select Description,Version,Manufacturer,@{n="ReleaseDate";e={$_.ReleaseDate.ToString("yyyy-MM-dd")}},BuildNumber,SerialNumber | fl').then((stdout, error) => { if (!error) { let lines = stdout.toString().split('\r\n'); const description = util.getValue(lines, 'description', ':'); @@ -523,9 +523,6 @@ function bios(callback) { result.version = util.getValue(lines, 'version', ':'); } result.releaseDate = util.getValue(lines, 'releasedate', ':'); - if (result.releaseDate.length >= 10) { - result.releaseDate = result.releaseDate.substr(0, 4) + '-' + result.releaseDate.substr(4, 2) + '-' + result.releaseDate.substr(6, 2); - } result.revision = util.getValue(lines, 'buildnumber', ':'); result.serial = util.getValue(lines, 'serialnumber', ':'); } diff --git a/lib/users.js b/lib/users.js index 0b1a508..dc120fc 100644 --- a/lib/users.js +++ b/lib/users.js @@ -207,17 +207,23 @@ function users(callback) { } if (_windows) { try { - let cmd = 'Get-CimInstance Win32_LogonSession | select LogonId,StartTime | fl' + '; echo \'#-#-#-#\';'; + let cmd = 'Get-CimInstance Win32_LogonSession | select LogonId,@{n="StartTime";e={$_.StartTime.ToString("yyyy-MM-dd HH:mm:ss")}} | fl' + '; echo \'#-#-#-#\';'; cmd += 'Get-CimInstance Win32_LoggedOnUser | select antecedent,dependent | fl ' + '; echo \'#-#-#-#\';'; - cmd += 'Get-CimInstance Win32_Process -Filter "name=\'explorer.exe\'" | Select @{Name="sessionid";Expression={$_.SessionId}}, @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl' + '; echo \'#-#-#-#\';'; + // cmd += `Get-CimInstance Win32_Process -Filter 'name="explorer.exe"' | Select @{Name="sessionid";Expression={$_.SessionId}}, @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl` + '; echo \'#-#-#-#\';'; + cmd += '$process = (Get-CimInstance Win32_Process -Filter "name = \'explorer.exe\'"); Invoke-CimMethod -InputObject $process -MethodName GetOwner | select user, domain | fl; get-process -name explorer | select-object sessionid | fl; echo \'# -# -# -#\';'; cmd += 'query user'; util.powerShell(cmd).then((data) => { if (data) { data = data.split('#-#-#-#'); + console.log(data); let sessions = parseWinSessions((data[0] || '').split(/\n\s*\n/)); let loggedons = parseWinLoggedOn((data[1] || '').split(/\n\s*\n/)); let queryUser = parseWinUsersQuery((data[3] || '').split('\r\n')); let users = parseWinUsers((data[2] || '').split(/\n\s*\n/), queryUser); + console.log(sessions); + console.log(loggedons); + console.log(queryUser); + console.log(users); for (let id in loggedons) { if ({}.hasOwnProperty.call(loggedons, id)) { loggedons[id].dateTime = {}.hasOwnProperty.call(sessions, id) ? sessions[id] : ''; @@ -236,8 +242,8 @@ function users(callback) { result.push({ user: user.user, tty: user.tty, - date: `${dateTime.substr(0, 4)}-${dateTime.substr(4, 2)}-${dateTime.substr(6, 2)}`, - time: `${dateTime.substr(8, 2)}:${dateTime.substr(10, 2)}`, + date: `${dateTime.substring(0, 10)}`, + time: `${dateTime.substring(11, 19)}`, ip: '', command: '' }); @@ -247,27 +253,11 @@ function users(callback) { resolve(result); }); - // util.powerShell('query user').then(stdout => { - // if (stdout) { - // // lines / split - // let lines = stdout.toString().split('\r\n'); - // getWinCulture() - // .then(culture => { - // result = parseUsersWin(lines, culture); - // if (callback) { callback(result); } - // resolve(result); - // }); - // } else { - // if (callback) { callback(result); } - // resolve(result); - // } - // }); } catch (e) { if (callback) { callback(result); } resolve(result); } } - }); }); } @@ -317,7 +307,7 @@ function parseWinUsers(userParts, userQuery) { const lines = user.split('\r\n'); const domain = util.getValue(lines, 'domain', ':', true); - const username = util.getValue(lines, 'username', ':', true); + const username = util.getValue(lines, 'user', ':', true); const sessionid = util.getValue(lines, 'sessionid', ':', true); if (username) { @@ -338,14 +328,12 @@ function parseWinLoggedOn(loggedonParts) { const lines = loggedon.split('\r\n'); const antecendent = util.getValue(lines, 'antecedent', ':', true); - let parts = antecendent.split(','); - const domainParts = parts.length > 1 ? parts[0].split('=') : []; - const nameParts = parts.length > 1 ? parts[1].split('=') : []; - const domain = domainParts.length > 1 ? domainParts[1].replace(/"/g, '') : ''; - const name = nameParts.length > 1 ? nameParts[1].replace(/"/g, '') : ''; + let parts = antecendent.split('='); + const name = parts.length > 2 ? parts[1].split(',')[0].replace(/"/g, '').trim() : ''; + const domain = parts.length > 2 ? parts[2].replace(/"/g, '').trim() : ''; const dependent = util.getValue(lines, 'dependent', ':', true); parts = dependent.split('='); - const id = parts.length > 1 ? parts[1].replace(/"/g, '') : ''; + const id = parts.length > 1 ? parts[1].replace(/"/g, '').replace(/\)/g, '').trim() : ''; if (id) { loggedons[id] = { domain, diff --git a/lib/util.js b/lib/util.js index 8ee0a61..4379339 100644 --- a/lib/util.js +++ b/lib/util.js @@ -564,7 +564,7 @@ function getCodepage() { const stdout = execSync('chcp', execOptsWin); const lines = stdout.toString().split('\r\n'); const parts = lines[0].split(':'); - codepage = parts.length > 1 ? parts[1].replace('.', '') : ''; + codepage = parts.length > 1 ? parts[1].replace('.', '').trim() : ''; } catch (err) { codepage = '437'; }