Newsgroup: it.comp.lang.visual-basic
Titolo: Connessione remota??

Sono riuscito a far partire la connessione remota
grazie al codice trovato nel sito comune
e credo di poterlo chiudere chiudere
con le api 
prima findwindows (per avere l'handle) (che stringa gli faccio
cercarere sapendo che la conessione si chiama pippo)
e poi senmessage
ma come faccio a sapere una folta avviata
quando e' pronta ed attiva ovvero quando ha finito la connessione con
il provider????
michele
NOSPAM...@startmultimedia.com

Prova cosě:
Ti chiude tutte le connessioni (anche perché č difficile che ci siano piů di una attive sulla stessa macchina...)
Ecco le dichiarazioni:
Public Const RAS_MAXENTRYNAME As Integer = 256
Public Const RAS_MaxDeviceType As Integer = 16
Public Const RAS_MAXDEVICENAME As Integer = 128
Public Const RAS_RASCONNSIZE As Integer = 412
Public Const ERROR_SUCCESS = 0&
Public Type RasEntryName
    dwSize As Long
    szEntryName(RAS_MAXENTRYNAME) As Byte
End Type
Public Type RasConn
    dwSize As Long
    hRasConn As Long
    szEntryName(RAS_MAXENTRYNAME) As Byte
    szDeviceType(RAS_MaxDeviceType) As Byte
    szDeviceName(RAS_MAXDEVICENAME) As Byte
End Type
Public Declare Function RasEnumConnections Lib "RasApi32.DLL" Alias "RasEnumConnectionsA" (lprasconn As Any, lpcb As
Long, lpcConnections As Long) As Long
Public Declare Function RasHangUp Lib "RasApi32.DLL" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long
Public gstrISPName As String
Ecco il codice:
    Dim i As Long
    Dim lprasconn(255) As RasConn
    Dim lpcb As Long
    Dim lpcConnections As Long
    Dim hRasConn As Long
 
    lprasconn(0).dwSize = RAS_RASCONNSIZE
    lpcb = RAS_MAXENTRYNAME * lprasconn(0).dwSize
    lpcConnections = 0
    ReturnCode = RasEnumConnections(lprasconn(0), lpcb, lpcConnections)
 
    If ReturnCode = ERROR_SUCCESS Then
        For i = 0 To lpcConnections - 1
            If Trim(lprasconn(i).szEntryName)) = Trim(gstrISPName) Then
                hRasConn = lprasconn(i).hRasConn
                ReturnCode = RasHangUp(ByVal hRasConn)
            End If
        Next i
    End If
Ciao, Moreno
#sirri#@
tin.it
(togliete "#" dall'indirizzo)

On Fri, 08 Jan 1999 19:20:11 GMT, 
si...@tin.it
 (Moreno Sirri) wrote:
Grazie Moreno!
Se non ti rompo troppo come posso sapere se la connessione Pippo una
volta avviata e' attiva, ovvero che e' gia' connessa al provider e che
quindi posso far partire le funzioni di interrogazione in rete??????
Michele

Public Const ERROR_SUCCESS = 0&
Public Const APINULL = 0&
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public ReturnCode As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String,
phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As
String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Public Function ActiveConnection() As Boolean
    Dim hKey As Long
    Dim lpSubKey As String
    Dim phkResult As Long
    Dim lpValueName As String
    Dim lpReserved As Long
    Dim lpType As Long
    Dim lpData As Long
    Dim lpcbData As Long
    ActiveConnection = False
    lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
    ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, phkResult)
 
    If ReturnCode = ERROR_SUCCESS Then
        hKey = phkResult
        lpValueName = "Remote Connection"
        lpReserved = APINULL
        lpType = APINULL
        lpData = APINULL
        lpcbData = APINULL
        ReturnCode = RegQueryValueEx(hKey, lpValueName, lpReserved, lpType, ByVal lpData, lpcbData)
        lpcbData = Len(lpData)
        ReturnCode = RegQueryValueEx(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData)
        If ReturnCode = ERROR_SUCCESS Then
            If lpData = 0 Then
                ActiveConnection = False
            Else
                ActiveConnection = True
            End If
        End If
    RegCloseKey (hKey)
    End If
End Function
If ActiveConnection = True Then
	'C'è una connessione attiva
Else
	'Non c'è nessuna connessione attiva


Ti ringrazio tantissimo
mi potresti tradurre in api anche 
l'attivazione che io adesso attivo cosi'
Sub Main()
Connect ("Pluto")
End
End Sub
Sub Connect(NomeConnessione As String)
    Dim rtn As Long
    rtn = Shell("rundll32.exe rnaui.dll,RnaDial " & NomeConnessione,
0) ' Mostra finestra di connessione
    SendKeys "{ENTER}" 'Preme invio ed avvia la connessione
End Sub
Grazie Michele