mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 04:55:39 +02:00
capture to db: use powershell command instead of deprecated wmic.exe
This commit is contained in:
parent
472b12ba3a
commit
bfb2a57881
2 changed files with 32 additions and 9 deletions
|
@ -1237,6 +1237,7 @@ namespace PersistentWindows.Common
|
|||
try
|
||||
{
|
||||
processName = process.ProcessName;
|
||||
if (!windowProcessName.ContainsKey(hwnd))
|
||||
windowProcessName.Add(hwnd, processName);
|
||||
}
|
||||
catch(Exception ex)
|
||||
|
@ -2275,6 +2276,8 @@ namespace PersistentWindows.Common
|
|||
Log.Error(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
processCmd.Clear();
|
||||
}
|
||||
}
|
||||
else if (!userMovePrev && !immediateCapture && pendingEventCnt > MinWindowOsMoveEvents)
|
||||
|
|
|
@ -30,6 +30,11 @@ namespace PersistentWindows.SystrayShell
|
|||
static bool notification = false; //pop balloon when auto restore
|
||||
static int delay_manual_capture = 5000; //in millisecond
|
||||
|
||||
// capture to db
|
||||
static uint pid = 0;
|
||||
static string commandline;
|
||||
static int lineno = 0;
|
||||
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
@ -587,9 +592,13 @@ namespace PersistentWindows.SystrayShell
|
|||
static void GetProcessInfo()
|
||||
{
|
||||
Process process = new Process();
|
||||
/*
|
||||
process.StartInfo.FileName = "wmic.exe";
|
||||
//process.StartInfo.Arguments = "process get caption,commandline,processid /format:csv";
|
||||
process.StartInfo.Arguments = "process get commandline,processid /format:csv";
|
||||
*/
|
||||
process.StartInfo.FileName = "powershell.exe";
|
||||
process.StartInfo.Arguments = "get-ciminstance win32_process | select processid,commandline | format-list";
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.RedirectStandardError = false;
|
||||
|
@ -602,25 +611,36 @@ namespace PersistentWindows.SystrayShell
|
|||
process.BeginOutputReadLine();
|
||||
//process.BeginErrorReadLine();
|
||||
process.WaitForExit();
|
||||
|
||||
pid = 0;
|
||||
lineno = 0;
|
||||
}
|
||||
|
||||
static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
|
||||
{
|
||||
//* Do your stuff with the output (write to console/log/StringBuilder)
|
||||
string line = outLine.Data;
|
||||
lineno++;
|
||||
|
||||
if (string.IsNullOrEmpty(line))
|
||||
return;
|
||||
string[] fields = line.Split(',');
|
||||
if (fields.Length < 3)
|
||||
return;
|
||||
uint processId;
|
||||
if (uint.TryParse(fields[2], out processId))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(fields[1]))
|
||||
if (pid != 0)
|
||||
{
|
||||
pwp.processCmd[processId] = fields[1];
|
||||
pwp.processCmd[pid] = commandline;
|
||||
}
|
||||
}
|
||||
else if (line.StartsWith("processid"))
|
||||
{
|
||||
uint.TryParse(line.Split(':')[1], out pid);
|
||||
}
|
||||
else if (line.StartsWith("commandline"))
|
||||
{
|
||||
commandline = line.Substring(14);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandline += line.Substring(14);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogError(string format, params object[] args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue