How do I invoke a dial up connection from a VB script 
Author Message
 How do I invoke a dial up connection from a VB script

This was a great tip. Tanks!

My problem is slightly worse, however.

I want to launch a modem connection,
wait til it's established,
then, launch a VPN connection.

Is it possible to test if a dial up connection is working or not?
I have been in and out of those object models, without finding anything I
can use.

/H?kan Lidstr?m


I don't know if this works on Win2K, but you can try it.

Set ws = CreateObject("WScript.Shell")
Connectoid = "ExactNameOfDUNConnectoid"
ws.Run "rundll rnaui.dll,RnaDial " &  Connectoid

--

Bill James
Microsoft MVPDTS

?Free Win9x VBScript Utilities?
http://www.*-*-*.com/ ~wgjames/vbspage/


Quote:
> I am trying to inkoke a dial-up connection from a VB script on Windows
2000.



Sat, 07 Dec 2002 03:00:00 GMT  
 How do I invoke a dial up connection from a VB script
The WScript create object/run command accepts a third argument to wait for completion.
http://msdn.microsoft.com/scripting/windowshost/doc/wsMthRun.htm

object.Run (strCommand, [intWindowStyle], [bWaitOnReturn])

Set ws = CreateObject("WScript.Shell")
Connectoid = "ExactNameOfDUNConnectoid"
ws.Run "rundll rnaui.dll,RnaDial " &  Connectoid, 1, True

--
Mark L. Ferguson    Please reply in Newsgroup
marfer's notes for OE 5 > http://www.geocities.com/SiliconValley/Bay/6386/IE_ng_notes.htm

Quote:

> This was a great tip. Tanks!

> My problem is slightly worse, however.

> I want to launch a modem connection,
> wait til it's established,
> then, launch a VPN connection.

> Is it possible to test if a dial up connection is working or not?
> I have been in and out of those object models, without finding anything I
> can use.

> /H?kan Lidstr?m



> I don't know if this works on Win2K, but you can try it.

> Set ws = CreateObject("WScript.Shell")
> Connectoid = "ExactNameOfDUNConnectoid"
> ws.Run "rundll rnaui.dll,RnaDial " &  Connectoid

> --

> Bill James
> Microsoft MVPDTS

> ?Free Win9x VBScript Utilities?
> http://home.earthlink.net/~wgjames/vbspage/



> > I am trying to inkoke a dial-up connection from a VB script on Windows
> 2000.



Sat, 07 Dec 2002 03:00:00 GMT  
 How do I invoke a dial up connection from a VB script
Mark, in this case that doesn't work.  The script returns as soon as the DialUp windows appears:

Set ws = CreateObject("WScript.Shell")
Connectoid = "ExactNameOfDUNConnectoid"
ws.Run "rundll rnaui.dll,RnaDial " &  Connectoid, 1, True
MsgBox "I don't wait for nobody."

--

Bill James
Microsoft MVPDTS

?Free Win9x VBScript Utilities?
http://home.earthlink.net/~wgjames/vbspage/


The WScript create object/run command accepts a third argument to wait for completion.
http://msdn.microsoft.com/scripting/windowshost/doc/wsMthRun.htm

object.Run (strCommand, [intWindowStyle], [bWaitOnReturn])

Set ws = CreateObject("WScript.Shell")
Connectoid = "ExactNameOfDUNConnectoid"
ws.Run "rundll rnaui.dll,RnaDial " &  Connectoid, 1, True

--
Mark L. Ferguson    Please reply in Newsgroup
marfer's notes for OE 5 > http://www.geocities.com/SiliconValley/Bay/6386/IE_ng_notes.htm

Quote:

> This was a great tip. Tanks!

> My problem is slightly worse, however.

> I want to launch a modem connection,
> wait til it's established,
> then, launch a VPN connection.

> Is it possible to test if a dial up connection is working or not?
> I have been in and out of those object models, without finding anything I
> can use.

> /H?kan Lidstr?m



> I don't know if this works on Win2K, but you can try it.

