Using OpenNetCF Registry Classes on PDA to determine Activesync Connection

  • Thread starter Thread starter garfitz
  • Start date Start date
G

garfitz

Have recently downloaded these classes but am struggling - the lin to
the sample is down.

Has anyone used these classes to establish if an Activesync connection
is active (i.e. existence of "HKLM\Comm\Tcpip\Hosts\ppp_peer") and
more importantly does it do the trick ?

Gar.
 
AFAIK testing for the presence of this registry key is a way to determine if
an ActiveSync connection is present.

Here is a little snippet to use the OpenNETCF.org Registry library to test
for the key:


using OpenNETCF.Win32

private void Form1_Load(object sender, System.EventArgs e)
{
string key = "Comm\\tcpip\\hosts\\ppp_peer";

regKey = Registry.LocalMachine;

regKey = regKey.OpenSubKey(key, false);

if (regKey == null)
{
// NO ActiveSync connection available
}
else
{
// we do have an ActiveSync connection.
}
}


In this sample I used the FormLoad event to test the registry, but of course
you can do this anywhere you want.
 
Maarten,

Have implemented in VB.Net (don't have C# on notebook).
However, result is always "True" even though activesync is disconnected
and device is physically removed from cradle.
What property is (regKey is "") referencing ?
Any ideas ?

--- CODE USED ---
Dim keyName As String = "Comm\\tcpip\\hosts\\ppp_peer"
Dim regKey As RegistryKey
regKey = Registry.LocalMachine
regKey = regKey.OpenSubKey(keyName, False)

If regKey Is "" Then
Return False
Else
Return True
End If
 
Actually, in VB you should not test against "", but against nothing, because
regKey will not return "", so you will always get true. Also, I don't think
that two backslashes are needed between each subkey in the keyname string. I
verified this code snippet on a device and it works:

Dim rk As RegistryKey
Dim key As String = "Comm\tcpip\hosts\ppp_peer"

rk = Registry.LocalMachine

rk = rk.OpenSubKey(key)

If rk Is Nothing Then
MessageBox.Show("ActiveSync: No connection")
Else
MessageBox.Show("ActiveSync: CONNECTED!")
End If
 
Back
Top