Jump to content

Hi i have Another problem, End the window if its not active.


Recommended Posts

Hi im working on a script, it creates a file writes info in it runs it and closes it, i would like it to auto delete when its done.

The problem is when i set filedelete($file) it closes + deletes the file in mid process, which is not what i want. i cannot add sleep as the file may take longer on some systems than other and longer depending on what the user has.

so im basicly wondering if their a way to do this

if file is open then sleep('3000')

if file is closed then filedelete($file)

Thanks for any help again =]

Link to comment
Share on other sites

I suppose you could use WinExists or ProcessExists for the program that opens the file.

Also, you could use WinGetHandle right after opening the file if you assume that the user might be using the program for something else, meaning there'll be more than one window/process with the same name.

Link to comment
Share on other sites

i have done this.

filewrite($file,"")
sleep('500')
filewrite($file,$line1 & @crlf)
filewrite($file,$line2 & @crlf)
filewrite($file,$line3 & @crlf)
filewrite($file,$line4 & @crlf)
filewrite($file,$line5 & @crlf)
filewrite($file,$line6 & @crlf)
filewrite($file,$line7 & @crlf)
filewrite($file,$line8 & @crlf)
filewrite($file,$line9 & @crlf)
filewrite($file,$line10 & @crlf)
filewrite($file,$line11 & @crlf)
filewrite($file,$line12 & @crlf)
filewrite($file,$line13 & @crlf)
filewrite($file,$line14 & @crlf)
filewrite($file,$line15 & @crlf)
filewrite($file,$line16 & @crlf)
filewrite($file,$line17 & @crlf)
filewrite($file,$line18 & @crlf)
filewrite($file,$line19 & @crlf)
filewrite($file,$line20 & @crlf)

run($file)
sleep('500')
if winactive('c:\WINDOWS\system32\cmd.exe') then sleep('3000')

filedelete($file)

the problem is that the script still closes and deletes the file...

Thanks dolls i love you all.

Edited by trainwreck07
Link to comment
Share on other sites

Run($file)? Does that work? I think you have to use ShellExecute()

Use macros! Use @WinDir to replace C:\Windows. It will tell the script the path of the windows dir for the PC it's running on.

And I think that the second code should be:

If ProcessExists("cmd.exe") Then 
   Sleep(3000)
   FileDelete($File)
Endif

And you might also want to close the cmd window, so just use ProcessClose("cmd.exe")

Link to comment
Share on other sites

Run($file)? Does that work?

yup.

Use macros! Use @WinDir to replace C:\Windows. It will tell the script the path of the windows dir for the PC it's running on.

And I think that the second code should be:

im am =P im just trying to get the whole layout of the script done, first off...

thanks for the help =]

Link to comment
Share on other sites

the problem is that the cmd location may differ on some pcs ....

so the next step i am working on is making that peice of code dynamic.

Thanks dolls i love you all.

You could use the @SystemDir macro. This will return the system32 directory on the system where it is run. So @SystemDir & "\cmd.exe" should return what you need.

But you can also use Opt("WinTitleMatchMode",2) to make the WinActive also trigger when searching 'cmd' (then you don't need the full path).

A third option would be to use ProcessExists("cmd.exe") to check for a process called 'cmd.exe'.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

...im am =P im just trying to get the whole layout of the script done, first off...

try:
FileWrite($file, "")
Sleep(500)
FileWrite($file, $line1 & @CRLF)
FileWrite($file, $line2 & @CRLF)
FileWrite($file, $line3 & @CRLF)
FileWrite($file, $line4 & @CRLF)
FileWrite($file, $line5 & @CRLF)
FileWrite($file, $line6 & @CRLF)
FileWrite($file, $line7 & @CRLF)
FileWrite($file, $line8 & @CRLF)
FileWrite($file, $line9 & @CRLF)
FileWrite($file, $line10 & @CRLF)
FileWrite($file, $line11 & @CRLF)
FileWrite($file, $line12 & @CRLF)
FileWrite($file, $line13 & @CRLF)
FileWrite($file, $line14 & @CRLF)
FileWrite($file, $line15 & @CRLF)
FileWrite($file, $line16 & @CRLF)
FileWrite($file, $line17 & @CRLF)
FileWrite($file, $line18 & @CRLF)
FileWrite($file, $line19 & @CRLF)
FileWrite($file, $line20 & @CRLF)

Run($file)
Sleep(500)

WinWait('c:\WINDOWS\system32\cmd.exe')

While WinExists('c:\WINDOWS\system32\cmd.exe') Then
    Sleep(99)
WEnd

FileDelete($file)
-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

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