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放释放出来就好了,剩下自由发挥了。也许有更好的办法,这个只是我简单的一种尝试…
  • 相关阅读:
    主进程与渲染进程的异同
    Electron node integration enabled 设置
    JS-函数总结
    JS-变量、作用域、垃圾回收机制总结
    python进阶知识笔记
    高级抽象函数
    mac支持的文件系统
    生成器generator & 迭代器iterator
    磁盘如何做才能让系统识别
    winPE盘能做什么
  • 原文地址:https://www.cnblogs.com/meteoric_cry/p/4468368.html
Copyright © 2011-2022 走看看