Цитата: неподскажеш как Функцию Отключения/Подключения к Интернету можно применить к VPN соединению, а то у меня неработает (((
???
Код: ; AutoIt Version: 3.0
; Language: English
; Platform: WinXP SP2 (Tested)
; Author: Kenneth Padgett / IT Lifesaver / kenneth@itlifesaver.com
; Version: 1.0
;
; Script Function:
; Creates a PPTP VPN connection on Windows XP clients
; to connect to the server info you provide
;
#NoTrayIcon
#compiler_icon=itlifesaver.ico
#include <GUIConstants.au3>
$COMPANY_NAME = "Work VPN" ; name of the VPN icon
$COMPANY_IP = "123.123.123.123" ; can be DNS name too
$ConfigureDNS = True ; true if script should set DNS servers, false if not
$COMPANY_DNS1 = "192.168.1.10"
$COMPANY_DNS2 = "" ; optional
$NotDefaultGW = True ; true if script should uncheck the 'Use remote network as default gateway', if you want inet traffic to go through the VPN, set to false
$DELAY = 100
$answer = MsgBox(4, "VPN Connection", "This script will create a VPN connection to " & $COMPANY_NAME & ", Ready?")
If $answer = 7 Then
Exit
EndIf
; Prompt user for VPN login info
$frmInformation = GUICreate("Enter Information", 287, 194, 193, 115)
$lblUserName = GUICtrlCreateLabel("User Name:", 16, 40, 60, 17)
$lblPassword = GUICtrlCreateLabel("Password:", 16, 80, 53, 17)
$txtUserName = GUICtrlCreateInput("", 112, 40, 153, 21)
$txtPassword = GUICtrlCreateInput("", 112, 80, 153, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
$lblPassword2 = GUICtrlCreateLabel("Confirm Password:", 16, 120, 91, 17)
$txtPassword2 = GUICtrlCreateInput("", 112, 120, 153, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
$btnOK = GUICtrlCreateButton("&OK", 200, 160, 75, 25, 0)
$lblInfo = GUICtrlCreateLabel("Enter your VPN Login Information Below!", 48, 8, 196, 17)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $btnOK
If GUICtrlRead($txtPassword) <> GUICtrlRead($txtPassword2) Then
MsgBox (16, "Error", "Passwords do not match! Try again.")
Else
$Username = GUICtrlRead($txtUsername)
$Password = GUICtrlRead($txtPassword)
ExitLoop
EndIf
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
GUISetState(@SW_HIDE)
; Run Network Setup
Run("control ncpa.cpl")
WinWaitActive("Network Connections")
; Check if VPN by same name already exists, since it'll break script later if Windows add's a number at the end of the name...
$ControlID = ControlListView("Network Connections", "", "SysListView321", "FindItem", $COMPANY_NAME, "Virtual Private Network")
If $ControlID <> -1 Then
$answer = MsgBox(4404, "Error", "VPN Connection to " & $COMPANY_NAME & " already exists! Remove it and recreate it?")
If $answer = 6 Then
ControlListView("Network Connections", "", "SysListView321", "Select", $ControlID)
Send("{DEL}")
WinWaitActive("Confirm Connection Delete")
Send("!y")
Sleep($DELAY)
Else
MsgBox(16, "Exit", "Script stopped by user")
Exit
EndIf
EndIf
; open new connection wizard from file menu
Send("!f")
Send("n")
WinWaitActive("New Connection Wizard")
Send("!n")
Sleep($DELAY)
; What do you want to do?
Send("!o")
Sleep($DELAY)
Send("!n")
Sleep($DELAY)
; How do you want to connect to the network at your workplace?
Send("!v")
Sleep($DELAY)
Send("!n")
Sleep($DELAY)
; Specifiy a name for this connection to your workplace.
Send($COMPANY_NAME)
Send("!n")
Sleep($DELAY)
; Windows can make sure the public network is connected first.
Send("!d")
Sleep($DELAY)
Send("!n")
Sleep($DELAY)
; What is the name or address of the VPN server?
Send($COMPANY_IP)
Send("!n")
Sleep($DELAY)
; Wizard Complete, do we want a desktop shortcut?
Send("!s")
Sleep($DELAY)
Send("{ENTER}")
WinWaitClose("New Connection Wizard")
WinWaitActive("Connect " & $COMPANY_NAME)
Send($Username)
Send("{TAB}")
Send($Password)
Sleep($DELAY)
Send("!s") ; save password...
Send("!a") ; for anyone who uses this computer, use "!n" for 'Me only'
Sleep($DELAY)
If $ConfigureDNS Or $NotDefaultGW Then
Send("!o") ; open Properties
WinWaitActive($COMPANY_NAME & " Properties")
Send("^{TAB 3}")
Sleep($DELAY)
Send("!o") ; highlight 'This connection uses the following items:'...
Sleep($DELAY)
; select TCP/IP from the listview:
$ControlID = ControlListView($COMPANY_NAME & " Properties", "", "SysListView321", "FindItem", "Internet Protocol (TCP/IP)")
If $ControlID = -1 Then
MsgBox(16, "Error", "Could not select TCP/IP, please finish setup manually")
Exit
EndIf
ControlListView($COMPANY_NAME & " Properties", "", "SysListView321", "Select", $ControlID)
Sleep($DELAY)
Send("!r") ; open properties
WinWaitActive("Internet Protocol (TCP/IP) Properties")
If $ConfigureDNS Then
Send("!e") ; Use the following DNS server addresses
Sleep($DELAY)
Send($COMPANY_DNS1)
Sleep($DELAY)
If $COMPANY_DNS2 <> "" Then
Send("{TAB}")
Send($COMPANY_DNS2)
Sleep($DELAY)
Endif
EndIf
If $NotDefaultGW Then
Send("!v")
WinWaitActive("Advanced TCP/IP Settings")
Send("!u") ; Uncheck 'Use default gateway on remote network'
ControlClick("Advanced TCP/IP Settings", "", 1) ; click OK
EndIf
WinWaitActive("Internet Protocol (TCP/IP) Properties")
ControlClick("Internet Protocol (TCP/IP) Properties", "", 1) ; click OK
WinWaitActive($COMPANY_NAME & " Properties")
ControlClick($COMPANY_NAME & " Properties", "", 1) ; click OK
EndIf
WinClose("Network Connections")