vb.net把EXE文件加入资源文件,需要时还原成EXE文件的方法(实例)

把EXE加入到VB工程资源中,这是个不错的方法,下载是vb源代码:

Private Const FILESIZEOFAPP = 154688 '我生成的APP.Exe大小是154688Byte
    Private Sub Command1_Click() '单击按钮cmdOK运行代码
        Dim APP() As Byte 'APP是个Btye类型和数组
        Dim Counter As Long
        APP = LoadResData(101, "CUSTOM") '将自定义资源中101号资源读入数组
        '注意,资源标识为"CUSTOM"而非数字
        If Dir(App.Path & "\APP.Exe") <> "" Then '第一次按command1有效
            MsgBox App.Path & "\APP.Exe 已经存在!"
            Exit Sub
       End If
        Open App.Path & "\APP.exe" For Binary As #1 '以二进制方式写入所在的目录
            For Counter = 0 To FILESIZEOFAPP - 1 '注意因为从0 Byte开始因此以文件大小 - 1Byte 为终
                Put #1, , APP(Counter)
            Next Counter
        Close #1
        Shell App.Path & "\APP.Exe", vbNormalFocus  '运行刚生成的APP.Exe
        Unload Me
   End Sub

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code