Jump to content

Script assistance?


Joshjosh
 Share

Recommended Posts

Hey guys and girls,

With help from a few users here I have changed a scripts actions and now have errors after compiling. I'm only very new to scripting and not sure how to close it off properly.

Please see the info below. Any help would be much appricated

Global $file_to_monitor = "c:\a.txt"

Global $on_start_value = CheckForFileUpdate($file_to_monitor)

While 1

Sleep(1000)

$return_date = CheckForFileUpdate($file_to_monitor)

;ConsoleWrite(@CRLF & $return_date & " - " & $on_start_value)

If $return_date <> $on_start_value Then

_RestartServices() ; restarts service 'Music', could have some error checking here

$on_start_value = $return_date ; resets the on_start_value to newest date / time value

EndIf

WEnd

Func CheckForFileUpdate($file_to_check)

$file_time = FileGetTime($file_to_check, 0)

If Not @error Then

$yyyymd = $file_time[0] & "/" & $file_time[1] & "/" & $file_time[2]

$hhmmss = $file_time[3] & ":" & $file_time[4] & ":" & $file_time[5]

Return $yyyymd & " " & $hhmmss

EndIf

Return 0

EndFunc ;==>CheckForFileUpdate

Func _ProcessClose("iexplore.exe")

While 1

If FileRead($file_to_monitor) <> $on_start_value Then ProcessClose(iexplore.exe)

Wend

EndFunc ;==>_ProcessClose

All I want to do is if a particular file changes (c:\a.txt), close the iexplore process. The error I get is Line -1: Error: Expected a variable in user function call". I know it is something that is wrong or missing below the func _processclose("iexplore.exe") but not sure where to go.

Thanks everyone.

Link to comment
Share on other sites

To me it looks like you're calling the function wrong.

You want

_ProcessClose("iexplore.exe")

Not

Func _ProcessClose("iexplore.exe")

The "Func" goes before a function name only when you're creating a new function, like you're Function CheckForFileUpdate.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Maybe somthing like?

CODE
Global $file_to_monitor = "c:\a.txt"

Global $on_start_value = CheckForFileUpdate($file_to_monitor)

While 1

Sleep(1000)

$return_date = CheckForFileUpdate($file_to_monitor)

;ConsoleWrite(@CRLF & $return_date & " - " & $on_start_value)

If $return_date <> $on_start_value Then

_RestartServices() ; restarts service 'Music', could have some error checking here

$on_start_value = $return_date ; resets the on_start_value to newest date / time value

EndIf

WEnd

Func CheckForFileUpdate($file_to_check)

$file_time = FileGetTime($file_to_check, 0)

If Not @error Then

$yyyymd = $file_time[0] & "/" & $file_time[1] & "/" & $file_time[2]

$hhmmss = $file_time[3] & ":" & $file_time[4] & ":" & $file_time[5]

Return $yyyymd & " " & $hhmmss

EndIf

Return 0

_ProcessClose("iexplore.exe")

EndFunc ;==>CheckForFileUpdate

Func _ProcessClose("iexplore.exe")

While 1

If FileRead($file_to_monitor) <> $on_start_value Then ProcessClose(iexplore.exe)

Wend

EndFunc ;==>_ProcessClose

[Cheeky]Comment[/Cheeky]
Link to comment
Share on other sites

thanks fellas, but still same error.

Lordicast : I thought I was to get rid of the func _processclose..... and replace with just _processclose.......

I have this so far and the result is unknown function:

Global $file_to_monitor = "c:\a.txt"

Global $on_start_value = CheckForFileUpdate($file_to_monitor)

While 1

Sleep(1000)

$return_date = CheckForFileUpdate($file_to_monitor)

;ConsoleWrite(@CRLF & $return_date & " - " & $on_start_value)

If $return_date <> $on_start_value Then

_RestartServices() ; restarts service 'Music', could have some error checking here

$on_start_value = $return_date ; resets the on_start_value to newest date / time value

EndIf

WEnd

Func CheckForFileUpdate($file_to_check)

$file_time = FileGetTime($file_to_check, 0)

If Not @error Then

$yyyymd = $file_time[0] & "/" & $file_time[1] & "/" & $file_time[2]

$hhmmss = $file_time[3] & ":" & $file_time[4] & ":" & $file_time[5]

Return $yyyymd & " " & $hhmmss

EndIf

Return 0

EndFunc ;==>CheckForFileUpdate

_ProcessClose("iexplore.exe")

While 1

If FileRead($file_to_monitor) <> $on_start_value Then ProcessClose("iexplore.exe")

Wend

Edited by Joshjosh
Link to comment
Share on other sites

finalllly got it sorted. amazing what you learn when forced to. I was completely over complicating it as mentionned above. I ripped the whole action component out and started it fresh using the help to guide me and it now works a treat.

I now have 2 scripts that run all the time. One monitors for iexplore.exe and if its closed (i.e. a user tries to user the mediapc as a workstation and closes ie), it will automatically open again and lock the mouse cursor off screen (remembering all this box does is run a full screen html page embedded in flash). The second is this one. When we upload the new content (xyz.html and xyz.swf) via ftp from a remote server, this script monitors to c:\xyz\xyz.htm and automatically closes the iexplore session. The other session immediately reopens iexplore with the new content.

I know this sounds odd, but it is better than have a refresh time built into the html code as there is always the chance the page refreshes while doing a upload and rendering a page not found or blank page (cant find ebedded swf as it will be in use).

Thanks again for everyones help and hope these little scripts can help others in the future.

Link to comment
Share on other sites

Just for information, your original error was simply a syntax error in _process_close.

[by the way, you r not using _ProcessClose in the sample code that you ve pasted.]

Func _ProcessClose()

While 1

If FileRead($file_to_monitor) <> $on_start_value Then

ProcessClose("iexplore.exe")

EndIf

Sleep(800) ; because it s an infinite loop you should add a timer to save CPU time.

Wend

EndFunc ;==>_ProcessClose

When defining a Function, you can put variable in the brackets like this :

Function _ProcessClose($my_var)

or with a default value like this :

Function _ProcessClose($my_var = "iexplore.exe")

Hope it helps.

Regards.

Iklim

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...