0

我开发了一个启动器,可以在其他公司环境中更新/运行我们的软件。大多数时候,公司批准启动器,但忘记了实际应用程序。

目前我正在使用 Process.Start(procStart) 来启动应用程序,但是如果 applocker 阻止应用程序,那将静默失败。

所以我想知道是否有人可靠的方法来检测 applocker 是否处于活动状态,以及它何时阻止我的应用程序(所以我可以提供正确的错误消息)。

当错误发生时,我的应用程序对用户来说似乎是空闲的,内存转储显示: 在此处输入图像描述

代码注释:没有异常处理或异常抑制。如果启动器崩溃,我希望在事件日志中看到它。

添加代码:

private void StartzzzDesktop(int value)
{            
       var rel = Settings.zzzDesktopStore.GetReleaseInfo(Settings.ConnectionDetails.zzzDesktopID);
        var proc = CreateProccess(rel);
        if (proc == null)
        {
            Settings.LastError = zzzLauncherError.FatelErrorStartzzz;
            Settings.EventManager.TriggerEvent(zzzDesktopStatus.FatalError);
            return;
        }

        Logger.Log(EventLogEntryType.Information, $"Started zzz desktop and got PID {proc.Id} from {rel.GenerateExtrationPath()}");
        Settings.EventManager.TriggerEventSync(zzzDesktopStatus.DeleteOldReleases);
        Settings.EventManager.TriggerEvent(zzzDesktopStatus.ReleaseBackgroundWorkers);
        GC.Collect();

        var remoteStatus = new GetRemotezzzWebStatus();
        while (!proc.HasExited)
        {
            Thread.Sleep(1000);

            if(!remoteStatus.IsRemoteVersionCompatible())
            {
                proc.Kill();
                Logger.Log(EventLogEntryType.Information, $"Detected that the remote website is no longer compatible with current runnign version, and we are killing desktop.");
            }
        }            

        if(proc.ExitCode != 0)
        {
            Settings.zzzDesktopStore.Delete(rel);
            Logger.Log(EventLogEntryType.Warning, $"zzz exited with a none zero exit code ({proc.ExitCode}), the local cached installation will be deleted");
        }
        else
            Logger.Log(EventLogEntryType.Information, $"zzz exited in a normal way with exitcode {proc.ExitCode}, running for {(DateTime.Now - proc.StartTime).ToString()} ");

        CloseDown();
} 

internal Process CreateProccess(zzzDesktopInfo release)
{
        release = GetReleaseInfo(release.ID);
        string pathzzzExe = Path.Combine(release.GenerateExtrationPath(), "zzz.exe");
        var verifyStatus = UtilsVerifyFile.Verify(pathzzzExe);
        if ( !File.Exists(pathzzzExe) || !verifyStatus.Verified)
        {
            Logger.Log(EventLogEntryType.Error, "Found zzz.exe in temp folder, but the certificate did not pass verification");

            foreach (var logentry in verifyStatus.Logs)
                Logger.Log(EventLogEntryType.Error, "Certificate verification log: " + logentry);
            MarkDatabaseForPurge();
            return null;
        }           
    // Removed enterprise spesific code.

        var procStart = new ProcessStartInfo();
        procStart.FileName = pathzzzExe;

        if (Settings.ConnectionDetails.zzzLoginToken != Guid.Empty )
        {
            procStart.Arguments = "/RefreshToken:" + Settings.ConnectionDetails.zzzLoginToken.ToString();
        }

        var process = Process.Start(procStart);
        return process;
}
4

0 回答 0