MattX Posted January 19, 2005 Posted January 19, 2005 Dunno why but the first else statement is not running and I don't know why as I need it to run to test the PC thats NOT called IT_TEST. Also I only want this code to run on around 14 out of 100 PCs how can I do that neatly ? Any ideas would be appreciated... expandcollapse popupIf @ComputerName = 'IT_TEST' Then ;#include <File.au3> Dim $sLogPath = "c:\logs\sitelog.txt" Dim $sLogMsg = "History Boardwords Opened By " _FileWriteLog($sLogPath, $sLogMsg) Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") exit Else Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf Endif Endif Func _FileWriteLog( $sLogPath, $sLogMsg ) ;============================================== ; Local Constant/Variable Declaration Section ;============================================== Local $sDateNow Local $sTimeNow Local $sMsg Local $hOpenFile Local $hWriteFile Local $user $sDateNow = @YEAR & "-" & @MON & "-" & @MDAY $sTimeNow = @Hour & ":" & @MIN & ":" & @SEC $user = @username $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg & $user $hOpenFile = FileOpen( $sLogPath, 1 ) If $hOpenFile = -1 Then SetError( 1 ) Return 0 EndIf $hWriteFile = FileWriteLine( $hOpenFile, $sMsg ) If $hWriteFile = -1 Then SetError( 2 ) Return 0 EndIf FileClose( $hOpenFile ) Return 1 EndFunc
ezzetabi Posted January 19, 2005 Posted January 19, 2005 Maybe you meant If NOT (@ComputerName = 'IT_TEST') Then or If @ComputerName <> 'IT_TEST' Then About selecting the computers, what about using a list in file? You check the @computername value over the list.
MattX Posted January 19, 2005 Author Posted January 19, 2005 Maybe you meant If NOT (@ComputerName = 'IT_TEST') ThenorIf @ComputerName <> 'IT_TEST' ThenAbout selecting the computers, what about using a list in file? You check the @computername value over the list.<{POST_SNAPBACK}>Thanks for the idea over the list in the file. As for the Else statement, its still not executing.
ezzetabi Posted January 19, 2005 Posted January 19, 2005 Your code is strange. You execute the program "C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe" and waits 3000 second, if the windows did not appeared you start it again? There is reason to think that the program should not start? It is not better using Winwait? Or if it is really reson to think that the program does not starts I think you should use a Do/Until loop.
MattX Posted January 19, 2005 Author Posted January 19, 2005 (edited) Your code is strange. You execute the program "C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe" and waits 3000 second, if the windows did not appeared you start it again? There is reason to think that the program should not start?It is not better using Winwait? Or if it is really reson to think that the program does not starts I think you should use a Do/Until loop.<{POST_SNAPBACK}>Sorry about the code !! All my stuff is self taught as I have never had any lessons or training on coding etc !!The reason for the wait [ winexists ] is that on some PCs a pop up box appears informing the user they have the wrong macro media player installed and its best to close the app down, on other PCs it runs fine, if the box does appear - [ Boardworks KS2 History ] then it justy hits the enter button and continues.I want the prog to run but only log on certain PCs.BTW I have tried a Elseif and it still does not fire off - this is really annoying, once this part is working the script is complete !! AAAGGHHHH.. Edited January 19, 2005 by MattX
MattX Posted January 19, 2005 Author Posted January 19, 2005 Took a different approach although I am sure there is a better way: expandcollapse popupIf (@ComputerName = 'IT_TEST') Then Dim $sLogPath = "c:\logs\sitelog.txt" Dim $sLogMsg = "History Boardwords Opened By " _FileWriteLog($sLogPath, $sLogMsg) Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf EndIf If Not (@ComputerName = 'IT_TEST') Then Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf EndIf Func _FileWriteLog($sLogPath, $sLogMsg) ;============================================== ; Local Constant/Variable Declaration Section ;============================================== Local $sDateNow Local $sTimeNow Local $sMsg Local $hOpenFile Local $hWriteFile Local $user $sDateNow = @YEAR & "-" & @MON & "-" & @MDAY $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC $user = @UserName $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg & $user $hOpenFile = FileOpen($sLogPath, 1) If $hOpenFile = -1 Then SetError(1) Return 0 EndIf $hWriteFile = FileWriteLine($hOpenFile, $sMsg) If $hWriteFile = -1 Then SetError(2) Return 0 EndIf FileClose($hOpenFile) Return 1 EndFunc ;==>_FileWriteLog
MattX Posted January 19, 2005 Author Posted January 19, 2005 Hmmmm, if I use OR in the first IF statement its ignored and the first part of the script [ the logging ] runs even though the PC I am testing it on is not even in the IF statement !!Can't you use OR there ?Took a different approach although I am sure there is a better way:expandcollapse popupIf (@ComputerName = 'IT_TEST' or 'ANOTHERPC') Then Dim $sLogPath = "c:\logs\sitelog.txt" Dim $sLogMsg = "History Boardwords Opened By " _FileWriteLog($sLogPath, $sLogMsg) Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf EndIf If Not (@ComputerName = 'IT_TEST' or 'ANOTHERPC') Then Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf EndIf Func _FileWriteLog($sLogPath, $sLogMsg) ;============================================== ; Local Constant/Variable Declaration Section ;============================================== Local $sDateNow Local $sTimeNow Local $sMsg Local $hOpenFile Local $hWriteFile Local $user $sDateNow = @YEAR & "-" & @MON & "-" & @MDAY $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC $user = @UserName $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg & $user $hOpenFile = FileOpen($sLogPath, 1) If $hOpenFile = -1 Then SetError(1) Return 0 EndIf $hWriteFile = FileWriteLine($hOpenFile, $sMsg) If $hWriteFile = -1 Then SetError(2) Return 0 EndIf FileClose($hOpenFile) Return 1 EndFunc ;==>_FileWriteLog<{POST_SNAPBACK}>
MattX Posted January 19, 2005 Author Posted January 19, 2005 Hmmmm, if I use OR in the first IF statement its ignored and the first part of the script [ the logging ] runs even though the PC I am testing it on is not even in the IF statement !!Can't you use OR there ?<{POST_SNAPBACK}>I think I have answered my own question again - I use:If (@ComputerName = 'IT_TEST' or @Computername = 'ITBOARD') Theninstead of If (@ComputerName = 'IT_TEST' or 'ANOTHERPC') Thenand I think thats done it...
MattX Posted January 19, 2005 Author Posted January 19, 2005 (edited) DONE IT !! I am sure there is a better way than having all the @comptuername statements though... expandcollapse popupIf (@ComputerName = 'PPLIBOARD' Or @ComputerName = 'ITBOARD' Or @ComputerName = 'JB01' Or @ComputerName = 'JB03' _ Or @ComputerName = 'JB05' Or @ComputerName = 'JB07' Or @ComputerName = 'LAB01' Or @ComputerName = 'LAB02' _ Or @ComputerName = 'GEOGBOARD' Or @ComputerName = 'MATHSBOARD' Or @ComputerName = 'LATBOARD' Or @ComputerName = 'FREBOARD' _ Or @ComputerName = 'ENGBOARD' Or @ComputerName = 'HISTBOARD' Or @ComputerName = 'IT_TEST2') Then Dim $sLogPath = "c:\logs\sitelog.txt" Dim $sLogMsg = "History Boardwords Opened By " _FileWriteLog($sLogPath, $sLogMsg) Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf EndIf If Not (@ComputerName = 'PPLIBOARD' Or @ComputerName = 'ITBOARD' Or @ComputerName = 'JB01' Or @ComputerName = 'JB03' _ Or @ComputerName = 'JB05' Or @ComputerName = 'JB07' Or @ComputerName = 'LAB01' Or @ComputerName = 'LAB02' _ Or @ComputerName = 'GEOGBOARD' Or @ComputerName = 'MATHSBOARD' Or @ComputerName = 'LATBOARD' Or @ComputerName = 'FREBOARD' _ Or @ComputerName = 'ENGBOARD' Or @ComputerName = 'HISTBOARD' Or @ComputerName = 'IT_TEST2') Then Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf EndIf Func _FileWriteLog($sLogPath, $sLogMsg) ;============================================== ; Local Constant/Variable Declaration Section ;============================================== Local $sDateNow Local $sTimeNow Local $sMsg Local $hOpenFile Local $hWriteFile Local $user $sDateNow = @YEAR & "-" & @MON & "-" & @MDAY $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC $user = @UserName $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg & $user $hOpenFile = FileOpen($sLogPath, 1) If $hOpenFile = -1 Then SetError(1) Return 0 EndIf $hWriteFile = FileWriteLine($hOpenFile, $sMsg) If $hWriteFile = -1 Then SetError(2) Return 0 EndIf FileClose($hOpenFile) Return 1 EndFunc ;==>_FileWriteLog Edited January 19, 2005 by MattX
therks Posted January 19, 2005 Posted January 19, 2005 (edited) Just looking at your first post here... If @ComputerName = 'IT_TEST' Then ;#include <File.au3> Dim $sLogPath = "c:\logs\sitelog.txt" Dim $sLogMsg = "History Boardwords Opened By " _FileWriteLog($sLogPath, $sLogMsg) Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") exit Else; <--- Is this the Else you are having trouble with? You realize it's matching with the If WinExists statement above, not the If @ComputerName one. Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf Endif Endif Please note the comment in my copy of your code above. I think maybe this is what you are looking for: If @ComputerName = 'IT_TEST' Then ;#include <File.au3> Dim $sLogPath = "c:\logs\sitelog.txt" Dim $sLogMsg = "History Boardwords Opened By " _FileWriteLog($sLogPath, $sLogMsg) Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") exit EndIf Else Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf Endif How does that work? Edited January 19, 2005 by Saunders My AutoIt Stuff | My Github
MattX Posted January 19, 2005 Author Posted January 19, 2005 Arrrrrrrrrrrrr - thats why the ELSE statement was not working - thanks for pointing that out to me - all makes sence now. I thought I was going mad !!I know what to look out for now in my next one - many thanks for pointing that out - I appreciate it.Just looking at your first post here...If @ComputerName = 'IT_TEST' Then ;#include <File.au3> Dim $sLogPath = "c:\logs\sitelog.txt" Dim $sLogMsg = "History Boardwords Opened By " _FileWriteLog($sLogPath, $sLogMsg) Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") exit Else; <--- Is this the Else you are having trouble with? You realize it's matching with the If WinExists statement above, not the If @ComputerName one. Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf Endif EndifPlease note the comment in my copy of your code above. I think maybe this is what you are looking for:If @ComputerName = 'IT_TEST' Then ;#include <File.au3> Dim $sLogPath = "c:\logs\sitelog.txt" Dim $sLogMsg = "History Boardwords Opened By " _FileWriteLog($sLogPath, $sLogMsg) Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") exit EndIf Else Run("C:\Program Files\Boardworks\KS2 History\Boardworks KS2 History.exe") BlockInput(1) Sleep(3000) If WinExists("Boardworks KS2 History") Then Send("{ENTER}") Exit EndIf EndifHow does that work?<{POST_SNAPBACK}>
therks Posted January 19, 2005 Posted January 19, 2005 No problem, glad I could help. My AutoIt Stuff | My Github
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now