82 lines
3.2 KiB
C#
82 lines
3.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Diagnostics;
|
||
using System.Linq;
|
||
using System.Text;
|
||
namespace ExplorerTools
|
||
{
|
||
public class ExplorerTool
|
||
{
|
||
public static void KillExplorer(bool state)
|
||
{
|
||
// 9.9 取消此功能
|
||
//if (state)
|
||
// new System.Threading.Thread(KillExplorer).Start();
|
||
//else
|
||
// new System.Threading.Thread(RunExplorer).Start();
|
||
}
|
||
|
||
private static void KillExplorer()
|
||
{
|
||
CmdExplorer(true);
|
||
}
|
||
|
||
private static void RunExplorer()
|
||
{
|
||
//CmdExplorer(false);
|
||
//调用 批处理程序
|
||
StartBat();
|
||
}
|
||
|
||
private static void CmdExplorer(bool a)
|
||
{
|
||
string str;
|
||
if (a)
|
||
{
|
||
str = @"taskkill /f /im explorer.exe";
|
||
}
|
||
else
|
||
{
|
||
str = @"explorer.exe";
|
||
}
|
||
System.Diagnostics.Process p = new System.Diagnostics.Process();
|
||
p.StartInfo.FileName = "cmd";
|
||
p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
|
||
p.StartInfo.RedirectStandardInput = true; //接受来自调用程序的输入信息
|
||
p.StartInfo.RedirectStandardOutput = true; //由调用程序获取输出信息
|
||
p.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
||
p.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
||
p.Start(); //启动程序
|
||
//向cmd窗口发送输入信息
|
||
p.StandardInput.WriteLine(str + "&exit");
|
||
p.StandardInput.AutoFlush = true;
|
||
|
||
p.StandardOutput.ReadToEnd();
|
||
//p.WaitForExit();//等待程序执行完退出进程
|
||
p.Close();
|
||
}
|
||
private static void StartBat()
|
||
{
|
||
System.Diagnostics.Process proc = null;
|
||
try
|
||
{
|
||
// string targetDir = string.Format(@"D:\BizMap\");//这是bat存放的目录
|
||
// string targetDir1 = AppDomain.CurrentDomain.BaseDirectory; //或者这样写,获取程序目录
|
||
string targetDir1 = UnityEngine.Application.streamingAssetsPath+"/bat"; //或者这样写,获取程序目录
|
||
proc = new System.Diagnostics.Process();
|
||
proc.StartInfo.WorkingDirectory = targetDir1;
|
||
proc.StartInfo.FileName = "startExplorer.bat";//bat文件名称
|
||
proc.StartInfo.Arguments = string.Format("10");//this is argument
|
||
//proc.StartInfo.CreateNoWindow = true;
|
||
//proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//这里设置DOS窗口不显示,经实践可行
|
||
proc.Start();
|
||
proc.WaitForExit();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.Log(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
}
|