how to know closing of one window within another

Hi

i am calling a batch file (.bat) file from one of my powerbuilder window. it will take bit seconds to fully execute the batch statements and it will close automatically.

now what i want is, i need to know closing of that dos mode window from my called powerbuilder window to show some message. how will i acheive it ?. if u can, pls give example codes..

is it possible to find with findwindowA API ?.  but what will be the title of the batch file ?

any comment will be appreciated

kidu 11
kidu11Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

namasi_navaretnamCommented:
If you use SheelExecuteA api instad of RUN function. You can accomplish this.

Function long ShellExecuteA( long hWindow, string Operation, string File, string Parameters, string Directory, long Visible) Library 'shell32'

See example below:

Use shellExecute API method :
// Add this to local/global external functions
//FUNCTION long ShellExecuteA(long hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, long nShowCmd) LIBRARY "SHELL32.DLL"

// API call script
long hwnd
string filname
hwnd=handle(parent)
filname='app2.exe'
shellexecuteA(hwnd,'open',filname,'','',0)


HTH

Namasi Navaretnam
0
kidu11Author Commented:
hi

thanx 4 ur comment

shellexecuteA is not working 4 the program i am trying to run, that has parameters also. here is my code,

is_commandline =  "command.com /c " + is_batfile + " " + is_workingfolder + " " + is_dbuid + " " + is_dbpwd + " " + is_zippwd + " " + is_span + " " + is_zipfile


//running the backup batchfile

if run( is_commandline , normal!) = 1 then
     return 1
end if

so, what is the problem...i think shellexecuteA will not work files that has paremeters, am i correct ?.

then how will achieve this

kidu 11
0
namasi_navaretnamCommented:
long hwnd
string filname
hwnd=handle(parent)

is_commandline =  "command.com /c " + is_batfile + " " + is_workingfolder + " " + is_dbuid + " " + is_dbpwd + " " + is_zippwd + " " + is_span + " " + is_zipfile


Try This
ShellExecuteA(0,'open',is_commandline ,'','',0)

Or Try This

shellexecuteA(hwnd,'open',is_commandline ,'','',0)

ShellExcuteA work well for me with parameters. I run a command to bcp with parameters.

HTH

Namasi Navaretnam
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

namasi_navaretnamCommented:
I am not sure of command.com is 16 bit or 32 bit. SO may want to try with cmd as well.

long hwnd
string filname
hwnd=handle(parent)

is_commandline =  "cmd /c " + is_batfile + " " + is_workingfolder + " " + is_dbuid + " " + is_dbpwd + " " + is_zippwd + " " + is_span + " " + is_zipfile


Try This
ShellExecuteA(0,'open',is_commandline ,'','',0)

Or Try This

shellexecuteA(hwnd,'open',is_commandline ,'','',0)

ShellExcuteA work well for me with parameters. I run a command to bcp with parameters.

0
gafoor78Commented:
Hi

it is not working if any argument is there. it return a value 2 ( no path found ) if any space is there ( that is arguments)

for ex: u check this one in ur system

ShellExecuteA(0,'open','notepad test.txt','','',1)

if it will be like       ShellExecuteA(0,'open','notepad','','',1), then no pblm it is working fine, return a value >34

my OS is win98

pls check and let me know if any other method is there ?.

kidu11

0
namasi_navaretnamCommented:
You are right!!
I went and checked my previous  code!! This is what I did

ls_commandfilename = "C:\test.bat"
ls_command = "commmand.... etc with your parameters"


Ll_FileNum = FileOpen ( Ls_CommandFileName, LineMode!, Write!, LockWrite!, Replace!)
FileWrite(ll_FileNum, Ls_Command)
FileClose(ll_FileNum)

Now execute,

Ll_Return = ShellExecuteA(0,'open',ls_CommandFileName,'','',0)
//make sure to use 0 as the last parameter.

HTH

Namasi Navaretnam





0
namasi_navaretnamCommented:
At the end ,

