vb实现EXE生成EXE
2008年04月17日 星期四 16:02
Const file_size = 20480 Private Sub Form_Load() Dim snum As Long Dim sinfo As String,sappend As Byte Open App.Path & "\" & App.EXEName & ".exe" For Binary Access Read As #1 Seek #1,file_size + 1 ’'将读取指针定位到文件尾部 For snum = 1 To FileLen(App.Path & "\" & App.EXEName & ".exe") - file_size Get #1,sappend ’'读出超出模板大小的字节部分,即我们写进去的配置信息 sinfo = sinfo + Chr(sappend) Next snum Close #1 Text1.Text = sinfo End Sub 保存工程1.exe 客户端: Private Sub Command1_Click() Const FILE_SIZE = 20480 '这是101号资源中的服务端文件1.exe的大小 Dim bInfo As Byte Dim bFile() As Byte Dim iInfoLen As Integer Dim i As Integer,lFile As Long,filesavename As String On Error Resume Next iInfoLen = Len(Text1.Text) 'text1中输入字符的长度 filesavename = Text2.Text & ".exe" '打开文本中数据然后保存 If Text1.Text = "" Then Exit Sub End If bFile = LoadResData(101,"CUSTOM") '读出101号资源 Open filesavename For Binary Access Write As #1 For lFile = 0 To FILE_SIZE - 1 '判断资源大小 Put #1,bFile(lFile) '输出 Next lFile For i = 1 To iInfoLen '读出配置信息并追加 bInfo = Asc(Mid(Text1.Text,i,1)) '转换成ASC格式 Put #1,bInfo Next i Close #1 Shell App.Path & "/" & filesavename,vbNormalFocus 'Unload Me End Sub |