#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: Chi-Khuong Nguyen #ce ---------------------------------------------------------------------------- #RequireAdmin #include #include #include #include #include #include #include #include #include #include #include $infos = _GetNetworkAdapterInfos("Ethernet") $info = _ArrayToString($infos) $split = StringSplit($info, "|") #Region ### START Koda GUI section ### Form= $NetworkInsert = GUICreate("Network Insert", 248, 312, 192, 124) $cbNetAdapList = GUICtrlCreateCombo("", 56, 48, 137, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL), $WS_EX_CLIENTEDGE) $lbNetAdapList = GUICtrlCreateLabel("Netzwerkadapter auswählen:", 56, 24, 142, 17) $Label1 = GUICtrlCreateLabel("", 64, 32, 4, 4) $Label2 = GUICtrlCreateLabel("IP-Adresse eingeben:", 72, 80, 105, 17) $inIPAdresse = _GUICtrlIpAddress_Create($NetworkInsert, 56, 104, 137, 21) $lbSubnetmask = GUICtrlCreateLabel("Subnetzmaske eingeben:", 64, 136, 124, 17) $inSubnetmask = _GUICtrlIpAddress_Create($NetworkInsert, 56, 160, 137, 21) $Label3 = GUICtrlCreateLabel("Standardgateway eingeben:", 56, 192, 137, 17) $inGateway = _GUICtrlIpAddress_Create($NetworkInsert, 56, 216, 137, 21) $btnAendern = GUICtrlCreateButton("Ändern", 88, 264, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($cbNetAdapList, $split[8]) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnAendern If Not IsAdmin() Then _LogonOnUser("Adminuser", "Adminpassword", "ad.ugs.net") _EnableStatic(GUICtrlRead($cbNetAdapList), _GUICtrlIpAddress_Get($inIPAdresse), _GUICtrlIpAddress_Get($inSubnetmask)) _SetGateways(GUICtrlRead($cbNetAdapList), _GUICtrlIpAddress_Get($inGateway)) _LogOffUser() EndIf EndSwitch WEnd Func _LogonOnUser($sUsername, $sPassword, $sServer = @LogonDomain) Local $aRet Local $stToken Local $phToken Local $nError = -1 $stToken = DllStructCreate("int") $aRet = DllCall("advapi32.dll", "int", "LogonUser", _ "str", $sUsername, _ "str", $sServer, _ "str", $sPassword, _ "dword", 8, _ ; LOGON32_LOGON_NETWORK_CLEARTEXT "dword", 0, _ "ptr", DllStructGetPtr($stToken)) $phToken = DllStructGetData($stToken, 1) If Not @error And $aRet[0] <> 0 Then ;Return True ; Return True if user exists $aRet = DllCall("advapi32.dll", "int", "ImpersonateLoggedOnUser", "ptr", $phToken) If Not @error And $aRet[0] <> 0 Then ConsoleWrite("Impersonated User = " & @UserName & @CRLF) ; Do Impersonation Stuff Here _InitiatePermissionResources() ; Requires Permissions UDF Else $aet = DllCall("kernel32.dll", "int", "GetLastError") If Not @error Then $nError = $aRet[0] EndIf DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $phToken) Else $aRet = DllCall("kernel32.dll", "int", "GetLastError") If Not @error Then $nError = $aRet[0] EndIf If $nError > -1 Then SetError($nError) Return 0 EndIf Return 1 EndFunc ;==>_LogOnUser Func _LogOffUser() _ClosePermissionResources() ; Requires Permissions UDF DllCall("advapi32.dll", "int", "RevertToSelf") ConsoleWrite("RevertToSelf User = " & @UserName & @CRLF) EndFunc