46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using File_Watcher.Models;
|
|
using System.Diagnostics;
|
|
|
|
namespace File_Watcher.Helpers;
|
|
|
|
internal static partial class HelperInfinityQS
|
|
{
|
|
|
|
private static void KillExisting(string processName)
|
|
{
|
|
Process[] processes = Process.GetProcessesByName(processName);
|
|
foreach (Process process in processes)
|
|
{
|
|
try
|
|
{ process.Kill(); }
|
|
catch (Exception) { }
|
|
}
|
|
}
|
|
|
|
private static void RunMI(string decryptedPassword)
|
|
{
|
|
#pragma warning disable CA1416
|
|
string processName = "iispcmi.exe";
|
|
KillExisting(processName);
|
|
ProcessStartInfo processStartInfo = new(processName)
|
|
{
|
|
Domain = "Infineon",
|
|
UseShellExecute = false,
|
|
UserName = "ecfisysadmin",
|
|
PasswordInClearText = decryptedPassword,
|
|
WorkingDirectory = "C:/Program Files (x86)/InfinityQS International/ProFicient/Applications"
|
|
};
|
|
TimeSpan timeSpan = new(DateTime.Now.AddDays(7).Ticks - DateTime.Now.Ticks);
|
|
Process process = Process.Start(processStartInfo) ?? throw new NullReferenceException(nameof(Process));
|
|
_ = process.WaitForExit((int)timeSpan.TotalMilliseconds);
|
|
#pragma warning restore CA1416
|
|
}
|
|
|
|
internal static bool ProcessStart(AppSettings appSettings, ILogger<Worker> logger)
|
|
{
|
|
logger.LogInformation(appSettings.FileWatcherConfiguration.Company);
|
|
string decrypted = RijndaelEncryption.Decrypt(appSettings.InfinityQSConfiguration.EncryptedPassword, appSettings.FileWatcherConfiguration.Company);
|
|
RunMI(decrypted);
|
|
return true;
|
|
}
|
|
} |