zoukankan      html  css  js  c++  java
  • 将hta包装为exe发布

    hta在打开的时候,有时候会被杀毒软件拦截而不给执行,更重要的一点是通常都可以右击查看源代码,里面如果涉及到域名或者其它的一些细节就很容易被其它人了解。

    网络上有一些hta转exe的,类似的软件基本上都是国外的,而且要付费,从一些乱七八糟的地方下载过“破解版”的用了一下,不是很好用,对hta支持比较差,对vbs可能会好很多,既然不好用那就只好自己动手了

     

    很简单,主要的实现过程是:将hta作为资源添加至项目中,exe启动后读取资源文件,并写入本地磁盘,然后调用mshta命令启动hta,当hta被关闭时删除该文件。

    读取资源 --> 写文件 --> 执行文件 --> 删除文件

     
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new Form1());

        System.Resources.ResourceManager manager = Properties.Resources.ResourceManager;
        Object target = manager.GetObject("test");

                 
        string strSystemPath = System.Environment.SystemDirectory;
        string strSystemDisk = strSystemPath.Substring(0, 1);

        string strHtaPath = strSystemDisk + ":\temp.hta";

        if (File.Exists(strHtaPath))
        {
            File.Delete(strHtaPath);
        }

        FileStream fs = new FileStream(strHtaPath, FileMode.Create);
        StreamWriter sw = new StreamWriter(fs);
        sw.Write(target.ToString());
        sw.Flush();
        sw.Close();
        fs.Close();

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "mshta.exe";
        startInfo.Arguments = strHtaPath;

        Process process = Process.Start(startInfo);

        //一直等待直到进程被关闭
        process.WaitForExit();

        if (File.Exists(strHtaPath))
        {
            File.Delete(strHtaPath);
        }


        //MessageBox.Show("hahaniu");

        //Application.Run();
    }
     
    exe的话就可以很方便的设定图标了,如果hta也想有图标,就再多获取一个icon放释放出来就好了,剩下自由发挥了。也许有更好的办法,这个只是我简单的一种尝试…
  • 相关阅读:
    (MonoGame从入门到放弃2) 初识MonoGame
    C# 13行代码带你模拟登录QQ空间
    (MonoGame从入门到放弃1) MonoGame环境搭建
    Format 、FormatDateTime 与 FormatFloat
    HTML中的em为何物?
    ASP.NET日期格式函数
    解决windows2003不能上传大于200K的问题
    信用卡知识知多少?
    解决:Win7打开控制面板主页就重启
    ASP.NET生成随机密码
  • 原文地址:https://www.cnblogs.com/meteoric_cry/p/4468368.html
Copyright © 2011-2022 走看看