Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script to output single HTTP GET ?

Reply
 
Old 10-07-2009   #1 (permalink)
Vilius Mockûnas


 
 

Script to output single HTTP GET ?

Hello,

I'm looking a way to execute single http GET request using vbscript.
The script will be run in wsh not in ASP.

thanks
Vilius



My System SpecsSystem Spec
Old 10-07-2009   #2 (permalink)
David H. Lipman


 
 

Re: Script to output single HTTP GET ?

From: "Vilius Mockûnas" <v_mockunas@newsgroup>

| Hello,

| I'm looking a way to execute single http GET request using vbscript.
| The script will be run in wsh not in ASP.

| thanks
| Vilius


Why not incorporate a shell to the GNU WGET utility ?

--
Dave
http://www.claymania.com/removal-trojan-adware.html
Multi-AV - http://www.pctipp.ch/downloads/dl/35905.asp


My System SpecsSystem Spec
Old 10-07-2009   #3 (permalink)
Tom Lavedas


 
 

Re: Script to output single HTTP GET ?

On Oct 7, 12:54*am, "Vilius Mockûnas" <v_mocku...@newsgroup> wrote:
Quote:

> Hello,
>
> I'm looking a way to execute single http GET request using vbscript.
> The script will be run in wsh not in ASP.
>
> thanks
> Vilius
Need a little more information. What is to be accomplished with the
Get? Display the resulting page? Save the response? Is the expected
response primarily text (HTNL) or binary (image)?

The common method of issuing a GET from script is to access the
scriptable MSXML.XMLHTTP class, something like the routine below,
which uses a Get to retrieve and save an arbitrary URL (works for text
or binary) to the named file.

' Source Michael Harris & Alex K. Angelopoulos
' modified by TGL May 2003
' http://groups.google.com/groups?selm...40TK2MSFTNGP11
&
' http://www.google.com/groups?selm=%2...%40tkmsftngp05

Sub DownBinFile(FilePath, sURL)
Const adTypeBinary = 1, adModeReadWrite = 3, adSaveCreateOverwrite =
2
' Create an xmlhttp object:
set oXML = CreateObject("MSXML2.XMLHTTP")
oXML.open "GET", sURL, False
oXML.send
With CreateObject("ADODB.Stream")
.type = adTypeBinary
.mode = adModeReadWrite
.open
Do Until oXML.readyState = 4 : Wscript.Sleep 50 : loop
.write oXML.responseBody
.savetofile FilePath, adSaveCreateOverwrite
End With
End Sub

Is that what you wanted? If not, please explain.
_____________________
Tom Lavedas
My System SpecsSystem Spec
Old 10-07-2009   #4 (permalink)
Anteaus


 
 

RE: Script to output single HTTP GET ?

Method using COM:

Function HTTPGet(URL)
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate URL
do while IE.Busy
loop
HTTPGet = IE.document.documentelement.outerhtml
IE.quit
Set IE = Nothing
End Function

Or, a better approach, use AutoIt's InetGet() function.

http://autoitscript.com

"Vilius Mockûnas" wrote:
Quote:

> Hello,
>
> I'm looking a way to execute single http GET request using vbscript.
> The script will be run in wsh not in ASP.
>
> thanks
> Vilius
>
>
>
My System SpecsSystem Spec
Old 10-07-2009   #5 (permalink)
mayayana


 
 

Re: Script to output single HTTP GET ?

In addition to the other answers provided, if
you want to do it more directly see here:

www.jsware.net/jsware/scripts.php5#jshttp

The XML method shown by Tom Lavedas is
easier (assuming that you don't have ADODB
disabled/removed).
This download more like a scriptable interface
for the Windows sockets API. It lets you handle
the server "conversation" directly.

Quote:

> Hello,
>
> I'm looking a way to execute single http GET request using vbscript.
> The script will be run in wsh not in ASP.
>
> thanks
> Vilius
>
>

My System SpecsSystem Spec
Old 10-10-2009   #6 (permalink)
Ruediger Roesler


 
 

Re: Script to output single HTTP GET ?

Tom Lavedas <tglbatch@newsgroup> typed:
Quote:
Quote:

>> I'm looking a way to execute single http GET request using vbscript.
>> The script will be run in wsh not in ASP.
Quote:

> The common method of issuing a GET from script is to access the
> scriptable MSXML.XMLHTTP class, something like the routine below,
> which uses a Get to retrieve and save an arbitrary URL (works for text
> or binary) to the named file.
>
> ' Source Michael Harris & Alex K. Angelopoulos
> ' modified by TGL May 2003
> ' http://groups.google.com/groups?selm...40TK2MSFTNGP11
> &
> ' http://www.google.com/groups?selm=%2...%40tkmsftngp05
>
> Sub DownBinFile(FilePath, sURL)
> Const adTypeBinary = 1, adModeReadWrite = 3, adSaveCreateOverwrite =
> 2
> ' Create an xmlhttp object:
> set oXML = CreateObject("MSXML2.XMLHTTP")
> oXML.open "GET", sURL, False
> oXML.send
> With CreateObject("ADODB.Stream")
> .type = adTypeBinary
> .mode = adModeReadWrite
> .open
> Do Until oXML.readyState = 4 : Wscript.Sleep 50 : loop
> .write oXML.responseBody
> .savetofile FilePath, adSaveCreateOverwrite
> End With
> End Sub
It should be still maybe considered that the call of your function fails
if the "GlobalUserOffline" flag of the "Internet Settings" is set.
That's why it is advisable to check the state of this flag every time
before an online call to the http api is made.

