Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/26/2014 in all areas

  1. This is a method to test connectivity to the Internet using the same approach as Mircosoft does, therefore no need to contact third party sites such as google or bing, which has often been the case. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MicrosoftInternetConnectivity ; Description ...: Test if the local machine is connected to the Internet using the same method as Microsoft for 'network awareness' minus the dns records verification. ; Syntax ........: _MicrosoftInternetConnectivity() ; Parameters ....: None ; Return values .: Success: True ; Failure: False ; Author ........: guinness ; Remarks .......: This will contact the website www.msftncsi.com. Works with Windows 2000+ ; Requires TCPStartup() to be initialised. ; The function has a restriction of contacting Microsoft every 15 seconds, so if you call the function within a tight loop then the last response will ; be returned and @extended set to non-zero. ; Link ..........: http://technet.microsoft.com/en-us/library/cc766017(v=ws.10).aspx#BKMK_How ; Example .......: Yes ; =============================================================================================================================== Func _MicrosoftInternetConnectivity() Local Static $hTimer = 0, _ ; Create a static variable to store the timer handle. $bLastResponse = Null ; Create a static variable to store the last response. If TimerDiff($hTimer) < 15000 And Not ($bLastResponse = Null) Then ; If still in the timer and $bLastResponse contains a value. Return SetExtended(1, $bLastResponse) ; Return the last response instead and set @extended to 1. EndIf Local $bEnableActiveProbing = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'EnableActiveProbing') > 0 If @error Then $bEnableActiveProbing = True EndIf If Not $bEnableActiveProbing Then Return False EndIf Local $sContent = 'Microsoft NCSI', _ $sDNSHost = 'dns.msftncsi.com', _ $sDNSIPAddress = '131.107.255.255', _ $sURL = 'http://' & RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbeHost') & '/' & RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbePath') If $sURL == 'http:///' Then $sURL = 'http://www.msftncsi.com/ncsi.txt' Else $sContent = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbeContent') $sDNSIPAddress = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveDnsProbeContent') $sDNSHost = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveDnsProbeHost') EndIf $bLastResponse = BinaryToString(InetRead($sURL, $INET_FORCERELOAD)) == $sContent And TCPNameToIP($sDNSHost) == $sDNSIPAddress Return $bLastResponse EndFunc ;==>_MicrosoftInternetConnectivity Example use of Function: #include <InetConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() TCPStartup() Local $bConnected = _MicrosoftInternetConnectivity() MsgBox($MB_SYSTEMMODAL, '', 'Is the Internet working?: ' & ($bConnected ? 'Yes, the Internet is working.' : 'No, the Internet isn''t working.')) TCPShutdown() EndFunc ;==>Example
    1 point
  2. Actually C:Documents and Settings would be the same folder as C:Users and what you're seeing is a junction point and not a real folder name. To detect whether a listed folder is actually a junction point, you can use this code. #include <WinAPIFiles.au3> BitAND(_WinAPI_GetFileAttributes ("C:\Documents and Settings\"), $FILE_ATTRIBUTE_REPARSE_POINT) <> 0 This returns True if the Reparse_Point attribute is set, and false if it's not.
    1 point
  3. Don't you just love it when a regular expression comes out on top?! I know I do.. Local $hTimer = 0 $hTimer = TimerInit() For $i = 1 To 10000 _IsSystemDrive_Test_1('C') Next ConsoleWrite(TimerDiff($hTimer) & @CRLF) $hTimer = TimerInit() For $i = 1 To 10000 _IsSystemDrive_Test_2('C') Next ConsoleWrite(TimerDiff($hTimer) & @CRLF) Func _IsSystemDrive_Test_1($sDrive) Local $aArray = [@HomeDrive, _ @ProgramFilesDir, _ @SystemDir, _ @WindowsDir] For $sFilePath In $aArray If StringLeft($sFilePath, 1) = $sDrive Then Return True EndIf Next Return False EndFunc ;==>_IsSystemDrive Func _IsSystemDrive_Test_2($sDrive) Return StringRegExp(@HomeDrive & '|' & @ProgramFilesDir & '|' & @SystemDir & '|' & @WindowsDir, '(?<=^|\|)(?:' & $sDrive & ')') = 1 EndFunc ;==>_IsSystemDrive I am no expert at regular expressions, but what I have managed to learn has proved very useful over the last couple of years.
    1 point
  4. love2u

    Program Starter

    I updated above script. Thanks. ; setup ini file like "settings.ini" #cs [Settings1] name=irfanview path_exe=C:\Programme\IrfanView\i_view32.exe verz_ausfuerung=C:\Programme\IrfanView autostart=1 #ce TraySetIcon("ProgramStarter.ico") Opt("TrayAutoPause", 0) Opt("TrayOnEventMode", 1) #include <GUIConstants.au3> #include <Array.au3> #include <Process.au3> #include <WinAPI.au3> #Include <Constants.au3> ; Demonstrates StdoutRead(),StderrRead Local $aboutitem = TrayCreateItem("Show Window") TrayItemSetOnEvent(-1, "showhidengui") ; ------------------- Options ---------------------------------- ; Options , nicht den dialog mit esc schliessen Opt("GUICloseOnESC", 0) ;Opt("RunErrorsFatal", 0) ; silent ; set @error to 1 !! Global $glob_inilocation = @ScriptDir & "\settings.ini" ; generelles INI - einzelne inis folgen noch ! Global $glob_max_processes = 100; start a max number -- Dim $process_id[$glob_max_processes] ;## process iD for start / stop. Dim $process_name[$glob_max_processes] ;## name "view.exe" Dim $process_path[$glob_max_processes] ;## \pathname\.. Dim $process_running[$glob_max_processes] ;## running true / false?? Dim $process_autostart[$glob_max_processes] ;## Auto start it ?? Dim $checkbox[$glob_max_processes] ;## checkbox if process is to be started ? Dim $btn_start[$glob_max_processes] ;## button start this process Dim $btn_stop[$glob_max_processes] ;## button stop this process Dim $btn_restart[$glob_max_processes] ;## button restart this process Global $glob_nbr_entries = 0; total number in array .. #Region ### START Koda GUI section ### Form=Program_starter.kxf $Form1 = GUICreate("Program Starter", 550, 767, 193, 115) GUISetIcon ("ProgramStarter.ico") GUISetState (@SW_SHOW) #EndRegion ### START Koda GUI section $Button_Hide = GUICtrlCreateButton("Hide", 400, 8, 50,25) ; read in settings .. ; generate dynamic labels after start of GUI !! _read_ini_file() ; ------ start -------------------------------------------------------- Do $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ;MsgBox(64, "Stop", "Programm Then exit and closed all border lauff task") $exithide = MsgBox(1, "Exit/Hide", "Yes = Exit" & @LF & "Cancel = Hide",0,$Form1) If ($exithide == 1) Then ExitLoop If ($exithide == 2) Then GUISetState(@SW_HIDE,$Form1) ;ExitLoop EndSelect Select Case $msg = $Button_Hide GUISetState(@SW_HIDE,$Form1) EndSelect ; ; outside the case main loop !! ; ; all buttons now ?? For $irun = 1 To $glob_nbr_entries ; stop button 1 ... x If $msg = $btn_stop[$irun] Then p_stop() EndIf ; start button 1 ... x If $msg = $btn_start[$irun] Then p_start() EndIf ; restart button 1 ... x If $msg = $btn_restart[$irun] Then p_stop() p_start() EndIf Next ;Until $msg = $GUI_EVENT_CLOSE Until False Func _read_ini_file() Local $ret = ""; Local $y_start = 40; For $i = 1 To $glob_max_processes - 1 ; [settings1 - 99] $sett = "settings" & $i; ; read first entry .. $ret = IniRead($glob_inilocation, $sett, "name", "ERROR") If $ret <> "ERROR" Then $glob_nbr_entries = $i $process_name[$i] = $ret $val = "path_exe"; $process_path[$i] = IniRead($glob_inilocation, $sett, $val, "") $val = "autostart" $process_autostart[$i] = IniRead($glob_inilocation, $sett, $val, "") ; build gui.. $checkbox[$i] = GUICtrlCreateCheckbox($process_name[$i], 16, $y_start, 260, 18) $btn_start[$i] = GUICtrlCreateButton("Start", 300, $y_start, 75, 20, 0) $btn_stop[$i] = GUICtrlCreateButton("Stop", 378, $y_start, 75, 20, 0) $btn_restart[$i] = GUICtrlCreateButton("Restart", 466, $y_start, 75, 20, 0) GUICtrlSetState($btn_stop[$i], $GUI_DISABLE) $y_start += 25 ; _DebugPrint("Name " & $process_name[$i]); ; is it autostart ??? If $process_autostart[$i] > 0 Then ;If FileExists($process_path[i])=0 Then MsgBox(4096, "File Error" , $process_path[i] & @CRLF & "Does NOT exists") $process_id[$i] = Run($process_path[$i]) If @error <> 1 Then ; no error ?? GUICtrlSetState($btn_start[$i], $GUI_DISABLE) GUICtrlSetState($btn_stop[$i], $GUI_ENABLE) Sleep(6000) EndIf ; no error EndIf ;; autostart EndIf Next ; alle $i GUISetState(@SW_HIDE,$Form1) ; Ths Script will hide GUI after all programms run on start. You can activate it from tray. EndFunc ;_read_ini_file ; print s debug text in CONSOLE view of scite.. Func _DebugPrint($s_text) $s_text = StringReplace($s_text, @LF, @LF & "-->") ConsoleWrite($s_text & @LF & "+===========================================================" & @LF) EndFunc Func showhidengui() GUISetState(@SW_SHOW,$Form1) EndFunc Func CloseProcessByPID($pid1) ; http://www.autoitscript.com/forum/topic/61571-simple-taskkill-script-solved/ $runString = StringFormat("taskkill /PID %s", $pid1) ;MsgBox(0,"runstring",$runString) $run = Run($runString, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($run) If @error Then ExitLoop If $line<>"" Then MsgBox(0, "Sucess:", $line,3000,$Form1) Wend If @error=0 Then Return 1 While 1 $line = StderrRead($run) If @error Then ExitLoop If $line<>"" Then MsgBox(0, "Error:", $line,3000,$Form1) WEnd If @error=0 Then Return 0 EndFunc Func p_stop() If ProcessExists($process_id[$irun]) Then ;$rc = ProcessClose($process_id[$irun]) $rc = CloseProcessByPID($process_id[$irun]) GUICtrlSetState($btn_start[$irun], $GUI_ENABLE) GUICtrlSetState($btn_stop[$irun], $GUI_DISABLE) Else $pclosed = MsgBox(4,"Process does not exist", "Do you closed the process? " & $process_path[$irun],5000,$Form1) If $pclosed == 6 Then GUICtrlSetState($btn_start[$irun], $GUI_ENABLE) GUICtrlSetState($btn_stop[$irun], $GUI_DISABLE) ElseIf $pclosed == 7 Then MsgBox(1,"PID Does Not Exist", "Please close the process manually. " & $process_path[$irun],5000,$Form1) EndIf EndIf EndFunc Func p_start() $process_id[$irun] = Run($process_path[$irun]) If @error <> 1 Then ; no error ?? GUICtrlSetState($btn_start[$irun], $GUI_DISABLE) GUICtrlSetState($btn_stop[$irun], $GUI_ENABLE) EndIf ; no error EndFunc
    1 point
  5. UEZ

    what function print Screen ?

    If you have Vista or a higher operating system you can try out >AutoIt Windows Screenshooter. Just push "Screenshot a Web Site", type your URL and see whether it works. Br, UEZ
    1 point
  6. Jfish

    key down not work ?

    @jguinch - I ran the code with and without the captalized w. I would have expected it to keep sending an "a" as in "aaaaaaaaaaaaaaaaaaaaaaa" until you press "e". It did not. It only sent one "A" when "w" was pressed. The code I posted simulates what I think he wants to happen but I confess I don't understand why the down key does not work that way (or maybe I don't understand how it is supposed to work).
    1 point
  7. jguinch

    key down not work ?

    What is "{W}" ? Try with just "w" instead
    1 point
  8. Here's a basic example (NOTE: coded for 3.2.10.0 (work mandate - we haven't migrated versions yet) so if running 3.2.12.x, you'll likely need to change the GUIContants.au3 include to GUIConstantsEx.au3 if I remember correctly from the change notes): #include <GUIConstants.au3> AutoItSetOption("GUIOnEventMode", 1) $GUITitle = "Listview Item Recolor" $GUIWidth = 400 $GUIHeight = 300 $GUI = GUICreate($GUITitle, $GUIWidth, $GUIHeight, (@DesktopWidth - $GUIWidth) / 2, (@DesktopHeight - $GUIHeight) / 2) $listviewStuff = GUICtrlCreateListView("Listview stuff", 10, 10, $GUIWidth - 20, $GUIHeight - 50) $buttonselected = GUICtrlCreateButton("Tag selected item", 10, $GUIHeight - 30, $GUIWidth - 20, 20) $iListviewCount = 20 GUICtrlCreateListViewItem("Index 0", $listviewStuff) For $i = 1 To $iListviewCount GUICtrlCreateListViewItem("Index " & $i, $listviewStuff) Next GUISetState() #Region Events list GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitIt") GUICtrlSetOnEvent($buttonselected, "_TagSelected") #EndRegion Events list While 1 Sleep(10) WEnd Func _ExitIt() Exit EndFunc Func _TagSelected() $selected = GUICtrlRead(GUICtrlRead($listviewStuff)) GUICtrlSetColor(GUICtrlRead($listviewStuff), 0xff00ff) GUICtrlSetBkColor(GUICtrlRead($listviewStuff), 0x00ffff) ConsoleWrite($selected & @CRLF) EndFunc
    1 point
×
×
  • Create New...