Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• About the product
• Download
• Sample projects:
Using with Visual Basic
Using with VB.NET
Using with C#
Using with ASP
Using with ASP.NET
Using with Office (VBA)
Using with VBScript
Using with JavaScript
Using with SQL Server
• Support Forum
Winsock Component - Using with VBScript

VBScript sample, based on OstroSoft Winsock component (oswinsck.dll)
Download sample script

Minimum requirements: oswinsck.dll*
* If you don't have OstroSoft Winsock Component, see installation instructions

1. Create file with extension ".vbs" and open it with
text editor of your choice (Notepad is fine)
2. Enter the following code:

Option Explicit

Dim oWinsock 'As OSWINSCK.Winsock
Dim sURL 'As String
Dim sPage 'As String
Dim sServer 'As String
Dim nPort 'As Long
Dim sBuffer 'As String
Dim sSource 'As String
Dim bClose 'As Boolean
Dim sProxy 'As String

'initialize variables
sURL = "": sPage = "": sServer = "": nPort = 80: sBuffer = ""
sSource = "": bClose = False
sProxy = "" 'enter HTTP proxy, if required

'prompt for URL
sURL = InputBox("Enter the URL", "OSWINSCK test", _
  "http://www.ostrosoft.com")

'parse URL
sServer = Trim(sURL)
If InStr(sServer, "://") > 0 Then _
  sServer = Mid(sServer, InStr(sServer, "://") + 3)
If InStr(sServer, "/") > 1 Then
  sPage = Mid(sServer, InStr(sServer, "/"))
  sServer = Left(sServer, InStr(sServer, "/") - 1)
  If InStr(sPage, "#") > 1 Then _
    sPage = Left(sPage, InStr(sPage, "#") - 1)
Else
  sPage = "/"
End If
If InStr(sServer, ":") > 1 Then
  nPort = Mid(sServer, InStr(sServer, ":") + 1)
  sServer = Left(sServer, InStr(sServer, ":") - 1)
End If

If sServer <> "" Then 'connect to the server
  Set oWinsock = CreateObject("OSWINSCK.Winsock")
  WScript.ConnectObject oWinsock, "oWinsock_"

  If sProxy = "" Then
    oWinsock.Connect CStr(sServer), CLng(nPort)
  Else
    sPage = "http://" & sServer & sPage
    oWinsock.Connect CStr(sProxy), 80
  End If
Else
  sSource "Invalid URL"
  bClose = True
End If

Sub oWinsock_OnClose()
  oWinsock.CloseWinsock
  WScript.Echo sSource

  bClose = True
  Set oWinsock = Nothing
End Sub

Sub oWinsock_OnConnect()
  oWinsock.SendData "GET " & sPage & " HTTP/1.0" & vbCrLf & vbCrLf
End Sub

Sub oWinsock_OnDataArrival(ByVal bytesTotal)
  oWinsock.GetData sBuffer
  sSource = sSource & sBuffer
End Sub

Sub oWinsock_OnError(ByVal Number, Description, _
    ByVal Scode, ByVal Source, ByVal HelpFile, _
    ByVal HelpContext, CancelDisplay)
  WScript.Echo Number & ": " & Description
  oWinsock.CloseWinsock
End Sub

While Not bClose
  WScript.Sleep 1
Wend

Copyright © 1996-2008 OstroSoft. All rights reserved. info@ostrosoft.com