C# 进程处理

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Diagnostics;

public class kkk : MonoBehaviour {

    [System.Runtime.InteropServices.DllImport("kernel32.dll")]
    public static extern int WinExec(string exeName, int operType);

    // Use this for initialization
    void Start () {


        // Process.Start("KuGou.exe");

        //  WinExec(@"C:\Program Files\KuGou\KuGou.exe",6);

        //  StartProcess();

        

        Process.Start(@"C:\Program Files\KuGou\");


    }

    // Update is called once per frame
    void Update () {
		
	}

    //得到进程总数
    public void GetProcess()
    {
        Process[] proList = Process.GetProcesses(".");
        UnityEngine.Debug.Log("进程总数:"+proList.Length);

        foreach (var  name in proList)
        {
            UnityEngine.Debug.Log(name.ProcessName);
        }
        
    }

    public void KillProcess()
    {
        Process[] p = Process.GetProcessesByName("KuGou");
        p[0].Kill();


    }

    public void StartProcess()
    {
        ProcessStartInfo info = new ProcessStartInfo();
        info.FileName = @"C:\Program Files\KuGou\KuGou.exe";
        info.WindowStyle = ProcessWindowStyle.Minimized;

        Process process = Process.Start(info);
       // process.WaitForExit();
        
    }
    


//    0: 隐藏, 并且任务栏也没有最小化图标  
//1: 用最近的大小和位置显示, 激活  
//2: 最小化, 激活  
//3: 最大化, 激活  
//4: 用最近的大小和位置显示, 不激活  
//5: 同 1  
//6: 最小化, 不激活  
//7: 同 3  
//8: 同 3  
//9: 同 1  
//10: 同 1  

}

猜你喜欢

转载自blog.csdn.net/weixin_37744986/article/details/80598203