Jump to content

driverj

Members
  • Posts

    3
  • Joined

  • Last visited

driverj's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. I ended up using a variant of your suggestion WinGetTitle("[REGEXPTITLE:( " & $RowCounter & " \( \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} \))]") This is now working perfectly, when it is ran for a one at a time instance, thank you! Thank you so much for your help! Working code: Added some Log Tracking and log file, Fixed some windows close issues, Looking into Functions now. This is the complete code I am working with in case anyone has ideas while I fiddle with it, #include <array.au3> #include <file.au3> #include <constants.au3> Global $command= 0 Global $command2= 0 Global $command3= 0 Dim $oneDarray ;CSV File of computers to connect to _FileReadToArray("PATH:\TO\CSVFILE.csv", $oneDarray,$FRTA_NOCOUNT) ;Play sound bite at start of script SoundPlay("PATH:\TO\start.wav", 1) ;include script compiled to exe that will Close the Authentication Rejection, runs in background Local $iPID = Run("PATH:\TO\CAR.exe", "", @SW_SHOWMINIMIZED) For $y =0 To UBound($oneDarray) -1 $columnsCounter = stringsplit($oneDarray[$y],",") For $x= 1 To UBound($columnsCounter)-1 Dim $RowCounter=$columnsCounter[$x] ;save code space added variable to house the launch command. $command= @ProgramFilesDir & "\UltraVNC\vncviewer.exe -connect " & $RowCounter & " -password ULTRAVNCPASSWORD" ;save code space added variable to hold code for window selection. $ultraVNC= "[REGEXPTITLE:( " & $RowCounter &" \( \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} \))]" Local $iPID = run($command) $stillLooking = True While $stillLooking $activeWindowTitle = WinGetTitle($ultraVNC) ;I want to find the window that is open for this instance, sleep for 6 seconds if no response ;it's okay to close the window or enter credentials. sleep(3000) ;If the window is found, run the log in part. If StringinStr(WinGetTitle("[ACTIVE]"),"- service mode") Then Send("WINDOWSUSERNAME") Send("{tab}") Sleep(1000) Send("WIDNOWSPASSWORD") Send("{enter}") Sleep(2000) $stillLooking = False ;But what if the computer is offline and not responding? Close and move on! Else ;Closes open dialogue window Send("{space}") $stillLooking = False ;done with If statement EndIf sleep(1000) WEnd Next Next $command2= "taskkill /F /IM vncviewer.exe" $command3= "taskkill /F /IM CAR.exe" ;Close open UltraVNC Windows Local $iPID = run($command2) ;Close CAR.exe Local $iPID = run($command3) sleep(2000) ;Sound bite at end of script to indicate completion SoundPlay("PATH:\TO\finished.wav", 1) ;Messagebox at end of script to indicate completion MsgBox(0, "Completed", "Job Finished, Check log file for Errors!") CAR.exe #include <Date.au3> ;needed for Date and Time #include <MsgBoxConstants.au3> ;needed for messageboxes #include <String.au3> ;needed for StringBetween #include <File.au3>;needed for FileWriteFromArray ;file paths Global $sFilePath = "PATH:\TO\Log.txt" Global $sTempFile = "PATH:\TO\CaughtMachines.txt" ;error messages Global $eTempFile = "An error occurred while writing to temp file." Global $ErrorLog = "Error Log " & _NowDate() & ":" & @CRLF ;set hotkey for termination HotKeySet("+!c","Terminate") ; Shift+Alt+c ;counters for errors Global $w=0 ;connection issue Global $u=0 ;rejected authentication $stillLooking = True While $stillLooking If WinActive("VncViewer Message Box","rejected") then Call("RejectedLog") ElseIf WinActive("VncViewer Message Box","Failed") then Call("FailedLog") EndIf WEnd Func RejectedLog() ;rejected Authentication ;retrieve the window text of the active window. Local $sText = WinGetText("VNC Viewer Status for") ;look for text matching machine name Local $sString = _StringBetween($sText, "VNC Server:", "Status:") ;if it exists and is an array then write the name to a temp file If IsArray($sString) Then Local $newString = StringReplace($sString[0],"" ,"") $PathToYourFileInclusiveName = $sTempFile _FileWriteFromArray($PathToYourFileInclusiveName, $sString) ;log the temp file to a variable Local $RowCounter = FileRead($sTempFile) ;close the open window ControlClick("VncViewer Message Box","","[CLASS:Button; INSTANCE:1]", "left") $stillLooking = True ;True to keep looking for windows, False to close after window has been found and call again when needed ;add one to the log tracker $w = $w +1 ;check to see if log file exists, if not, create it and add Error Log title, otherwise open and write to the file If Not FileExists($sFilePath) then FileWrite($sFilePath, $ErrorLog) Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", $eTempFile) Return False EndIf ;writes to log file including variable from above for computer name FileWriteLine($hFileOpen, _NowDate() & " " & _NowTime() & " - " & "Authentication rejected - " & $RowCounter) Else ;create a log file to write to If Not FileWrite($sFilePath, "") Then MsgBox($MB_SYSTEMMODAL, "", $eTempFile) Return False EndIf ;opens log file Local $hFileOpen = FileOpen($SFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", $eTempFile) Return False EndIf ;writes to log file including variable from above for computer name FileWriteLine($hFileOpen, _NowDate() & " " & _NowTime() & " - " & "Authentication rejected - " & $RowCounter) ;close the log file FileClose($hFileOpen) EndIf EndIf sleep(1000) EndFunc Func FailedLog() ;conection issue ;retrieve the window text of the active window. Local $sText = WinGetText("VNC Viewer Status for") ;look for text matching machine name Local $sString = _StringBetween($sText, "VNC Server:", "Status:") ;if it exists and is an array then write the name to a temp file If IsArray($sString) Then Local $newString = StringReplace($sString[0],"" ,"") $PathToYourFileInclusiveName = $sTempFile _FileWriteFromArray($PathToYourFileInclusiveName, $sString) ;log the temp file to a variable Local $RowCounter = FileRead($sTempFile) ;close the open window ControlClick("VncViewer Message Box","","[CLASS:Button; INSTANCE:1]", "left") $stillLooking = True ;True to keep looking for windows, False to close after window has been found and call again when needed ;add one to the log tracker $u = $u +1 ;check to see if log file exists, if not, create it and add Error Log title, otherwise open and write to the file If Not FileExists($sFilePath) then FileWrite($sFilePath, $ErrorLog) Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", $eTempFile) Return False EndIf ;writes to log file including variable from above for computer name FileWriteLine($hFileOpen, _NowDate() & " " & _NowTime() & " - " & "Connectivity issue - " & $RowCounter) Else ;create a log file to write to If Not FileWrite($sFilePath, "") Then MsgBox($MB_SYSTEMMODAL, "", $eTempFile) Return False EndIf ;opens log file Local $hFileOpen = FileOpen($SFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", $eTempFile) Return False EndIf ;writes to log file including variable from above for computer name FileWriteLine($hFileOpen, _NowDate() & " " & _NowTime() & " - " & "Connectivity issue - " & $RowCounter) ;close the log file FileClose($hFileOpen) EndIf EndIf sleep(1000) EndFunc Func Terminate() ;end the $stillLooking $stillLooking = False Exit EndFunc ;Terminate the task I'm sure there are some checks I am missing, and I plan to add an error log/tracker at some point as well. Thanks again for all your help!
  2. Yes I have tried using different forms of the WinTitleMatchMode but I was not having any luck. I also tried variants of the If $activeWindowTitle == $CR Then and If $activeWindowTitle = $CR Then Neither had any affect at all. I will have to dig deeper into this when I have time a Simple copy and paste did not work (of course I edited the CN100- bit to match a real machine leaving off the end portion for the script to finish it, but I am out of time today to really troubleshoot it.) Thank you both for your replies I will be working more on this the rest of the week.
  3. Hello, Long time browser, first time poster I can usually find everything I need by searching, but this time I seem to be falling short I have been working on some code to use with UltraVNC to log in as a specific user. I know... discrepancies.... but humor me and help me get this code working. I would like to be lazy rather than touch many many many machines manually. I know there will be times when the machine is logged in, but I plan to reboot them via Wake on Lan before issuing these commands! I want AutoIT to launch the VNC window and wait for the window to be active, then if the window is active put in a username and password. Otherwise I want it to close that window and move on to the next. The problem is with the window name. The title of the window is something like this: CN100-123 ( 12.34.56.78 ) - service mode in this example CN100-123 will be supplied from a csv file as $CR. the IP Address in parenthesis will change for every machine, so how do i code for this? I was hoping to be able to use the $CR since it will already have the computer name, but the window is not found and nothing happens. I left a sleep command commented out and if the window isn't the failure window, it should automatically put in the username and password, but I do not like this, I would rather wait for the correct window and input the information if possible. I have a spiffed up version of this code that pulls the computer names from a CSV file. The code seems to work, but I didn't code in for an instance when the connection fails, so I am attempting to do so with a very played down and basic version of that code. here is the code: ;Computer name Will be pulled from CSV file later $CR = 'COMPUTERNAME' ;Command to be executed calling UltraVNC using Comptuer name and supplying VNC password $command = @ProgramFilesDir & "\UltraVNC\vncviewer.exe -connect " & $CR & " -password VNCPASSWORD" Local $iPID = run($command) ;Sleep(20000) $stillLooking = True While $stillLooking $activeWindowTitle = WinGetTitle(WinActive("")) ;I want to find the window that is open for this instance If $activeWindowTitle == $CR Then ;Send Username Send("USERNAME") Send("{tab}") ; Wait for 1 second Sleep(1000) ;Send Password Send("PASSWORD") Send("{enter}") ; Wait for 2 seconds Sleep(2000) ;Close the window after typing username and password Send("!+{F4}") $stillLooking = False ;But what if the computer is offline and not responding? Close and move on! ElseIf $activeWindowTitle == "VncViewer Message Box" Then ;Closes open dialogue Send("{space}") $stillLooking = False ;done with If statement EndIf sleep(5) WEnd I appreciate any help you can offer! Thank you in advance!
×
×
  • Create New...