• C# 自杀程序 程序运行完毕后删除自身不显示批处理黑窗口 正常运行


    :Repeat
    del /f "d:新建 360压缩 ZIP 文件.zip"
    if exist "d:新建 360压缩 ZIP 文件.zip"  goto Repeat
    rmdir "d:"
    del "DelUS.bat"epeat
    rmdir "d:"
    del "DelUS.bat"

     之前在删除中文文件名的时候,总是不得行,想了很多都没有找到原因,但是同样的内容,新增一个bat,却又能删除,

    因为我的是在代码里生成的批处理内容,问题应该是出在这里在,中文,那是不是编码的问题呢?哈哈,还真是这样,完整代码如下:

            private string pathbat
            {
                get { return FileDirecName + @"Aaa.BAT"; }//生成的bat路径
            }
            private string path
            {
                get
                {
                    return @"" + this.textBox1.Text.Trim() + "";
    
                }
            }
            private string FileName
            {
                get
                {
                    return Path.GetFileName(path);//取得路径中的文件名
    
                }
            }
            private string FileDirecName
            {
                get
                {
                    return Path.GetDirectoryName(path);//获取路径中的目录,不包含文件名哦
    
                }
            }
            private void button1_Click(object sender, EventArgs e)
            {
                StringBuilder sb = new StringBuilder();
                string text = string.Format("{0}
    {1} {2}
    {3}
    {4}
    {5}", ":Repeat", "del /f", """ + path + """, "if exist "" + path + ""  goto Repeat", "rmdir "" + FileDirecName + """, "del "\DelUS.bat"");
                string tex2 = string.Format("{0}
    {1} {2}
    {3}
    {4}
    {5}", ":Repeat", "del /f", """ + pathbat + """, "if exist "" + pathbat + ""  goto Repeat", "rmdir "" + FileDirecName + """, "del "\DelUS.bat"");
                sb.Append(text).Append("
    ").Append(tex2);
                FileStream fs = new FileStream(pathbat, FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("gb2312"));
                sw.Write(sb.ToString());
                sw.Flush();
                sw.Close();
                System.Diagnostics.ProcessStartInfo myStartInfo = new System.Diagnostics.ProcessStartInfo();
                myStartInfo.FileName = pathbat;
                myStartInfo.WorkingDirectory = FileDirecName;
                System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                myProcess.StartInfo = myStartInfo;
                myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                myProcess.Start();
                myProcess.WaitForExit(); //等待程序退出
                base.Close();
            }

    以上部分代码来源于网络

  • 相关阅读:
    【Vim】多文件操作
    TC(Traffic Control)命令—linux自带高级流控
    【ceph | 运维】亲和性
    【Vim】Vim分屏基本操作
    Dubbo常用功能06集群容错
    Dubbo负载均衡策略轮询
    Redis知识体系
    Dubbo常用功能09参数回调
    Dubbo负载均衡策略最少活跃调用数
    Dubbo常用功能10异步调用
  • 原文地址:https://www.cnblogs.com/bantongshui/p/3169995.html
Copyright © 2020-2023  润新知