// Method which contains our custom action behaviour private static void RunSTAThread(object sessionObject) { try { Session session = sessionObject as Session; string powerShellShortcutPath = session.CustomActionData["ShortcutPath"]; string powerShellDefaultShortcutPath = session.CustomActionData["DefaultShortcutPath"]; if (!File.Exists(powerShellShortcutPath)) { _STAThreadException = new Exception(string.Format("UpdatePSShortcut: file {0} does not exist", powerShellShortcutPath)); return; } ShellLink powerShellShellLink = new ShellLink(powerShellShortcutPath); if (File.Exists(powerShellDefaultShortcutPath)) { session.Log("UpdatePSShortcut: found default Windows PowerShell shortcut at {0}", powerShellDefaultShortcutPath); ShellLink powerShellDefaultShellLink = new ShellLink(powerShellDefaultShortcutPath); powerShellShellLink.ConsoleProperties = powerShellDefaultShellLink.ConsoleProperties; } else { session.Log("UpdatePSShortcut: default Windows PowerShell shortcut does not exist at {0}", powerShellDefaultShortcutPath); for (int i = 0; i < powerShellShellLink.ConsoleProperties.ColorTable.Length; i++) { powerShellShellLink.ConsoleProperties.ColorTable[i] = powerShellDefaultColorTable[i]; } powerShellShellLink.AutoPosition = true; powerShellShellLink.CommandHistoryBufferSize = 50; powerShellShellLink.CommandHistoryBufferCount = 4; powerShellShellLink.InsertMode = true; powerShellShellLink.PopUpBackgroundColor = 15; powerShellShellLink.PopUpTextColor = 3; powerShellShellLink.QuickEditMode = true; powerShellShellLink.ScreenBackgroundColor = 5; powerShellShellLink.ScreenTextColor = 6; powerShellShellLink.SetScreenBufferSize(120, 3000); powerShellShellLink.SetWindowSize(120, 50); } powerShellShellLink.SetFont(); powerShellShellLink.Save(); session.Log("UpdatePSShortcut: success"); } catch (Exception ex) { _STAThreadException = new Exception(string.Format("UpdatePSShortcut: failed with exception {0}", ex.Message)); } }