FileDelete("c:\test.bat)
0
kidu11Author Commented:
hi namasi

thank u.. i will check and get u back soon

kidu11
0
kidu11Author Commented:
thanx again

it is working now...but still my goal is not acheived !!. how do i know when the task is finished ?. i need to do some coding just after the task is finished... where will i code this

what i already done is checking the existance of the newly created file within a timer by the PB function  fileexist() !!.  really i expect there will be some method with shellexecute..get me abooooout it.

kidu
0
namasi_navaretnamCommented:
This is what i am doing in my code to see if the execution has completed

String ls_donefile
ls_donefile = "c:\done.txt"

// First delete done file.
If FileExists(Ls_DoneFile) Then
   FileDelete(Ls_DoneFile)
End If

Ls_DoneCommand = 'echo done > "' + Ls_DoneFile + '"'
ls_commandfilename = "C:\test.bat"
ls_command = "commmand.... etc with your parameters"


Ll_FileNum = FileOpen ( Ls_CommandFileName, LineMode!, Write!, LockWrite!, Replace!)
FileWrite(ll_FileNum, Ls_Command)
FileWrite(ll_FileNum, Ls_DoneCommand)
FileClose(ll_FileNum)

Ll_Return = ShellExecuteA(0,'open',ls_CommandFileName,'','',0)

//Execute the command above and wait for the done file to be created.

Do While Lb_DoneFileFound = FALSE
      If FileExists(Ls_DoneFile) then
            Lb_DoneFileFound = TRUE
      end if      
      Sleep(1) // Sleep for 1 second
Loop

FileDelete(ls_donefile)
FileDelete(ls_commandfilename )

HTH

Namasi

0
namasi_navaretnamCommented:
Alternative,

Open a response window (that display "Backing Up Database or what ever") so that the code underneath will not get executed.
After opening the winodw post an event (using POSTEVENT function) to check the existance of done file. whenthe file exists you can close the response winodw.

Do While Lb_DoneFileFound = FALSE
     If FileExists(Ls_DoneFile) then
          Lb_DoneFileFound = TRUE
     end if    
     Sleep(1) // Sleep for 1 second
Loop


HTH
0
namasi_navaretnamCommented:
Kidu11
Did that solution work?
0
Vikas_DixitCommented:
Hi,
 you can use the ShellExecuteEx function instead :

refer the link below for an example.
http://www.experts-exchange.com/Programming/Programming_Languages/PowerBuilder/Q_20663647.html

Declare another function

Integer WAIT_TIMEOUT =  258 //&H102

Function ulong WaitForSingleObject (ulong hHandle, ulong dwMilliseconds) Library "KERNEL32.DLL"


And call  after the call to ShellExecuteEx

Do
      retval = WaitForSingleObject(lst_shellexecuteinfo.hProcess, 0)
Loop While retval = WAIT_TIMEOUT

MessageBox("Done","")

HTH
Regards,
Vikas Dixit
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vikas_DixitCommented:
Also,

to get the processid, the flag needs to be set before calling ShellExecuteEx:
CONSTANT long SEE_MASK_CLASSNAME =64 //&H40
lst_shellexecuteinfo.fMask = SEE_MASK_NOCLOSEPROCESS

Regards,
Vikas
0
kidu11Author Commented:
Hi

Thank u Namasi.. it is working, but i will also check with Vikas's ShellExecuteEx, i think that will be a better approch

so i will get back to u soon

rgrds

kidu
0
namasi_navaretnamCommented:
Yes. I agree ShellExecuteEx would be a better approch.
0
kidu11Author Commented:
Hello vikas

now i checked with shellexecuteex and WaitForSingleObject. but the WaitForSingleObject is not working.

here is my complete code

CONSTANT long SEE_MASK_CLASSNAME = 64
CONSTANT long SW_NORMAL = 1
Integer WAIT_TIMEOUT =  258 //&H102
CONSTANT long SH_HIDE = 0
integer retval

string ls_class
string ls_extension
long ll_ret

os_shellexecuteinfo lst_shellexecuteinfo

// Search for the classname associated with extension
RegistryGet("HKEY_CLASSES_ROOT\" + '.bat', "", ls_class)

// the file is not associated with any program.. try to install the program
IF isNull(ls_class) OR Trim(ls_class) = "" THEN
    RETURN 0
END IF

as_file = is_commandline = "command.com /c " + is_batfile + " " + is_workingfolder + " " + is_dsnname + " " + is_dbuid + " " + is_dbpwd + " " + is_zipfile

lst_shellexecuteinfo.cbsize = 60
lst_shellexecuteinfo.fMask = SEE_MASK_CLASSNAME  // Use classname
lst_shellexecuteinfo.hwnd = 0
lst_shellexecuteinfo.lpVerb = "open"
lst_shellexecuteinfo.lpfile = as_file
lst_shellexecuteinfo.lpClass = ls_class
lst_shellexecuteinfo.nShow = SH_HIDE

ll_ret = ShellExecuteEx(lst_shellexecuteinfo)

// cannot open the file...pls try reinstalling the program
IF ll_ret = 0 THEN
       RETURN 2
END IF

Do
   retval = WaitForSingleObject(lst_shellexecuteinfo.hProcess, 0)
loop while retval = WAIT_TIMEOUT

return 1

in the above code the problem is the do loop is iterating only once.  and its value at the first iteration is  -1. so what is the problem, pls check inform me what is wrong with the above code

thanx
kidu
0
Vikas_DixitCommented:
Hi kidu,

I tried with a .txt file, and it worked fine... the function kept returning 258 till the notepad was open, and once I closed the notepad, it returned 0..

you can try the following :

1.change the following :
lst_shellexecuteinfo.nShow = SH_SHOW  //SH_HIDE  -- SH_SHOW =1

2. check if the lst_shellexecuteinfo.hProcess has a process id.

3. instead of using "command.com /c", try opening just the batch file, and pass the parameters in the lpParameters member.

will try to test with a .bat file

regards,
Vikas D
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.