/// <summary> /// Initializing an instance of the class, with providing the filename /// of the starting executable file, a <paramref name="name" /> for the /// program, specifying an <paramref name="scope" /> and explicitly /// specifying the dependency on administrator privileges. Using this /// constructor you can specify a custom string to be used as the /// startup indicator. Make sure that there is no other string similar /// to this string in your expected command line arguments to conflict /// with it. /// </summary> /// <param name="applicationImage"> /// The address of the executable file of the application /// </param> /// <param name="name"> /// A unique name for the rule as an alias for the program /// </param> /// <param name="scope"> /// Scope in which startup rule should be created or managed /// </param> /// <param name="needsAdminPrivileges"> /// Set to True if the program should be executed with administrator's /// rights /// </param> /// <param name="provider"> /// Method that is expected to be used for registering the program /// startup /// </param> /// <param name="startupSpecialArgument"> /// A special string to send to the program when started and to detect /// the automatic startup /// </param> /// <exception cref="ArgumentException">Bad argument value.</exception> public StartupManager(string applicationImage, string name, RegistrationScope scope, bool needsAdminPrivileges, StartupProviders provider, string startupSpecialArgument) { if (!File.Exists(applicationImage)) { throw new ArgumentException("File doesn't exist.", nameof(applicationImage)); } if (string.IsNullOrEmpty(name.Trim())) { throw new ArgumentException("Bad name for application.", nameof(name)); } if (string.IsNullOrEmpty(startupSpecialArgument.Trim()) || IsAnyWhitespaceIn(startupSpecialArgument.Trim())) { throw new ArgumentException("Bad string provided as special argument for startup detection.", nameof(startupSpecialArgument)); } ApplicationImage = applicationImage; WorkingDirectory = Path.GetDirectoryName(applicationImage); Name = name.Trim(); NeedsAdministrativePrivileges = needsAdminPrivileges; RegistrationScope = scope; StartupSpecialArgument = startupSpecialArgument.Trim(); Provider = provider; }
/// <summary> /// Initializing an instance of the class, with providing the filename /// of the starting executable file, a <paramref name="name" /> for the /// program, specifying an <paramref name="scope" /> and explicitly /// specifying the dependency on administrator privileges. /// </summary> /// <param name="applicationImage"> /// The address of the executable file of the application /// </param> /// <param name="name"> /// A unique name for the rule as an alias for the program /// </param> /// <param name="scope"> /// Scope in which startup rule should be created or managed /// </param> /// <param name="provider"> /// Method that is expected to be used for registering the program /// startup /// </param> /// <param name="needsAdminPrivileges"> /// Set to True if the program should be executed with administrator's /// rights /// </param> public StartupManager(string applicationImage, string name, RegistrationScope scope, StartupProviders provider, bool needsAdminPrivileges) : this(applicationImage, name, scope, needsAdminPrivileges, provider, "--startup") { }