> Set ws = CreateObject("WScript.Shell")
> Connectoid = "ExactNameOfDUNConnectoid"
> ws.Run "rundll rnaui.dll,RnaDial " &  Connectoid

> --

> Bill James
> Microsoft MVPDTS

> ?Free Win9x VBScript Utilities?
> http://home.earthlink.net/~wgjames/vbspage/



> > I am trying to inkoke a dial-up connection from a VB script on Windows
> 2000.



Sat, 07 Dec 2002 03:00:00 GMT  
 How do I invoke a dial up connection from a VB script
It a little difficult to check for connection using scripting in Win9x.  There is a Registry value that changes when connected, HKLM\System\CurrentControlSet\Services\RemoteAccess - Remote Connection, but RegRead won't handle that kind of Hex value.

There are several ways to work around this by adding other components to your system:

  RegObj.dll from Clarence's site: http://cwashington.netreach.net/downloads/ocx_controls/registry_objec...

  RasDial95: http://www.osz.com/~claudio/rasdial95/rasdial95.zip

There probably is also a way to do this with WMI, but I don't know that technique.

You can also use Ping.exe, which should be present on any system, and parse the results.  Edit the file to set a domain to ping (I leave it up to you to select the domain -- probably your ISP would be best).

Option Explicit
Dim ws : Set ws = WScript.CreateObject("WScript.Shell")
Dim RegKey : RegKey = "HKEY_LOCAL_MACHINE\System\Current" & _
                      "ControlSet\Services\RemoteAccess"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim Connectoid : Connectoid = "ExactNameOfDUNConnectoid"
Dim h : h = "nnn.nnn.nnn.nnn" 'HOST TO PING

ws.Run "rundll rnaui.dll,RnaDial " & Connectoid, 1, True

CheckConnected()

MsgBox "Where do you want to go today?"

Set ws = Nothing
Set fso = Nothing

Sub CheckConnected
  Dim Connected, ip, Line
  While Not Connected
    ws.run "%comspec% /c PING " & h & " > ip", 0, true
    Set ip = fso.OpenTextFile("ip", 1)
    Do While Not ip.AtEndOfStream
      Line = ip.ReadLine
      If InStr(1, Line, "Reply from", 1) > 0 Then
        Connected = true
        ip.Close
        Set ip = Nothing
        fso.DeleteFile("ip")
        Exit Do
      End If
    Loop
  Wend
End Sub

--

Bill James
Microsoft MVPDTS

?Free Win9x VBScript Utilities?
http://home.earthlink.net/~wgjames/vbspage/

Quote:

> This was a great tip. Tanks!

> My problem is slightly worse, however.

> I want to launch a modem connection,
> wait til it's established,
> then, launch a VPN connection.

> Is it possible to test if a dial up connection is working or not?
> I have been in and out of those object models, without finding anything I
> can use.

> /H?kan Lidstr?m



> I don't know if this works on Win2K, but you can try it.

> Set ws = CreateObject("WScript.Shell")
> Connectoid = "ExactNameOfDUNConnectoid"
> ws.Run "rundll rnaui.dll,RnaDial " &  Connectoid

> --

> Bill James
> Microsoft MVPDTS

> ?Free Win9x VBScript Utilities?
> http://home.earthlink.net/~wgjames/vbspage/



> > I am trying to inkoke a dial-up connection from a VB script on Windows
> 2000.



Sat, 07 Dec 2002 03:00:00 GMT  
 How do I invoke a dial up connection from a VB script
Thank you so much Bill.
I just just about to respond that wait on return does not work, when I saw
your postings.
I will try to implement your solution in JScript. (Should be an interesting
challenge for a WSH beginner.)
/H?kan


It a little difficult to check for connection using scripting in Win9x.
There is a Registry value that changes when connected,
HKLM\System\CurrentControlSet\Services\RemoteAccess - Remote Connection, but
RegRead won't handle that kind of Hex value.

There are several ways to work around this by adding other components to
your system:

  RegObj.dll from Clarence's site:
http://cwashington.netreach.net/downloads/ocx_controls/registry_objec...

  RasDial95: http://www.osz.com/~claudio/rasdial95/rasdial95.zip

There probably is also a way to do this with WMI, but I don't know that
technique.

You can also use Ping.exe, which should be present on any system, and parse
the results.  Edit the file to set a domain to ping (I leave it up to you to
select the domain -- probably your ISP would be best).

Option Explicit
Dim ws : Set ws = WScript.CreateObject("WScript.Shell")
Dim RegKey : RegKey = "HKEY_LOCAL_MACHINE\System\Current" & _
                      "ControlSet\Services\RemoteAccess"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim Connectoid : Connectoid = "ExactNameOfDUNConnectoid"
Dim h : h = "nnn.nnn.nnn.nnn" 'HOST TO PING

ws.Run "rundll rnaui.dll,RnaDial " & Connectoid, 1, True

CheckConnected()

MsgBox "Where do you want to go today?"

Set ws = Nothing
Set fso = Nothing

Sub CheckConnected
  Dim Connected, ip, Line
  While Not Connected
    ws.run "%comspec% /c PING " & h & " > ip", 0, true
    Set ip = fso.OpenTextFile("ip", 1)
    Do While Not ip.AtEndOfStream
      Line = ip.ReadLine
      If InStr(1, Line, "Reply from", 1) > 0 Then
        Connected = true
        ip.Close
        Set ip = Nothing
        fso.DeleteFile("ip")
        Exit Do
      End If
    Loop
  Wend
End Sub

--

Bill James
Microsoft MVPDTS

?Free Win9x VBScript Utilities?
http://home.earthlink.net/~wgjames/vbspage/


Quote:
> This was a great tip. Tanks!

> My problem is slightly worse, however.

> I want to launch a modem connection,
> wait til it's established,
> then, launch a VPN connection.

> Is it possible to test if a dial up connection is working or not?
> I have been in and out of those object models, without finding anything I
> can use.

> /H?kan Lidstr?m



> I don't know if this works on Win2K, but you can try it.

> Set ws = CreateObject("WScript.Shell")
> Connectoid = "ExactNameOfDUNConnectoid"
> ws.Run "rundll rnaui.dll,RnaDial " &  Connectoid

> --

> Bill James
> Microsoft MVPDTS

> ?Free Win9x VBScript Utilities?
> http://home.earthlink.net/~wgjames/vbspage/



> > I am trying to inkoke a dial-up connection from a VB script on Windows
> 2000.



Sun, 08 Dec 2002 03:00:00 GMT  
 How do I invoke a dial up connection from a VB script

Quote:

> It a little difficult to check for connection using scripting in Win9x.  There is a Registry value that changes when connected, HKLM\System\CurrentControlSet\Services\RemoteAccess - Remote Connection, but RegRead won't handle that kind of Hex value.

Actually, RegRead can handle the value if the value is treated as an
array( four elements, 0 to 3).  For example:

'RegRead_Hex_Demo.vbs

On error resume next

set shell = WScript.CreateObject("WScript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")

'       If regRead below fails(new logon after shutdown or reset) or
'       if element(0) in the array returned by regRead = 0, the machine is
'       not connected; if element(0) = 1, the machine is connected.

regBranch = "HKLM\System\CurrentControlSet\Services\RemoteAccess\"
regVal = regBranch & "Remote Connection"

'       The value returned by regread here is an array.

remoteStatusArray = shell.regread(regVal)

if (err <> 0)  or (remoteStatusArray(0) = 0) then
        msg = "Not connected"
else
        msg = "Connected"
end if

msgbox msg



Sun, 08 Dec 2002 03:00:00 GMT  
 How do I invoke a dial up connection from a VB script
Thanks, Guy.  Always glad to learn something new.  Based on your information I have revised the sample script I posted (check connection, dial if not connected, wait till connected, then do something else).

