Jump to content

Recommended Posts

Posted

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...

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
   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
Posted

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.

Posted

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.

<{POST_SNAPBACK}>

Thanks for the idea over the list in the file. As for the Else statement, its still not executing.
Posted

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.

Posted (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 by MattX
Posted

Took a different approach although I am sure there is a better way:

If (@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
Posted

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:

If (@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}>

Posted

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') Then

instead of If (@ComputerName = 'IT_TEST' or 'ANOTHERPC') Then

and I think thats done it...

Posted (edited)

DONE IT !! I am sure there is a better way than having all the @comptuername statements though...

If (@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 by MattX
Posted (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 by Saunders
Posted

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   
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?

<{POST_SNAPBACK}>

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...