csharp 通过Visual Studio创建程序启动器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 通过Visual Studio创建程序启动器相关的知识,希望对你有一定的参考价值。

/*
Let's say you want to create a launcher that, with the click of a button, opens all of the programs you use on a daily basis. Let's also say that your system administrator has blocked certain apps from running unless they are run with Administrative permission. And, finally, let's say that some of your programs (Like Outlook) don't function properly when they, too, are run with administrative permission
*/

/*
To handle this, create Scheduled Tasks using the Windows Task Scheduler. Don't add any triggers to your tasks, but point them to the program you want to launch. If they need administrative permission to run, check the "Run with highest permission" checkbox. If they don't, leave it unchecked
*/

/*
Run your tasks as follows:
(In the examples below, my tasks are stored in a custom folder in the Task Scheduler named "Doug's Custom Tasks")
*/
var Args = new string[] {
            "/run /tn \"\\Doug's Custom Tasks\\Run PortableApps as Administrator\""
        };
        StartupPrograms.Add(new StartupProgram
        {
            AppPath = @"C:\Windows\System32\Schtasks.exe",
            AppName = "Task Scheduler",
            Args = Args
        });
        
        Args = new string[]
        {
            "/run /tn \"\\Doug's Custom Tasks\\Run Outlook As Standard User\""
        };
        StartupPrograms.Add(new StartupProgram
        {
            AppPath = @"C:\Windows\System32\Schtasks.exe",
            AppName = "Task Scheduler",
            Args = Args
        });
        
        /*
        For programs that don't matter how they run, you can call them individually
        */
        StartupPrograms.Add(new StartupProgram
        {
            AppPath = @"C:\Users\dlockwood\AppData\Local\Apps\2.0\H34GAGRH.PJ8\NXANYN8W.LQA\81e2..5a40_0000000000000000_000b.0004_d0f5373a6993ab3a\TechnicianClient.exe",
            AppName = "BMC Track-It"
        });
        
        
/***MS EDGE*/
        ProcessStartInfo processInfo;
        Process process;

        processInfo = new ProcessStartInfo("cmd.exe", "/K " + "\"" + @"%windir%\explorer.exe shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge
" + "\" & exit");

        processInfo.CreateNoWindow = true;
        processInfo.UseShellExecute = true;
        processInfo.RedirectStandardOutput = false;
        processInfo.ErrorDialog = true;

        process = Process.Start(processInfo);
        process.Close();
        process.Dispose();

以上是关于csharp 通过Visual Studio创建程序启动器的主要内容,如果未能解决你的问题,请参考以下文章

csharp 在Visual Studio(适用于大型项目)的整个解决方案中,使用公共库中的NLog工作的示例类。

如何在 Visual Studio 中为带有 Windows 计算机的 Xamarin 应用程序设计用户界面?

csharp 【WPF】Visual Studioのデザイン表示时にエラーが発生する场合の対处法

Visual Studio设置代码注释模板

visual studio下工程启动失败,提示无法启动程序,系统找不到指定的文件

visual studio下工程启动失败,提示无法启动程序,系统找不到指定的文件