*IESample Registry Settings*:
http://msdn.microsoft.com/en-us/library/aa908115.aspx

Therefore, I have written an example script to demonstrate this. It
downloads the application TCPView from SysInternals and executes it
after unpacking.

<!--######################### TCPView.wsf #############################
von h.r.roesler -->
<job>
<runtime>
<description>
Starts the TCPView utility from SysInternals. If it does not
exist on the local system, it is downloaded from the internet.

To show this message, enter:
TCPIPLog.wsf /?
</description>
</runtime>
<object id="fso" progid="Scripting.FileSystemObject"/>
<object id="wshShell" progid="WScript.Shell"/>
<object id="xmlHttpReq" progid="MSXML2.XMLHTTP.3.0"/>
<object id="adoStream" progid="ADODB.Stream" reference="true"/>
<resource id="URL">
http://download.sysinternals.com/Files/TCPView.zip</resource>
<script language="VBScript">
Option Explicit

Dim strFldr, strPath, strAppl

strAppl = "TCPView.exe"
strPath = wshShell.CurrentDirectory & ";" & _
fso.GetParentFolderName(WScript.ScriptFullName) & ";" & _
wshShell.Environment("PROCESS")("PATH")

For Each strFldr In Split(strPath, ";")
If Len(strFldr) > 0 Then
If fso.FileExists(fso.BuildPath(strFldr, strAppl)) Then
strAppl = fso.BuildPath(strFldr, strAppl)
Exit For
End If
End If
Next
If Not(fso.FileExists(strAppl)) Then strAppl = GetAppl(strAppl)
wshShell.Run strAppl

Function GetAppl(strProg)
Dim str, strDest

Select Case wshShell.PopUp(strProg & " wasn't found. Do you " & _
"want it to download now?" & vbCRLF & _
getResource("URL"), 60, WScript.Scriptname & _
": Request", vbYesNo Or vbQuestion Or vbSystemModal)
Case vbNo
Err.Raise vbObjectError + 2, , "Application was" & _
"not found: " & strProg
Case Else
str = wshShell.Environment("USER")("TEMP")
str = wshShell.ExpandEnvironmentStrings(str)
str = Download(getResource("URL"), str)
End Select

strDest = fso.GetParentFolderName(WScript.ScriptFullName)
GetAppl = Unzip(str, strDest, strProg)
End Function

Function Download(strURL, strDstPath)
Const CURVER = "HKCU\Software\Microsoft\Windows\CurrentVersion\"
Const OFF = "Internet Settings\GlobalUserOffline", COMPLETED = 4
Dim intOffline

strDstPath = fso.BuildPath(strDstPath, fso.GetFileName(strURL))
If Not(fso.FileExists(strDstPath)) Then
intOffline = ReadReg(CURVER & OFF)
If intOffline <> 0 Then
wshShell.RegWrite CURVER & OFF, 0, "REG_DWORD"
End If ' see <http://support.microsoft.com/kb/195730>
xmlHttpReq.Open "GET", strURL, False
xmlHttpReq.Send
Do
WScript.Sleep 50
Loop Until xmlHttpReq.ReadyState = COMPLETED
With adoStream
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write xmlHttpReq.ResponseBody
.SaveToFile strDstPath, adSaveCreateNotExist
.Close
End With
If ReadReg(CURVER & OFF) <> intOffline Then
wshShell.RegWrite CURVER & OFF, intOffline, "REG_DWORD"
End If
End If

Download = strDstPath
End Function

Function Unzip(strZipFldr, strDestFldr, strFile)
Dim xpZipFolder, xpDstFolder

With CreateObject("Shell.Application")
Set xpZipFolder = .NameSpace(strZipFldr)
Set xpDstFolder = .NameSpace(strDestFldr)
xpDstFolder.CopyHere xpZipFolder.ParseName(strFile)
End With

Unzip = fso.BuildPath(strDestFldr, strFile)
End Function

Function ReadReg(ByRef strKey)
On Error Resume Next
ReadReg = wshShell.RegRead(strKey)
End Function
</script>
</job>
<!--######################### TCPView.wsf ##########################-->

This is a reduced version of a little more extensive script which I have
written before some time. However, this script encloses approximately
400 lines, so that it is a little bit too largely to publish it here.

--
ЯR

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: script output VB Script
Output XML to Single Line Log File using VBScript VB Script
output group membership on a single line PowerShell
BUG: All http access blocked after running Perl script Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46