بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله وبركاته
إخواني الأعزاء أقدم لكم اليوم كود تفعيل و تعطيل الشبكة المحلية
في البداية أحب أن أشكر الأخ DreamNet
وذلك لأن الفضل يعود لله عز و جل ثم له في هذا الموضوع
قبل البدء يجب إضافة المرجع Microsoft Shell Controls and Automationللمشروع وذلك كما يلي
القائمة Project ثم References ثم نختار Microsoft Shell Controls and Automation ثم نضغط Ok
سوف تحتاج لإتمام هذه العملية إلى زرين Command1 , Command2
نكتب في الحدث Click للزر الأول
Dim LANEnable As Boolean
LANEnable = True
Const ssfCONTROLS = 3
Dim ConnectionName As String
ConnectionName = "Local Area Connection"
Dim EnableVerb As String
EnableVerb = "En&able"
Dim DisableVerb As String
DisableVerb = "Disa&ble"
Dim ShellApp As New Shell32.Shell
' Obtain the CP
Dim ControlPanel As Shell32.Folder
Set ControlPanel = ShellApp.NameSpace(ssfCONTROLS)
Dim FolderItem As Shell32.FolderItem
Dim NetworkFolder As Shell32.Folder
Dim LANConnection As Shell32.FolderItem
For Each FolderItem In ControlPanel.Items()
If FolderItem.Name = "Network Connections" Then
Set NetworkFolder = FolderItem.GetFolder
Exit For
End If
Next
If NetworkFolder Is Nothing Then
MessageBox.Show ("Error - No network folder found")
Exit Sub
End If
For Each FolderItem In NetworkFolder.Items()
If FolderItem.Name = ConnectionName Then
Set LANConnection = FolderItem
Exit For
End If
Next
If LANConnection Is Nothing Then
MessageBox.Show ("Error - No LAN entry was not found")
Exit Sub
End If
LANEnable = Not LANEnable
Dim EnableVerbItem As Shell32.FolderItemVerb
Dim DisableVerbItem As Shell32.FolderItemVerb
Dim Verb As Shell32.FolderItemVerb
For Each Verb In LANConnection.Verbs
If Verb.Name = EnableVerb Then
Set EnableVerbItem = Verb
End If
If Verb.Name = DisableVerb Then
Set DisableVerbItem = Verb
End If
Next
EnableVerbItem.DoItونكتب في الحدث Click للزر الثاني :
Dim LANEnable As Boolean
LANEnable = True
Const ssfCONTROLS = 3
Dim ConnectionName As String
ConnectionName = "Local Area Connection"
Dim EnableVerb As String
EnableVerb = "En&able"
Dim DisableVerb As String
DisableVerb = "Disa&ble"
Dim ShellApp As New Shell32.Shell
' Obtain the CP
Dim ControlPanel As Shell32.Folder
Set ControlPanel = ShellApp.NameSpace(ssfCONTROLS)
Dim FolderItem As Shell32.FolderItem
Dim NetworkFolder As Shell32.Folder
Dim LANConnection As Shell32.FolderItem
For Each FolderItem In ControlPanel.Items()
If FolderItem.Name = "Network Connections" Then
Set NetworkFolder = FolderItem.GetFolder
Exit For
End If
Next
If NetworkFolder Is Nothing Then
MessageBox.Show ("Error - No network folder found")
Exit Sub
End If
For Each FolderItem In NetworkFolder.Items()
If FolderItem.Name = ConnectionName Then
Set LANConnection = FolderItem
Exit For
End If
Next
If LANConnection Is Nothing Then
MessageBox.Show ("Error - No LAN entry was not found")
Exit Sub
End If
LANEnable = Not LANEnable
Dim EnableVerbItem As Shell32.FolderItemVerb
Dim DisableVerbItem As Shell32.FolderItemVerb
Dim Verb As Shell32.FolderItemVerb
For Each Verb In LANConnection.Verbs
If Verb.Name = EnableVerb Then
Set EnableVerbItem = Verb
End If
If Verb.Name = DisableVerb Then
Set DisableVerbItem = Verb
End If
Next
DisableVerbItem.DoItأرجوا أن تكونو قد استفدتم
من هذا الكود ولا تنسونا أنا والأخ DreamNet من دعوة صالحة في ظهر الغيب
للأمانة العلمية الموضوع منقول من Vbcity
ولكنه مكتوب في Vbcity بلغة VB.Net تم تحويلة إلى VB6.0 عذراً للإطالة و السلام عليكم و رحمة الله وبركاته
هذا و الله أعلم



