/// <summary> /// 指定したフォルダに登録されているスタートアップを取得 /// </summary> /// <param name="startup_information">スタートアップ情報</param> /// <param name="startup_register_place">登録情報</param> /// <param name="startup_folder_path">パス</param> private static void GetDesignationFolder( ref System.Collections.Generic.List <StartupInformation> startup_information, StartupRegisterPlace startup_register_place, string startup_folder_path ) { try { string[] file_path = System.IO.Directory.GetFiles(startup_folder_path, "*.lnk", System.IO.SearchOption.TopDirectoryOnly); // ファイルパス foreach (string now_file_path in file_path) { try { IWshRuntimeLibrary.IWshShell_Class shell = new IWshRuntimeLibrary.IWshShell_Class(); IWshRuntimeLibrary.IWshShortcut_Class shortcut = (IWshRuntimeLibrary.IWshShortcut_Class)shell.CreateShortcut(now_file_path); StartupInformation new_startup_information = new StartupInformation { Path = shortcut.TargetPath, RegisterName = System.IO.Path.GetFileNameWithoutExtension(shortcut.FullName), Parameter = shortcut.Arguments, WorkingDirectory = shortcut.WorkingDirectory, RegisterPlace = startup_register_place }; switch (shortcut.WindowStyle) { case 1: new_startup_information.WindowState = WindowState.Normal; break; case 3: new_startup_information.WindowState = WindowState.Maximized; break; case 7: new_startup_information.WindowState = WindowState.Minimized; break; } startup_information.Add(new_startup_information); } catch { } } } catch { } }
/// <summary> /// フォルダに登録 /// </summary> /// <param name="startup_register_place">スタートアップの登録場所</param> /// <param name="register_name">登録名</param> /// <param name="file_path">ファイルパス</param> /// <param name="parameter">パラメータ</param> /// <param name="window_state">ウィンドウの状態</param> /// <param name="working_directory">作業ディレクトリ</param> private static void RegisterFolder( StartupRegisterPlace startup_register_place, string register_name, string file_path, string parameter, WindowState window_state, string working_directory ) { string startup_folder_path = null; // スタートアップフォルダのパス switch (startup_register_place) { case StartupRegisterPlace.FolderLogonUser: startup_folder_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup); break; case StartupRegisterPlace.FolderAllUser: startup_folder_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonStartup); break; } startup_folder_path += "\\" + register_name + ".lnk"; IWshRuntimeLibrary.IWshShell_Class shell = new IWshRuntimeLibrary.IWshShell_Class(); IWshRuntimeLibrary.IWshShortcut_Class shortcut = (IWshRuntimeLibrary.IWshShortcut_Class)shell.CreateShortcut(startup_folder_path); shortcut.TargetPath = file_path; shortcut.Arguments = parameter; switch (window_state) { case WindowState.Normal: shortcut.WindowStyle = 1; break; case WindowState.Maximized: shortcut.WindowStyle = 3; break; case WindowState.Minimized: shortcut.WindowStyle = 7; break; } shortcut.WorkingDirectory = working_directory; shortcut.Save(); }