How can i add some bat files to my project so i will not need them anymore on the hard disk?

前端 未结 6 1570

For example i have this code:

Process proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName          


        
6条回答
  •  旧巷少年郎
    2020-12-12 06:54

    As long as you have no variables or nonsingleline-commands you can run this function with each line of the bat-file

        internal static void executeCommand(string command, bool waitForExit,
        bool hideWindow, bool runAsAdministrator)
        {
            System.Diagnostics.ProcessStartInfo psi =
            new System.Diagnostics.ProcessStartInfo("cmd", "/C " + command);
    
            if (hideWindow)
            {
                psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            }
    
            if (runAsAdministrator)
            {
                psi.Verb = "runas";
            }
    
            if (waitForExit)
            {
                System.Diagnostics.Process.Start(psi).WaitForExit();
            }
            else
            {
                System.Diagnostics.Process.Start(psi);
            }
        }
    

    so you can also save the text in the code

    string bat_file = @"@echo off\ncopy c:\users\Desktop\filea.txt c:\users\Desktop\fileb.txt\n...";
    

    otherwise i would create a temporary bat file, run it and delete it.

提交回复
热议问题