Auto-Start Server Changes

- added username/password settings to use for the Auto-Start server on Boot task.
- updated support zip with new settings.
This commit is contained in:
Brett Hewitson 2022-08-08 21:43:03 +10:00
parent 5532050c04
commit efbdc77be6
17 changed files with 143 additions and 8 deletions

View file

@ -900,6 +900,12 @@
<setting name="Alert_OnlinePlayerCountChange" serializeAs="String">
<value>Online Player Count:</value>
</setting>
<setting name="TaskSchedulerUsername" serializeAs="String">
<value />
</setting>
<setting name="TaskSchedulerPassword" serializeAs="String">
<value />
</setting>
</ServerManagerTool.Config>
</userSettings>
</configuration>

View file

@ -3189,5 +3189,29 @@ namespace ServerManagerTool {
return ((int)(this["ServicePointManager_SecurityProtocol"]));
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string TaskSchedulerUsername {
get {
return ((string)(this["TaskSchedulerUsername"]));
}
set {
this["TaskSchedulerUsername"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string TaskSchedulerPassword {
get {
return ((string)(this["TaskSchedulerPassword"]));
}
set {
this["TaskSchedulerPassword"] = value;
}
}
}
}

View file

@ -872,5 +872,11 @@
<Setting Name="ServicePointManager_SecurityProtocol" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">3072</Value>
</Setting>
<Setting Name="TaskSchedulerUsername" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="TaskSchedulerPassword" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View file

@ -802,6 +802,11 @@
<sys:String x:Key="GlobalSettings_TaskPriority_AutoShutdownLabel">Auto Shutdown/Restart Task Priority:</sys:String>
<sys:String x:Key="GlobalSettings_TaskPriority_AutoStartLabel">Auto Start Task Priority:</sys:String>
<sys:String x:Key="GlobalSettings_TaskSchedulerUsernameLabel">Task Scheduler Username:</sys:String>
<sys:String x:Key="GlobalSettings_TaskSchedulerUsernameTooltip">This username will be used for the Auto-Start server on Boot task.</sys:String>
<sys:String x:Key="GlobalSettings_TaskSchedulerPasswordLabel">Task Scheduler Password:</sys:String>
<sys:String x:Key="GlobalSettings_TaskSchedulerPasswordTooltip">This password will be used for the Auto-Start server on Boot task.</sys:String>
<sys:String x:Key="GlobalSettings_ResetSettings_ConfirmTitle">Confirm Settings Reset Action</sys:String>
<sys:String x:Key="GlobalSettings_ResetSettings_ConfirmLabel">Click 'Yes' to confirm you want to perform the settings reset.</sys:String>
<sys:String x:Key="GlobalSettings_ResetSettings_FailedTitle">Failed to Reset Settings</sys:String>

View file

@ -4611,7 +4611,7 @@ namespace ServerManagerTool.Lib
var taskKey = GetProfileKey();
if (!TaskSchedulerUtils.ScheduleAutoStart(taskKey, null, this.EnableAutoStart, GetLauncherFile(), ProfileName, this.AutoStartOnLogin, Config.Default.AutoStart_TaskPriority))
if (!TaskSchedulerUtils.ScheduleAutoStart(taskKey, null, this.EnableAutoStart, GetLauncherFile(), ProfileName, this.AutoStartOnLogin, Config.Default.TaskSchedulerUsername, Config.Default.TaskSchedulerPassword, Config.Default.AutoStart_TaskPriority))
{
return false;
}

View file

@ -813,6 +813,8 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="20"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="150"/>
@ -856,6 +858,12 @@
<Label Grid.Row="10" Grid.Column="2" Margin="0" Content="{DynamicResource GlobalSettings_TaskPriority_AutoStartLabel}" VerticalAlignment="Center"/>
<ComboBox Name="TaskPriorityAutoStartComboBox" Grid.Row="10" Grid.Column="3" Margin="1" ItemsSource="{Binding ElementName=GlobalSettings, Path=TaskPriorities}" SelectedValue="{Binding Config.AutoStart_TaskPriority}" ToolTip="{DynamicResource GlobalSettings_TaskPriority_Tooltip}" SelectedValuePath="ValueMember" DisplayMemberPath="DisplayMember" PreviewMouseWheel="ComboBox_PreviewMouseWheel"/>
<Label Grid.Row="12" Grid.Column="0" Content="{DynamicResource GlobalSettings_TaskSchedulerUsernameLabel}" VerticalAlignment="Center"/>
<TextBox Grid.Row="12" Grid.Column="1" Margin="1" Text="{Binding Config.TaskSchedulerUsername}" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" ToolTip="{DynamicResource GlobalSettings_TaskSchedulerUsernameTooltip}"/>
<Label Grid.Row="12" Grid.Column="2" Content="{DynamicResource GlobalSettings_TaskSchedulerPasswordLabel}" VerticalAlignment="Center"/>
<TextBox Grid.Row="12" Grid.Column="3" Margin="1" Name="HideTaskSchedulerPasswordTextBox" Text="{DynamicResource ServerSettings_HidePasswordText}" IsEnabled="{Binding Config.Email_UseDetaultCredentials, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ServerSettings_HidePasswordTooltip}" GotFocus="HiddenField_GotFocus" Style="{StaticResource HiddenTextBoxStyle}"/>
<TextBox Grid.Row="12" Grid.Column="3" Margin="1" Name="TaskSchedulerPasswordTextBox" Text="{Binding Config.TaskSchedulerPassword}" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" ToolTip="{DynamicResource GlobalSettings_TaskSchedulerPasswordTooltip}" LostFocus="HiddenField_LostFocus" Visibility="Collapsed"/>
</Grid>
</GroupBox>
</Grid>

View file

@ -434,6 +434,8 @@ namespace ServerManagerTool
textBox = EmailPasswordTextBox;
if (Equals(hideTextBox, HideDiscordBotTokenTextBox))
textBox = DiscordBotTokenTextBox;
if (Equals(hideTextBox, HideTaskSchedulerPasswordTextBox))
textBox = TaskSchedulerPasswordTextBox;
if (textBox != null)
{
@ -459,6 +461,8 @@ namespace ServerManagerTool
hideTextBox = HideEmailPasswordTextBox;
if (textBox == DiscordBotTokenTextBox)
hideTextBox = HideDiscordBotTokenTextBox;
if (textBox == TaskSchedulerPasswordTextBox)
hideTextBox = HideTaskSchedulerPasswordTextBox;
if (hideTextBox != null)
{

View file

@ -972,6 +972,14 @@ namespace ServerManagerTool
comment.AppendLine($"ServerShutdown_WorldSaveDelay: {Config.Default.ServerShutdown_WorldSaveDelay}");
comment.AppendLine($"RCON_MessageCommand: {Config.Default.RCON_MessageCommand}");
comment.AppendLine($"AutoBackup_TaskPriority: {Config.Default.AutoBackup_TaskPriority}");
comment.AppendLine($"AutoUpdate_TaskPriority: {Config.Default.AutoUpdate_TaskPriority}");
comment.AppendLine($"AutoShutdown_TaskPriority: {Config.Default.AutoShutdown_TaskPriority}");
comment.AppendLine($"AutoStart_TaskPriority: {Config.Default.AutoStart_TaskPriority}");
comment.AppendLine($"TaskSchedulerUsername: {Config.Default.TaskSchedulerUsername}");
comment.AppendLine($"HasTaskSchedulerPassword: {!string.IsNullOrWhiteSpace(Config.Default.TaskSchedulerPassword)}");
var zipFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), this.Settings.ProfileID + ".zip");
if (File.Exists(zipFile)) File.Delete(zipFile);

View file

@ -705,6 +705,12 @@
<setting name="Alert_OnlinePlayerCountChange" serializeAs="String">
<value>Online Player Count:</value>
</setting>
<setting name="TaskSchedulerUsername" serializeAs="String">
<value />
</setting>
<setting name="TaskSchedulerPassword" serializeAs="String">
<value />
</setting>
</ServerManagerTool.Config>
</userSettings>
</configuration>

View file

@ -2462,5 +2462,29 @@ namespace ServerManagerTool {
return ((string)(this["AppPatchNotesUrl_Testlive"]));
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string TaskSchedulerUsername {
get {
return ((string)(this["TaskSchedulerUsername"]));
}
set {
this["TaskSchedulerUsername"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string TaskSchedulerPassword {
get {
return ((string)(this["TaskSchedulerPassword"]));
}
set {
this["TaskSchedulerPassword"] = value;
}
}
}
}

View file

@ -677,5 +677,11 @@
<Setting Name="AppPatchNotesUrl_Testlive" Type="System.String" Scope="Application">
<Value Profile="(Default)">https://forums.funcom.com/c/conan-exiles/exiles-pc/testlive</Value>
</Setting>
<Setting Name="TaskSchedulerUsername" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="TaskSchedulerPassword" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View file

@ -957,6 +957,11 @@
<sys:String x:Key="GlobalSettings_TaskPriority_AutoShutdownLabel">Auto Shutdown/Restart Task Priority:</sys:String>
<sys:String x:Key="GlobalSettings_TaskPriority_AutoStartLabel">Auto Start Task Priority:</sys:String>
<sys:String x:Key="GlobalSettings_TaskSchedulerUsernameLabel">Task Scheduler Username:</sys:String>
<sys:String x:Key="GlobalSettings_TaskSchedulerUsernameTooltip">This username will be used for the Auto-Start server on Boot task.</sys:String>
<sys:String x:Key="GlobalSettings_TaskSchedulerPasswordLabel">Task Scheduler Password:</sys:String>
<sys:String x:Key="GlobalSettings_TaskSchedulerPasswordTooltip">This password will be used for the Auto-Start server on Boot task.</sys:String>
<sys:String x:Key="GlobalSettings_ResetSettings_ConfirmTitle">Confirm Settings Reset Action</sys:String>
<sys:String x:Key="GlobalSettings_ResetSettings_ConfirmLabel">Click 'Yes' to confirm you want to perform the settings reset.</sys:String>
<sys:String x:Key="GlobalSettings_ResetSettings_FailedTitle">Failed to Reset Settings</sys:String>

View file

@ -1248,7 +1248,7 @@ namespace ServerManagerTool.Lib
var taskKey = GetProfileKey();
if (!TaskSchedulerUtils.ScheduleAutoStart(taskKey, null, this.EnableAutoStart, GetLauncherFile(), ProfileName, this.AutoStartOnLogin, Config.Default.AutoStart_TaskPriority))
if (!TaskSchedulerUtils.ScheduleAutoStart(taskKey, null, this.EnableAutoStart, GetLauncherFile(), ProfileName, this.AutoStartOnLogin, Config.Default.TaskSchedulerUsername, Config.Default.TaskSchedulerPassword, Config.Default.AutoStart_TaskPriority))
{
return false;
}

View file

@ -758,6 +758,8 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="20"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="150"/>
@ -801,6 +803,12 @@
<Label Grid.Row="10" Grid.Column="2" Margin="0" Content="{DynamicResource GlobalSettings_TaskPriority_AutoStartLabel}" VerticalAlignment="Center"/>
<ComboBox Name="TaskPriorityAutoStartComboBox" Grid.Row="10" Grid.Column="3" Margin="1" ItemsSource="{Binding ElementName=GlobalSettings, Path=TaskPriorities}" SelectedValue="{Binding Config.AutoStart_TaskPriority}" ToolTip="{DynamicResource GlobalSettings_TaskPriority_Tooltip}" SelectedValuePath="ValueMember" DisplayMemberPath="DisplayMember" PreviewMouseWheel="ComboBox_PreviewMouseWheel"/>
<Label Grid.Row="12" Grid.Column="0" Content="{DynamicResource GlobalSettings_TaskSchedulerUsernameLabel}" VerticalAlignment="Center"/>
<TextBox Grid.Row="12" Grid.Column="1" Margin="1" Text="{Binding Config.TaskSchedulerUsername}" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" ToolTip="{DynamicResource GlobalSettings_TaskSchedulerUsernameTooltip}"/>
<Label Grid.Row="12" Grid.Column="2" Content="{DynamicResource GlobalSettings_TaskSchedulerPasswordLabel}" VerticalAlignment="Center"/>
<TextBox Grid.Row="12" Grid.Column="3" Margin="1" Name="HideTaskSchedulerPasswordTextBox" Text="{DynamicResource ServerSettings_HidePasswordText}" IsEnabled="{Binding Config.Email_UseDetaultCredentials, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ServerSettings_HidePasswordTooltip}" GotFocus="HiddenField_GotFocus" Style="{StaticResource HiddenTextBoxStyle}"/>
<TextBox Grid.Row="12" Grid.Column="3" Margin="1" Name="TaskSchedulerPasswordTextBox" Text="{Binding Config.TaskSchedulerPassword}" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" ToolTip="{DynamicResource GlobalSettings_TaskSchedulerPasswordTooltip}" LostFocus="HiddenField_LostFocus" Visibility="Collapsed"/>
</Grid>
</GroupBox>
</Grid>

View file

@ -435,6 +435,8 @@ namespace ServerManagerTool
textBox = EmailPasswordTextBox;
if (Equals(hideTextBox, HideDiscordBotTokenTextBox))
textBox = DiscordBotTokenTextBox;
if (Equals(hideTextBox, HideTaskSchedulerPasswordTextBox))
textBox = TaskSchedulerPasswordTextBox;
if (textBox != null)
{
@ -460,6 +462,8 @@ namespace ServerManagerTool
hideTextBox = HideEmailPasswordTextBox;
if (textBox == DiscordBotTokenTextBox)
hideTextBox = HideDiscordBotTokenTextBox;
if (textBox == TaskSchedulerPasswordTextBox)
hideTextBox = HideTaskSchedulerPasswordTextBox;
if (hideTextBox != null)
{

View file

@ -651,6 +651,8 @@ namespace ServerManagerTool
comment.AppendLine($"Profiles Directory: {Config.Default.ConfigPath}");
comment.AppendLine($"Server Directory: {this.Settings.InstallDirectory}");
comment.AppendLine($"Testlive Server: {this.Settings.UseTestlive}");
comment.AppendLine($"IsAdministrator: {SecurityUtils.IsAdministrator()}");
comment.AppendLine($"RunAsAdministratorPrompt: {Config.Default.RunAsAdministratorPrompt}");
comment.AppendLine($"CheckIfServerManagerRunningOnStartup: {Config.Default.CheckIfServerManagerRunningOnStartup}");
@ -744,6 +746,14 @@ namespace ServerManagerTool
comment.AppendLine($"ServerShutdown_WorldSaveDelay: {Config.Default.ServerShutdown_WorldSaveDelay}");
comment.AppendLine($"RCON_MessageCommand: {Config.Default.RCON_MessageCommand}");
comment.AppendLine($"AutoBackup_TaskPriority: {Config.Default.AutoBackup_TaskPriority}");
comment.AppendLine($"AutoUpdate_TaskPriority: {Config.Default.AutoUpdate_TaskPriority}");
comment.AppendLine($"AutoShutdown_TaskPriority: {Config.Default.AutoShutdown_TaskPriority}");
comment.AppendLine($"AutoStart_TaskPriority: {Config.Default.AutoStart_TaskPriority}");
comment.AppendLine($"TaskSchedulerUsername: {Config.Default.TaskSchedulerUsername}");
comment.AppendLine($"HasTaskSchedulerPassword: {!string.IsNullOrWhiteSpace(Config.Default.TaskSchedulerPassword)}");
var zipFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), this.Settings.ProfileID + ".zip");
if (File.Exists(zipFile)) File.Delete(zipFile);

View file

@ -430,7 +430,7 @@ namespace ServerManagerTool.Common.Utils
return false;
}
public static bool ScheduleAutoStart(string taskKey, string taskSuffix, bool enableAutoStart, string command, string profileName, bool onLogin, ProcessPriorityClass priority)
public static bool ScheduleAutoStart(string taskKey, string taskSuffix, bool enableAutoStart, string command, string profileName, bool onLogin, string username, string password, ProcessPriorityClass priority)
{
var taskName = GetScheduledTaskName(TaskType.AutoStart, taskKey, taskSuffix);
var taskFolder = TaskService.Instance.RootFolder.SubFolders.Exists(TaskFolder) ? TaskService.Instance.RootFolder.SubFolders[TaskFolder] : null;
@ -457,7 +457,8 @@ namespace ServerManagerTool.Common.Utils
Task task = null;
TaskDefinition taskDefinition = null;
TaskLogonType taskLogonType;
string userId;
string taskUsername = !string.IsNullOrWhiteSpace(username) ? username : null;
string taskPassword = !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password) ? password : null;
try
{
@ -488,10 +489,12 @@ namespace ServerManagerTool.Common.Utils
if (onLogin)
{
taskUsername = null;
taskPassword = null;
taskLogonType = TaskLogonType.InteractiveToken;
taskDefinition.Principal.LogonType = taskLogonType;
taskDefinition.Principal.UserId = null;
userId = null;
var oldtriggers = taskDefinition.Triggers.OfType<BootTrigger>();
foreach (var trigger in oldtriggers)
@ -522,10 +525,18 @@ namespace ServerManagerTool.Common.Utils
}
else
{
taskLogonType = TaskLogonType.ServiceAccount;
if (!string.IsNullOrWhiteSpace(taskUsername))
{
taskLogonType = TaskLogonType.Password;
}
else
{
taskUsername = "SYSTEM";
taskPassword = null;
taskLogonType = TaskLogonType.ServiceAccount;
}
taskDefinition.Principal.LogonType = taskLogonType;
taskDefinition.Principal.UserId = null;
userId = "SYSTEM";
var oldtriggers = taskDefinition.Triggers.OfType<LogonTrigger>();
foreach (var trigger in oldtriggers)
@ -564,7 +575,7 @@ namespace ServerManagerTool.Common.Utils
try
{
task = taskFolder.RegisterTaskDefinition(taskName, taskDefinition, TaskCreation.CreateOrUpdate, userId, null, taskLogonType);
task = taskFolder.RegisterTaskDefinition(taskName, taskDefinition, TaskCreation.CreateOrUpdate, taskUsername, taskPassword, taskLogonType);
return task != null;
}
catch (Exception ex)