Leaderboard
Popular Content
Showing content with the highest reputation on 08/21/2012 in all areas
-
Run consecutive commands based on return value?
richietheprogrammer reacted to blademonkey for a topic
looks like you're doing a @comspec /k which lingers and doesn't autoterminate. i believe you want to use /c not /k.1 point -
There are no dumb questions and a quest for knowledge should never leave one embarrassed. Everything was over my head until I learned ... Njoy1 point
-
Try this: Local $Result = RunWait(@ComSpec & ' /c wevtutil qe Application /q:"*[System[Provider[@Name=' & "'EMET']]]" & '" /rd:true /c:1 /f:text > c:EMET.log', @SystemDir, @SW_SHOW)1 point
-
@VijayS Declaring some more of the variables seems to have helped. #NoTrayIcon #RequireAdmin #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #include <Constants.au3> #include <GUIConstantsEx.au3> #include <Array.au3> #include <Date.au3> ; This script requires full Administrative rights Opt("MustDeclareVars", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. TraySetClick(16) ; Only secondary mouse button will show the tray menu. TrayCreateItem("Info") TrayItemSetOnEvent(-1, "IP1Pressed") TrayCreateItem("Renew") TrayItemSetOnEvent(-1, "RenewPressed") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "IP1Pressed") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "RenewPressed") TraySetState() IP1Pressed() Global $oldIP, $newIP, $oldDNS, $newDNS, $stitle, $log CheckChange(False) ;CheckChange(False) While 1 Sleep(5000) ; Idle loop CheckChange() WEnd Exit ; Functions Func ExitScript() Exit EndFunc ;==>ExitScript Func VerPressed() Run("winver") EndFunc ;==>VerPressed Func IP1Pressed($stitle = "IP Addresses", $log = True) Local $stmp = _IPDetails(1) TrayTip($stitle, $stmp, 5, 1) If $log Then WriteLog($stitle & @CRLF & $stmp) ;MsgBox(64, "IP Addresses",$stmp) EndFunc ;==>IP1Pressed Func CheckChange($log = True) $oldIP = $newIP $oldDNS = $newDNS $newIP = @IPAddress1 $newDNS = GetDNS() Local $rIP = $oldIP <> $newIP Local $rDNS = $oldDNS <> $newDNS If ($log) Then If $rIP Then IP1Pressed("IP CHANGED", $log) MsgBox(64, "Debug IP DNS", "DNS:" & $oldDNS & " " & $newDNS & $rDNS & @CRLF & "IP:" & $oldIP & " " & $newIP & $rIP) EndIf If $rDNS Then IP1Pressed("DNS CHANGED", $log) MsgBox(64, "Debug IP DNS", "DNS:" & $oldDNS & " " & $newDNS & $rDNS & @CRLF & "IP:" & $oldIP & " " & $newIP & $rIP) EndIf EndIf ;$curr = GetIP (or get dns) or whatever else you want to monitor EndFunc ;==>CheckChange Func GetDNS() ;Occasionally returns none!, even when there are valid entries. TOFIX Local $sResult, $line Local $hRun = Run(@ComSpec & " /c netsh interface ip show dns", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($hRun) If @error Then ExitLoop $sResult &= $line WEnd ;$answer1 = StringRegExp($sResult,'((?:d+)(?:.d+){3})',3) Local $sString = StringRegExp($sResult, '((?:[1-2]?[0-9]?[0-9].){3}(?:[1-2]?[0-9]?[0-9]))', 3) $sString = _ArrayToString($sString) ;MsgBox(64,"DNS:",$sResult & "capture:" & $sString) Return $sString EndFunc ;==>GetDNS Func WriteLog($Data, $FileName = -1, $TimeStamp = True) If $FileName == -1 Then $FileName = @ScriptDir & '' & @ScriptName & '.Log' Local $hFile = FileOpen($FileName, 1) If $hFile <> -1 Then If $TimeStamp = True Then $Data = _Now() & ' - ' & $Data FileWriteLine($hFile, $Data) FileClose($hFile) EndIf EndFunc ;==>WriteLog ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func ReleasePressed() Local $IP_Address = _RunStdOutRead('ipconfig /release') $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(d+.d+.d+.d+).*{:content:}quot;", "1") MsgBox(64, "Release IP Address", StringFormat("Your IP Address is: %s", $IP_Address)) EndFunc ;==>ReleasePressed Func RenewPressed() Local $IP_Address = _RunStdOutRead('ipconfig /renew') $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(d+.d+.d+.d+).*{:content:}quot;", "1") MsgBox(64, "Renew IP Address", StringFormat("Your IP Address is: %s", $IP_Address)) EndFunc ;==>RenewPressed Func FlushPressed() Local $IP_Address = _RunStdOutRead('netsh int ip delete arpcache & ipconfig/flushdns') $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(d+.d+.d+.d+).*{:content:}quot;", "1") MsgBox(64, "Flush DNS", StringFormat("%s", $IP_Address)) EndFunc ;==>FlushPressed Func TCPIPPressed() Local $IP_Address = _RunStdOutRead('netsh int ip reset resetlog.txt & netsh winsock reset') $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(d+.d+.d+.d+).*{:content:}quot;", "1") MsgBox(64, "Reset TCP/IP & Winsock", StringFormat("%s", $IP_Address)) EndFunc ;==>TCPIPPressed ;Function to read from Command Line process. Func _RunStdOutRead($sRunCmd) Local $iPID = Run(@ComSpec & ' /c ' & $sRunCmd, @ScriptDir, @SW_HIDE, 4 + 2) Local $sStdOutRead = "" While ProcessExists($iPID) $sStdOutRead &= StdoutRead($iPID) WEnd Return $sStdOutRead EndFunc ;==>_RunStdOutRead Func Ping4Pressed() Local $IP_Address = _RunStdOutRead('ping www.google.com') $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(d+.d+.d+.d+).*{:content:}quot;", "1") MsgBox(64, "Ping Out By URL", StringFormat("%s", $IP_Address)) EndFunc ;==>Ping4Pressed Func InetPressed() Run("control inetcpl.cpl") WinWait("Internet Options", "", 5) EndFunc ;==>InetPressed Func ServPressed() Local $File = @SystemDir & "services.msc" Run(@SystemDir & "mmc.exe " & $File) EndFunc ;==>ServPressed Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Case @GUI_CtrlId = $GUI_EVENT_RESTORE MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) EndSelect EndFunc ;==>SpecialEvents Func _IPDetails($num = 100) Local $totalReturn = "" Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!" & "." & "rootcimv2") Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", "WQL", 0x30), $aReturn[6] = [5] Local $count = 0 If IsObj($oColItems) Then For $oObjectItem In $oColItems If IsString($oObjectItem.IPAddress(0)) Then $count += 1 ;MsgBox(64,"debug",$count & '/' & $num) If ($count > $num) Then ExitLoop ;limiting the number of adapters to show If IsString($oObjectItem.Description) Then $aReturn[1] = "Description:" & @TAB & $oObjectItem.Description Else $aReturn[1] = "Description:" & @TAB & "Not Available" EndIf If IsString($oObjectItem.IPAddress(0)) Then $aReturn[2] = "IP Address:" & @TAB & $oObjectItem.IPAddress(0) Else $aReturn[2] = "IP Address:" & @TAB & "Not Available" EndIf If IsString($oObjectItem.DefaultIPGateway(0)) Then $aReturn[3] = "Default Gateway:" & @TAB & $oObjectItem.DefaultIPGateway(0) Else $aReturn[3] = "Default Gateway:" & @TAB & "Not Available" EndIf If IsArray($oObjectItem.DNSServerSearchOrder()) Then $aReturn[4] = "DNS Servers:" & @TAB & _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ") Else $aReturn[4] = "DNS Servers:" & @TAB & "Not Available" EndIf If IsString($oObjectItem.MACAddress) Then $aReturn[5] = "MAC: " & @TAB & @TAB & $oObjectItem.MACAddress Else $aReturn[5] = "MAC: " & @TAB & @TAB & "Not Available" EndIf $totalReturn &= $aReturn[1] & @CRLF & $aReturn[2] & @CRLF & $aReturn[3] & @CRLF & $aReturn[4] & @CRLF & $aReturn[5] & @CRLF & @CRLF EndIf Next Return StringTrimRight($totalReturn, 4) EndIf Return SetError(1, 0, $aReturn) EndFunc ;==>_IPDetails Func _WMIArrayToString($aArray, $sDelimeter = "|") If IsArray($aArray) = 0 Then Return SetError(1, 0, "") EndIf Local $iUbound = UBound($aArray) - 1, $sString For $A = 0 To $iUbound $sString &= $aArray[$A] & $sDelimeter Next Return StringTrimRight($sString, StringLen($sDelimeter)) EndFunc ;==>_WMIArrayToString Hope this helps, -Mike P.S. You may want to move this to a new thread if you still need help, and just reference the old thread as your source of inspiration.1 point
-
Reading data from a text file...
BrandNewTester reacted to kylomas for a topic
BrandNewTester, Long, boring afternoon so I cleaned up the code a bit and added a function to create a formatted output file. Enjoy! #include <Array.au3> Opt("MustDeclareVars", 1) local $string = "12345:a100:a200:9876:0:dfgh" & @crlf & _ "string:z43:%:6:0" & @crlf & _ "str:z:%the:9876:0:dfgh:what:the :hell" & @crlf & _ "basketball" & @crlf & @crlf & "this:is:an:example:row:following1234567890:a:blank:row" & @lf & "123456789:for:@lf:mixed:with:@CRLF" local $result_array = _stringsplit2d($string,":") _arraydisplay($result_array) _print2d_array($string,":","c:dsdtemptest.txt") run ("notepad.exe " & "c:dsdtemptest.txt") ; #FUNCTION# ====================================================================================== ; Name ................: _stringsplit2d($str,$del) ; Description .........: create 2d array where each row is a @lf delimited text string comprised ; of columns delimited by a user defined string ; Syntax ..............: StringSplitW($str, $del) ; Parameters ..........: $str - string to split ; $del - the delimter for columns ; ================================================================================================= func _stringsplit2d($str,$del) local $a1 = stringsplit($str,@lf,1), $a2 local $rows = ubound($a1),$cols = 0 ; determine max number of columns by splitting each row and keeping highest ubound value for $i = 0 to ubound($a1) - 1 $a2 = stringsplit($a1[$i],$del,1) if ubound($a2) > $cols then $cols = ubound($a2) next ; define and populate array local $o[$rows][$cols] for $i = 1 to $rows - 1 $a2 = stringsplit($a1[$i],$del,1) for $j = 0 to ubound($a2) - 1 $o[$i][$j] = $a2[$j] Next next return $o endfunc ; #FUNCTION# ====================================================================================== ; Name ................: _print2d_array($str,$del$output_file_name) ; Description .........: create a formatted text file from a 2d array ; Syntax ..............: StringSplitW($str, $del) ; Parameters ..........: $str - string to split ; $del - the delimter for columns ; $output_file_name - fully qualified output file name ; ================================================================================================= Func _print2d_array($str,$del,$output_file_name) $str = stringregexpreplace($str,@crlf,@lf) Local $a10 = StringSplit($str,@lf,3), $numcols = 0, $a20, $matrix = "" ; find max number of columns For $i = 0 To UBound($a10) - 1 $a20 = StringSplit($a10[$i],$del) if ubound($a20) > $numcols then $numcols = ubound($a20) Next ; find max size of each column local $colsize[$numcols] For $i = 0 To UBound($a10) - 1 $a20 = StringSplit($a10[$i],$del) For $j = 0 To $a20[0] If StringLen($a20[$j]) > $colsize[$j] Then $colsize[$j] = StringLen($a20[$j]) + 5 Next Next ; now format the output line For $i = 0 To UBound($a10) - 1 $a20 = StringSplit($a10[$i],$del) For $j = 0 To $a20[0] $matrix &= StringFormat("%-" & $colsize[$j] & "s",$a20[$j]) & "|" Next $matrix &= @CRLF next ; and finally write the output file local $hfl = FileOpen($output_file_name,2) FileWrite($hfl,$matrix) FileClose($hfl) $hfl = 0 endfunc kylomas1 point -
I can't seem to get this working. Even in the examples the control just isn't getting made. o_0; I've tried several different sources of the dll at this point but nothing works. Windows 7 64 bit1 point
-
Damn, I thought I'd checked them all. Thanks.1 point