Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Новый участник


Сообщения: 20
Благодарности: 1

Профиль | Отправить PM | Цитировать


Дополнил код по сетевым интерфейсам.
Не могу понять почему не получается обновить информацию по состоянию интерфейса после включения / выключения.
Мож кто подскажит.
Код: Выделить весь код
#include <GUIConstants.au3>
#include <GuiCombo.au3>
#NoTrayIcon
Dim $i=1
Dim $NetArr[$i+1][6]
$objShare = ObjCreate("HNetCfg.HNetShare.1")
$shellApp = ObjCreate("Shell.Application")
; GUI ------------------------------------------------------
$Form1 = GUICreate("Сетевые подключения", 350, 198)
GuiSetIcon("netshell.dll", 100)
$Combo1 = GUICtrlCreateCombo("Подключения", 16, 16, 320, 21)
$Button1 = GUICtrlCreateButton("Вкл / Выкл", 100, 145, 150, 35)
$Label1 = GUICtrlCreateLabel("Выберите подключение", 16, 48, 320, 81, $BS_PUSHLIKE)
Data($NetArr, $objShare)
For $n = 1 To $NetArr[0][0]
	GUICtrlSetData($Combo1,$NetArr[$n][1])
Next	
GUISetState(@SW_SHOW)
While 1
	$msg = GuiGetMsg()
  Select
	Case $msg = $GUI_EVENT_CLOSE
		ExitLoop
	Case $msg = $Combo1
		$n = _GUICtrlComboGetCurSel($Combo1)
		If $n > 0 Then
        Output($n)
	    Else
		  GUICtrlSetData($Label1, "Выберите подключение")
	    EndIf
	Case $msg = $Button1
        $oNetConnections = $shellApp.Namespace(0x00000031)
        For $folderitem in $oNetConnections.items
		  For $verb in $folderitem.verbs
            if $folderitem.name = $NetArr[$n][1] Then
              $verb.DoIt
              Sleep(1000)
              ExitLoop 2
            EndIf 
          Next
        Next
        If $folderitem.name <> $NetArr[$n][1] Then msgbox(48, "Ошибка", "Имя соединения указанно не правильно")
		GUICtrlSetData($Label1,"Ждите")
        Output($n)
  EndSelect
WEnd
Exit
; Func -------------------------------------------------------
Func Data(ByRef $NetArr, $objShare)
  If $objShare = 0 Then 
	  MsgBox(48, "Внимание", "Сетевых подключений не найдено", 5)
	  Exit
  EndIf
  $objEveryColl = $objShare.EnumEveryConnection
  If $objEveryColl <> 0 Then
	For $objNetConn In $objEveryColl
	  $objShareCfg = $objShare.INetSharingConfigurationForINetConnection($objNetConn)
	  If $objShareCfg <> 0 Then
		$objNCProps = $objShare.NetConnectionProps($objNetConn)
		If $objNCProps <> 0 Then
			ReDim $NetArr[$i+1][6]
			Select
				Case  $objNCProps.Status = 0
                    $Status = "The connection is disconnected."
				Case  $objNCProps.Status = 1
                    $Status = "The connection is in the process of connecting."
				Case  $objNCProps.Status = 2
                    $Status = "The connection is in a connected state."
				Case  $objNCProps.Status = 3
                    $Status = "The connection is in the process of disconnecting."
				Case  $objNCProps.Status = 4
                    $Status = "The hardware for the connection, for example network interface card (NIC), is not present."
				Case  $objNCProps.Status = 5
                    $Status = "The hardware for the connection is present, but is not enabled."
				Case  $objNCProps.Status = 6
                    $Status = "A malfunction has occurred in the hardware for the connection."
				Case  $objNCProps.Status = 7
                    $Status = "The media, for example the network cable, is disconnected."
				Case  $objNCProps.Status = 8
                    $Status = "The connection is waiting for authentication to occur."
				Case  $objNCProps.Status = 9
                    $Status = "Authentication has succeeded on this connection."
				Case  $objNCProps.Status = 10
                    $Status = "Authentication has failed on this connection."
				Case  $objNCProps.Status = 11
                    $Status = "The address is invalid."
				Case  $objNCProps.Status = 12
                    $Status = "Security credentials are required."
			EndSelect
			Select
				Case $objNCProps.MediaType = 0 
                    $MediaType = "No media is present."
				Case $objNCProps.MediaType = 1
                    $MediaType = "Direct serial connection through a serial port."
				Case $objNCProps.MediaType = 2
                    $MediaType = "Connection is through an integrated services digital network (ISDN) line."
				Case $objNCProps.MediaType = 3
                    $MediaType = "Connection is to a local area network (LAN)."
				Case $objNCProps.MediaType = 4
                    $MediaType = "Dial-up connection over a conventional phone line."
				Case $objNCProps.MediaType = 5
                    $MediaType = "Virtual private network (VPN) connection."
				Case $objNCProps.MediaType = 6
                    $MediaType = "Point-to-Point protocol (PPP) over Ethernet."
				Case $objNCProps.MediaType = 7
                    $MediaType = "Bridged connection."
				Case $objNCProps.MediaType = 8
                    $MediaType = "Shared connection to a LAN."
				Case $objNCProps.MediaType = 9
                    $MediaType = "Shared connection to a remote or wide area network (WAN)."
			EndSelect
			$NetArr[$i][1] = $objNCProps.Name
			$NetArr[$i][2] = $objNCProps.Guid
			$NetArr[$i][3] = $objNCProps.DeviceName
			$NetArr[$i][4] = $Status
			$NetArr[$i][5] = $MediaType
			$NetArr[0][0] = $i  ; Общее кол-во
			$i = $i + 1
		  EndIf
	  EndIf
	Next
  EndIf
Return $NetArr
EndFunc
Func Output($n)
	GUICtrlSetData($Label1, _ 
	      "- Name: "       & $NetArr[$n][1] & @CRLF & _
	      "- Device Name: " & $NetArr[$n][3] & @CRLF & _
	      "- Status: "     & $NetArr[$n][4] & @CRLF & _
	      "- Media Type: "  & $NetArr[$n][5] & @CRLF)
	      ;"- Guid: "       & $NetArr[$n][2]
EndFunc

Отправлено: 00:30, 16-08-2006 | #287