updaet 20250226
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -50,6 +51,27 @@ namespace OnDoc.Klassen
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetProcessOwner(int processId)
|
||||
{
|
||||
string query = "SELECT * FROM Win32_Process WHERE ProcessID = " + processId;
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
|
||||
ManagementObjectCollection processList = searcher.Get();
|
||||
|
||||
foreach (ManagementObject obj in processList)
|
||||
{
|
||||
string[] argList = new string[] { string.Empty, string.Empty };
|
||||
int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList));
|
||||
|
||||
if (returnVal == 0)
|
||||
{
|
||||
// return DOMAIN\user
|
||||
return argList[1] + "\\" + argList[0];
|
||||
}
|
||||
}
|
||||
searcher = null;
|
||||
|
||||
return "NO OWNER";
|
||||
}
|
||||
private static void WatchProcesses(object source, ElapsedEventArgs e)
|
||||
{
|
||||
bool word = false;
|
||||
@@ -81,26 +103,45 @@ namespace OnDoc.Klassen
|
||||
|
||||
foreach (Process p in localByName)
|
||||
{
|
||||
Logging.Logging.Debug(fc.dokumentid + "/" + p.MainWindowTitle, "", "");
|
||||
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 || p.MainWindowTitle.Trim() == "")
|
||||
|
||||
string owner = GetProcessOwner(p.Id);
|
||||
owner = owner.ToUpper();
|
||||
Logging.Logging.Debug(AppParams.systemtgnummer+"/"+AppParams.currenttgnummer+"/"+owner+"/"+fc.dokumentid + "/" + p.MainWindowTitle, "", "");
|
||||
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 ||
|
||||
(p.MainWindowTitle.Trim() == "" && owner.Contains(AppParams.systemtgnummer.ToUpper())))
|
||||
{
|
||||
if (p.MainWindowTitle.Trim() != "") { fc.Lastfound = DateTime.Now; }
|
||||
found = true;
|
||||
save_to_db(fc);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//foreach (Process p in localByName)
|
||||
//{
|
||||
// Logging.Logging.Debug(fc.dokumentid + "/" + p.MainWindowTitle, "", "");
|
||||
// if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 || p.MainWindowTitle.Trim() == "")
|
||||
|
||||
// {
|
||||
// if (p.MainWindowTitle.Trim() != "") { fc.Lastfound = DateTime.Now; }
|
||||
// found = true;
|
||||
// save_to_db(fc);
|
||||
|
||||
// break;
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
if (excel)
|
||||
{
|
||||
Process[] localByName = Process.GetProcessesByName("EXCEL");
|
||||
foreach (Process p in localByName)
|
||||
{
|
||||
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 || p.MainWindowTitle.Trim() == "")
|
||||
string owner = GetProcessOwner(p.Id);
|
||||
owner = owner.ToUpper();
|
||||
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 ||
|
||||
(p.MainWindowTitle.Trim() == "" && owner.Contains(AppParams.systemtgnummer.ToUpper())))
|
||||
{
|
||||
if (p.MainWindowTitle.Trim() != "") { fc.Lastfound = DateTime.Now; }
|
||||
found = true;
|
||||
@@ -108,6 +149,17 @@ namespace OnDoc.Klassen
|
||||
}
|
||||
|
||||
}
|
||||
//Process[] localByName = Process.GetProcessesByName("EXCEL");
|
||||
//foreach (Process p in localByName)
|
||||
//{
|
||||
// if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 || p.MainWindowTitle.Trim() == "")
|
||||
// {
|
||||
// if (p.MainWindowTitle.Trim() != "") { fc.Lastfound = DateTime.Now; }
|
||||
// found = true;
|
||||
// save_to_db(fc);
|
||||
// }
|
||||
|
||||
//}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user