• 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();
            }

    以上部分代码来源于网络

  • 相关阅读:
    centos6安装mono
    Flashcache系统管理员手册
    【ZT】超乎想象 HTML5九大超酷特效体验
    程序员不可不知的C#代码规范
    【推薦】帮你炼成软件架构师的97件事
    [ZT]智能客户端(Smart Client)
    【ZT】成就大型高性能网站的十项规则
    通過SQL取出所有周六/周日的日期到Table
    【杯具】面试才说一句话就被轰出来了
    Integer在webservice的传递
  • 原文地址:https://www.cnblogs.com/bantongshui/p/3169995.html
Copyright © 2020-2023  润新知