PDA

View Full Version : Network Connection ?? làm sao nhĩ ??



phuonghuy2912
21-10-2004, 14:19
Chào mọi người, vấn đề với cái thằng Outlook mình giải quyết xong rùi, nhưng giờ lại sinh ra một vấn đề nữa là :
1. Làm sao biết đc máy tính hiện tại của người dùng có kết nối Internet (hay Lan) không ?
2. Nêu không thì làm sao tìm đc cái Connection Default trong Connection Network của người ta và show lên cho người ta Dial-up ?
-------------------------------------------------------------------------------------------------------------------------------
Vấn đề thứ 1. thì đc rùi, nhưng còn thằng thứ hai mình chưa giải quyết đc ?
Có ai đã làm rồi thì giúp mình với nha, cảm ơn nhiều ?

White Rose
21-10-2004, 20:48
http://windows.oreilly.com/news/dialup_0600.html

phuonghuy2912
22-10-2004, 10:50
Cảm ơn bác White Rose, nhưng mục đích của tui là lấy thẳng cái của OS đang xài - cái Default ấy Login luôn mà không viết lại cái Dialog Dial-up này. Nhưng vẫn đang lay hoay chưa lấy đc thằng Default. Bác có cách nào không ?

À tui có cái source bên VbCity của drydo (vbCity Leader)
Nhưng không hiểu cái namspace Shell32 là ở đây nữa ??
Mấy bác giúp hén .
Thanks

--------------------------------------------------------------
' Switch Boolean (Scope: form or module level)
Dim LANEnable As Boolean = True

' ***** Either placed within a button or routine *****

' Control Panel Identifier
Const ssfCONTROLS = 3

' Enter the name of the connection to manipulate
Dim ConnectionName As String = "Local Area Connection"
Dim EnableVerb As String = "En&able"
Dim DisableVerb As String = "Disa&ble"

' Generate Shell item
Dim ShellApp As New Shell32.Shell()
' Obtain the CP
Dim ControlPanel As Shell32.Folder = ShellApp.NameSpace(ssfCONTROLS)
Dim FolderItem As Shell32.FolderItem
Dim NetworkFolder As Shell32.Folder
Dim LANConnection As Shell32.FolderItem

' Loop through the items in the control panel and obtain the Network Connections folder
For Each FolderItem In ControlPanel.Items()
Debug.WriteLine("Loop 1: " & FolderItem.Name)
If FolderItem.Name = "Network Connections" Then
' When found - exit the loop
NetworkFolder = FolderItem.GetFolder
Exit For
End If
Next

' Debug check
If NetworkFolder Is Nothing Then
MessageBox.Show("Error - No network folder found")
Exit Sub
End If

' Obtain the appropriate connection record
For Each FolderItem In NetworkFolder.Items()
Debug.WriteLine("Loop 2: " & FolderItem.Name)
If FolderItem.Name = ConnectionName Then
' When found - exit the loop
LANConnection = FolderItem
Exit For
End If
Next

' Debug check
If LANConnection Is Nothing Then
MessageBox.Show("Error - No LAN entry was not found")
Exit Sub
End If

' Swtich the LAN toggle
LANEnable = Not LANEnable

Dim EnableVerbItem, DisableVerbItem, Verb As Shell32.FolderItemVerb

' Run through all available options and obtain the appropriate action
For Each Verb In LANConnection.Verbs
Debug.WriteLine("Loop 3: " & Verb.Name)
If Verb.Name = EnableVerb Then
EnableVerbItem = Verb
End If
If Verb.Name = DisableVerb Then
DisableVerbItem = Verb
End If
Next

' Perform the enable / disable
If LANEnable Then
EnableVerbItem.DoIt()
Else
DisableVerbItem.DoIt()
End If
--------------------------------------------------------------

White Rose
23-10-2004, 02:07
Shell32.dll, bạn phải export từ thư viện này vào mới dùng được.
Đây chính là cái bạn cần, tự chuyển sang .NET nhé, have fun!

http://www.thescarms.com/vbasic/wininet.asp

phuonghuy2912
23-10-2004, 08:50
Chào bác WR bác cho tui hỏi cái náy luôn nhé - vì tui kô có xài VB6 nên hơi lạ:
Trong VB6 có kiểu dữ liệu do người dùng định nghĩa Type, có phải cái này là thằng Structure trong VB.Net không ?? - theo tui thì đung rùi, nhưng vấn đề là tại sao trong Structure không thể khai báo tỉnh 1 cái array đc ??
VD :
' Nhu thế này thì OK
Public Structure utRASENTRYNAME
Dim dwSize As Long
Dim szEntryName() As Byte ' ANSI entry point means use Bytes - 'RAS_MaxEntryName + 1
Dim Padding1() As Byte
Dim dwFlags As Long
Dim szPhonebookPath() As Byte ' MAX_PATH + 1
Dim Padding2() As Byte
End Structure

'------------------------------------------
Nhưng như thế này thỉ not ok

Public Structure utRASENTRYNAME
Dim dwSize As Long
Dim szEntryName(RAS_MaxEntryName + 1 ) As Byte ' ****'
' ANSI entry point means use Bytes - RAS_MaxEntryName + 1
Dim Padding1() As Byte
Dim dwFlags As Long
Dim szPhonebookPath(MAX_PATH + 1) As Byte ' MAX_PATH + 1 ' *****'
Dim Padding2() As Byte
End Structure
Lỗi sinh ra ở dòng ' **** đó ????

---------------------------------
Tui làm vậy : Nhưng kô biết có ổn không ?
Public Structure utRASENTRYNAME
Dim dwSize As Long
Dim szEntryName() As Byte ' ANSI entry point means use Bytes - 'RAS_MaxEntryName + 1
Dim Padding1() As Byte
Dim dwFlags As Long
Dim szPhonebookPath() As Byte ' MAX_PATH + 1
Dim Padding2() As Byte

Public Sub redimArr()
ReDim szPhonebookPath(MAX_PATH + 1)
ReDim szEntryName(RAS_MaxEntryName + 1)
End Sub

End Structure

Chỉ tui nhá - chúc bác cuối tuần vui vẽ

White Rose
24-10-2004, 03:05
Nói đơn giản thì mảng nó giống như một con trỏ trỏ đến đoạn bộ nhớ lưu dữ liệu thôi. Bạn khai báo vậy chính xác rồi :-)

phuonghuy2912
26-10-2004, 08:00
Vậy là VB.Net không cho khai báo tỉnh kích thước của mảng trong structure à ???

White Rose
27-10-2004, 04:09
Bạn nên xem lại cú pháp của VB.NET đi. VB.NET vẫn cho bạn khai báo mảng với kích thước xác đinh trước. Chẳng hạn

Dim IntArray(18, 10) As Integer

Tuy nhiên, các API nói chung nếu cần dùng đến một array thì tham số bạn truyền là địa chỉ bắt đầu của array đó. Bạn nên xem kĩ lại tài liệu mô tả cho function mình sử dụng.

phuonghuy2912
29-10-2004, 17:14
Bác xem lại giùm mình nhé!!
Mình nói là trong Structure cơ - chứ ở ngoài thì OK.
Nhưng vấn đề đó mình giải quyết đc rùi ...
Thanks - vì đã gợi ý cho mình nhiều !!