private static bool InformInstallerInitiator( string installStatus, uint timeout = 0) // Informs the user who ran Setup.exe about the overall // success or failure of the 'InstallAgent' // Returns 'true' if the user was successfully informed; // 'false' otherwise { string text = Branding.GetString("BRANDING_managementName"); if (installStatus.Equals("Installed")) { text += " installed successfully"; } else if (installStatus.Equals("Failed")) { text += " failed to install"; } else { throw new Exception( "InstallStatus: \'" + installStatus + "\' not supported" ); } string caption = Branding.GetString("BRANDING_manufacturer") + " " + Branding.GetString("BRANDING_hypervisorProduct") + " " + Branding.GetString("BRANDING_managementName") + " " + "Setup"; string sid = GetInstallerInitiatorSid(); WtsApi32.ID resp; WtsApi32.WTS_SESSION_INFO[] sessions = Helpers.GetWTSSessions( WtsApi32.WTS_CURRENT_SERVER_HANDLE ); foreach (WtsApi32.WTS_SESSION_INFO si in sessions) { if (si.State == WtsApi32.WTS_CONNECTSTATE_CLASS.WTSActive && sid.Equals(Helpers.GetUserSidFromSessionId(si.SessionID))) { if (!WtsApi32.WTSSendMessage( WtsApi32.WTS_CURRENT_SERVER_HANDLE, si.SessionID, caption, (uint)caption.Length * sizeof(Char), text, (uint)text.Length * sizeof(Char), WtsApi32.MB.OK | WtsApi32.MB.ICONINFORMATION, timeout, out resp, false)) { Win32Error.Set("WTSSendMessage"); throw new Exception(Win32Error.GetFullErrMsg()); } return(true); } } return(false); }
private static bool InformInstallerInitiator(uint timeout = 0) // Informs the user who ran Setup.exe about the overall // success or failure of the 'InstallAgent' // Returns 'true' if the user was successfully informed; // 'false' otherwise { string text = Branding.GetString("BRANDING_managementName"); if (installStatus == InstallStatus.Installed) { text = text + " " + Branding.GetString("BRANDING_installSuccess"); } else if (installStatus == InstallStatus.Failed) { text = text + " " + Branding.GetString("BRANDING_installFailed"); } else { throw new Exception( "InstallStatus: \'" + installStatus + "\' " + Branding.GetString("BRANDING_notSupport") ); } string caption = Branding.GetString("BRANDING_manufacturer") + " " + Branding.GetString("BRANDING_hypervisorProduct") + " " + Branding.GetString("BRANDING_managementName") + " " + Branding.GetString("BRANDING_setupString"); string sid = GetInstallerInitiatorSid(); WtsApi32.ID resp; WtsApi32.WTS_SESSION_INFO[] sessions = Helpers.GetWTSSessions( WtsApi32.WTS_CURRENT_SERVER_HANDLE ); foreach (WtsApi32.WTS_SESSION_INFO si in sessions) { bool equalSessionId; try { equalSessionId = (si.State == WtsApi32.WTS_CONNECTSTATE_CLASS.WTSActive && sid.Equals(Helpers.GetUserSidFromSessionId(si.SessionID))); } catch (Exception e) { Trace.WriteLine("Unknown user for session id " + si.SessionID.ToString() + " " + e.ToString()); continue; } if (equalSessionId) { if (!WtsApi32.WTSSendMessage( WtsApi32.WTS_CURRENT_SERVER_HANDLE, si.SessionID, caption, (uint)caption.Length * sizeof(Char), text, (uint)text.Length * sizeof(Char), WtsApi32.MB.OK | WtsApi32.MB.ICONINFORMATION, timeout, out resp, false)) { Win32Error.Set("WTSSendMessage"); throw new Exception(Win32Error.GetFullErrMsg()); } return(true); } } return(false); }