WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Determine if RAS Connection

Keywords:    RAS connection Remote Access Connection

Determing RAS in Windows 95/98:

This is how we test our Win95/98 systems to NOT run update programs if RAS connected. [Remote Connection] will not be there (in the Registry) before connecting, and will be changed to the binary '00 00 00 00' when you disconnect. The value is dynamic, i.e., when connected, it's '01 00 00 00' and when not connected it's '00 00 00 00'.

;============================cut====================================
; Start of Winbatch Code

if RegExistValue(@REGMACHINE, "System\CurrentControlSet\Services\RemoteAccess[Remote Connection]")
   binval=RegQueryBin(@REGMACHINE, "System\CurrentControlSet\Services\RemoteAccess[Remote Connection]")

   If binval=="01 00 00 00"  ;if this value is set, there is a RAS connection
     Remote=@TRUE
     Display(2,"Connection Status","System is connected by RAS")
   Else
     Remote=@FALSE
     Display(2,"Connection Status","System is connected to local network")
   EndIf
Endif
; End of Winbatch Code

Determining RAS in NT:

I need to test our WinNT systems to NOT run update programs if RAS connected. I found 'Determine if RAS Connection.txt' which refers to Win95 and is a Godsend, but there doesn't appear to be an equivalent NT registry key. Many thanks for your help.

Answer:

One user reported that on NT, when an active connectio to a RAS server exists, the following key exists, but this needs to be confirmed.

Note: The part of the key "NdisWan4" referred to in this article CAN vary. It can have values from NdisWan to at least NdisWan6 and possibly higher.


HKLM\System\CurrentControlSet\Services\NdisWan4\Parameters\Tcpip[DhcpIPAddress]
Here's a user's sample login script:
IF RegExistKey(@REGMACHINE, "System\CurrentControlSet\Services\RemoteAccess" ) ; This key does NOT exist unless DUN is installed
; so if it's NOT there the PC CAN'T be dialing in

ndis_ctr="" ; initialize counter -- minor problem -- it starts with just PLAIN NdisWan

While ndis_ctr<10 
	; there's an indeterminate number of NdisWan# keys -- have seen up to NdisWan6 we will check NdisWan thru NdisWan9
	
	IF RegExistValue(@REGMACHINE,"System\CurrentControlSet\Services\NdisWan%ndis_ctr%\Parameters\Tcpip[DhcpIPAddress]" )
	   goto warning 
	; the above key ONLY exists during an active connection to a dial-in server so as soon as we find it we KNOW we've dialed in 
	endif ; so we jump to the warning 
	
	If ndis_ctr=="" ; minor problem -- it starts with just PLAIN NdisWan this section sets it to 1
	   ndis_ctr=1 
	else ; once it's a number rather than "empty" or "" 
	   ndis_ctr=ndis_ctr + 1 ; we can increment it
	endif
endwhile ; if we get all the way through this while loop without jumping to warning we must be connected by LAN


Marty's Usual Trick:


aa=GetTickCount()
FileCopy("FROMSERVER.TXT","LOCALMACHINE.TXT",0)
bb=GetTickCount()
cc=bb-aa
Then if cc is bigger than some number then you have a slow connection and DONT want to update. The value of cc you use is dependent on file size.

The algorithm can occasionally get fooled by a real bogged down network....but then you probably would not want to update anyway so its ok.

The bigger file you transfer the more accurate the number is....but the more time it takes to figure it out. I suggest 1K to 4K files.


Another approach for Win95/98 or NT:

If your script is a logon script then there is almost no chance that DUN is running unless you connected with it. Therefore:


if WinExist("~Connected") || WinExist("~Dial-Up") ;Are we Dial Up
DIALUP=@TRUE
else
DIALUP=@FALSE
endif
Will work on both 95 and NT. Of course you could always use this test to see if it's worth checking the network speed.

Another Option for Detecting RAS in Login Scripts:

There is a utility for use in login scripts called checkras.exe. It is placed in the login script to detect whether someone is logging in through RAS. If so, it skips the more time-consuming login script tasks.

NOTE: Checkras.exe was included in earlier versions of MS Back Office; CheckRas.exe is not included with the Back Office Resource Kit 4.5 or later.

To find it and use it, you may have to scramble around and get it from the earlier version.

Checkras.exe is a command line utility for use in login scripts, etc, and is from the Backoffice Resource kit.

It must only be run on machines which have RAS installed (maybe it bombs otherwise), and I expect it works via errorlevels.

One of our users reported that the following utility, called RASTAT, is much better and is available for download from:


http://sharky.nanko.ru/staff/index.html

Article ID:   W13147
Filename:   Determine if RAS Connection.txt
File Created: 2001:07:25:13:11:52
Last Updated: 2001:07:25:13:11:52