Option Explicit
Dim ws : Set ws = WScript.CreateObject("WScript.Shell")
Dim RegKey : RegKey = "HKEY_LOCAL_MACHINE\System\CurrentControl" & _
                      "Set\Services\RemoteAccess\Remote Connection"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim Connectoid : Connectoid = "ExactNameOfDUNConnectoid"

CheckConnected()

MsgBox "Connected"

Sub CheckConnected
  Dim Connected, Dialing, v
  On error resume next
  While Not Connected
    v = ws.regread(RegKey)
    If (Err <> 0) Or (v(0) = 0) Then
      If Not Dialing Then Dialup()
      Dialing = True
    Else
      Connected = True
    End If
  Wend
End Sub

Sub Dialup()
  ws.Run "rundll rnaui.dll,RnaDial " & Connectoid, 1, True
End Sub
--

Bill James
Microsoft MVPDTS

?Free Win9x VBScript Utilities?
http://home.earthlink.net/~wgjames/vbspage/

Quote:


> > It a little difficult to check for connection using scripting in Win9x.  There is a Registry value that changes when connected, HKLM\System\CurrentControlSet\Services\RemoteAccess - Remote Connection, but RegRead won't handle that kind of Hex value.

> Actually, RegRead can handle the value if the value is treated as an
> array( four elements, 0 to 3).  For example:

> 'RegRead_Hex_Demo.vbs

> On error resume next

> set shell = WScript.CreateObject("WScript.Shell")
> set fso = CreateObject("Scripting.FileSystemObject")

> ' If regRead below fails(new logon after shutdown or reset) or
> ' if element(0) in the array returned by regRead = 0, the machine is
> ' not connected; if element(0) = 1, the machine is connected.

> regBranch = "HKLM\System\CurrentControlSet\Services\RemoteAccess\"
> regVal = regBranch & "Remote Connection"

> ' The value returned by regread here is an array.

> remoteStatusArray = shell.regread(regVal)

> if (err <> 0)  or (remoteStatusArray(0) = 0) then
> msg = "Not connected"
> else
> msg = "Connected"
> end if

> msgbox msg



Sun, 08 Dec 2002 03:00:00 GMT  
 How do I invoke a dial up connection from a VB script

Quote:

> Thanks, Guy.  Always glad to learn something new.  Based on your information I have revised the sample script I posted (check connection, dial if not connected, wait till connected, then do something else).

> Option Explicit
> Dim ws : Set ws = WScript.CreateObject("WScript.Shell")
> Dim RegKey : RegKey = "HKEY_LOCAL_MACHINE\System\CurrentControl" & _
>                       "Set\Services\RemoteAccess\Remote Connection"
> Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
> Dim Connectoid : Connectoid = "ExactNameOfDUNConnectoid"

> CheckConnected()

> MsgBox "Connected"

> Sub CheckConnected
>   Dim Connected, Dialing, v
>   On error resume next
>   While Not Connected
>     v = ws.regread(RegKey)
>     If (Err <> 0) Or (v(0) = 0) Then
>       If Not Dialing Then Dialup()
>       Dialing = True
>     Else
>       Connected = True
>     End If
>   Wend
> End Sub

> Sub Dialup()
>   ws.Run "rundll rnaui.dll,RnaDial " & Connectoid, 1, True
> End Sub
> --

> Bill James
> Microsoft MVPDTS

That's an elegant application of the tip.
I've learned a lot from your posts while lurking.  Glad to be of help.


Mon, 09 Dec 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Invoke a Dial up connection using WSH

2. Invoke Dial Up connection using WSH in Win98

3. Script to DIAL a RAS connection???

4. RAS/Dial-Up connection creation script?

5. script a dial-up connection

6. Changing Dial-up connection proxy settings scripts/tools?

7. Script for creating Dial-up connections in NT

8. script a network dial-up connection

9. Scripting for Dial UP connections

10. How to invoke dialing dialog

11. VB Script database connection

12. Connection: VB Script-Crystal Report 6.0

 

 
Powered by phpBB® Forum Software