The ActiveX control provides methods to access the Remote Access Services (RAS) API. This enables you to control your Dial Up Network (DUN) from WSH scripts. The OCX file (see below) is released to the public in the internet.
Alpha Version of WSHRas.ocx , which is available for download now. I just have tested the control in Windows Me and in Windows 98.
The ActiveX control WSHRas (WSHRas.ocx) contains the object WSHRas, which extends the Windows Scripting Host with methods to access the RAS API.
Using the object
The object may be created in VBScript with the following statement:
Dim oRas Set oRas = WScript.CreateObject("WSHRas.Ras")
and in JScript with the following statement:
var oRas = WScript.CreateObject("WSHRas.Ras");
Then you may use the object variable oRas to access the methods and properties.
The WSHRas methods
Till now I haven't finished an extended English languaged document describing the methods exposed by this object. Here is in brief what the object provides:
oRAS.InetAutoDial
Uses the default DUN to establish an online connection.
oRAS.InetAutoDialHangup
Disconnect the already running default DUN connection. Fails on non-default DUN connections.
oRAS.RASStatus
Returns the online state of the current session.
True = a DUN connection is active,
False = no online connection (via DUN) found
Example:
WScript.Echo "Online-State: "
& oRAS.RASStatus()
Here are the methods to use any DUN entry for a internet
connection.
oRas.InetDial (Text(tmp),ConID)
Use the DUN entry submitted in the parameter Text to establish a DUN connection. The parameter ConID receives the connection ID (which is required to disconnect).
oRas.RasEnum (Num, Text)
Retrieves all DUN entries. The parameter Text must be an array (which is used to return the names of DUN entries). The array size is submitted in the parameter Num. After calling, the parameter Num contains the number of DUN entries already found (the value is alway below or equal the initial value passed to the method - to prevent a buffer overflow, if more DUN entries are found then the buffer Text() allows). If the buffer Text() is to small to keep all DUN entries, the last entries are cut off.
oRas.InetHangup (ConID)
Disconnect the DUN-session specified in ConID.
The VBScript samples within the ZIP-Archive demonstrates how to use the WSHRas.ocx control. The following code listing demonstrates how to enumerate all RAS entries, dial one entry and hang up.
'************************************************ ' File: RasTest.vbs (WSH-sample in VBScript) ' Author: (c) G. Born ' ' Demonstrates how to use Remote Access Services (RAS) ' to enumerate all RAS entries, dial on and hang up. ' Use the ActiveX control WSHRas.ocx, that provides ' a scripteable interface to WinInet.dll. '************************************************ Option Explicit Dim oRas ' RAS object Dim Num ' number of RAS entries Dim Text (10) ' buffer for max. 10 RAS entries Dim ConID ' connection ID Dim i, txt, tmp ' helper variables Num = 10 ' init buffer size ' create RAS object reference Set oRas = WScript.CreateObject("WSHRas.Ras") ' try to enumerate all RAS entries ' after call Num contains the number of entries, ' if the call fails, RasEnum returns false If oRas.RasEnum (Num, Text) Then txt = "Number of entries: " & Num & vbCrLf For i = 0 to Num-1 txt = txt & i & ": " & Text(i) & vbCrLf Next tmp = InputBox (txt, "Please enter a number", "0") End if ' Ask user whether to dial or not If MsgBox ("Connecting to: " & Text(tmp), vbYesNo + vbQuestion, _ "Dialing Test") = vbYes Then If oRas.InetDial (Text(tmp),ConID) Then WScript.Echo "Connected to: ", Text(tmp), _ vbCrLf & "Connect ID: " & ConID If MsgBox ("Hangup ?", vbYesNo + vbQuestion, _ "Dialing Test") = vbYes Then _ If oRas.InetHangup (ConID) Then WScript.Echo "Done" End If End If WScript.Echo "Ready" '* End |
The WSHRas ActiveX control comes AS-IS without any warranty and support. Use the control at your own risk. In no case the author will be liable for damages or losses or whatever else resulting from the use of this component. The OCX module may be freely distributed under the condition that this Programmers Reference is included and that the WSH Bazaar with its URL http://www.borncity.de is mentioned as the source of the control.
Download the OCX file and install it on your
machine. Because the ActiveX control was developed under VB, it
needs the VB 5 run-time libraries. If you have ever installed the
WSHExtend control, these run-time libraries are
available. Then is is sufficient to download the ZIP-archive,
unzip the files into a local folder and run RegSvr32.exe to
install the control. The control may be registered using:
RegSvr32.exe path\WSHRas.ocx
Unregistering may be done with:
RegSvr32.exe /u path\WSHRas.ocx
Further details may be found in the file
Readme.txt shipped within the ZIP archive.
Feedback about trouble may be reported to GBorn@Borncity.de.
top
by (c) Günter Born changed 16-August-2000