call another excute file and close itself ?

Post Reply
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

call another excute file and close itself ?

Post by ShumingWang »

Hi,
my.exe :

function main()

define dialog odlg source "odlg"

define button of odlg action (winexec(downloadfiles.exe),odlg:end())

activate dialog odlg

Return

Problem is that before close my.exe, the downloadfiles.exe is already running and donwload my.exe from web site,so my.exe will be overwrite fail.

Thanks !

Shuming Wang
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Shuming,

Code: Select all

#include "FiveWin.ch"

function Main()

   local lUpgrade := .F.

   DEFINE DIALOG oDlg RESOURCE "odlg"

   @ 2, 2 BUTTON "Upgrade" OF oDlg SIZE 80, 20 ;
      ACTION ( lUpgrade := .T., oDlg:End() )

   ACTIVATE DIALOG oDlg

   if lUpgrade
      WinExec( "downloadfiles.exe" )
   endif

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Post by ShumingWang »

Antonio,
The main my.exe file is still exist in memory and running during winexe("copyfile.exe").


#include "FiveWin.ch"

function Main()

local lUpgrade := .F.

DEFINE DIALOG oDlg RESOURCE "odlg"

@ 2, 2 BUTTON "Upgrade" OF oDlg SIZE 80, 20 ;
ACTION ( lUpgrade := .T., oDlg:End() )

ACTIVATE DIALOG oDlg

if lUpgrade
hLib = LOADLIBRARY( "urlmon.dll")
URLDownloadToFile( 0, "www.my.com/down/my.exe", ".\tmp\my.exe", 0, 0 ) == 0
FREELIBRARY( hLib )
WinExec( "copyfile.exe" )
endif

return nil

DLL32 FUNCTION URLDownloadToFile(pCaller AS LONG,szURL AS STRING, szFileName AS STRING, dwReserved AS LONG, lpfnCB AS LONG);
AS LONG PASCAL;
FROM "URLDownloadToFileA";
LIB hlib



copyfile.prg

#include "fivewin.ch"
FUNCTION main(cpath)
local afiles
msgwait("正在更新文件","",2)


afiles:=directory(".\tmp\*.*")

for i:=1 to len(afiles)
copyfile( "\"+CURDIR()+"\tmp\"+afiles[i,1] ,afiles[i,1] ,.f.)
next

winexec("my.exe")

return


Thank you!
Shuming Wang
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Shuming,

In downloadfiles.exe do this:

Code: Select all

while GetModuleHandle( "my.exe" ) != 0
   SysRefresh()
end
So it will wait until my.exe finishes
regards, saludos

Antonio Linares
www.fivetechsoft.com
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Post by ShumingWang »

Antonio,

Sometime works, sometimes fail .

Thank you!

Shuming Wang
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

I have done this in the past:

Code: Select all

SHELLEXECUTE(0,0,"DownloadFile.exe",0,0,1 )
dbcloseall()
freelibrary( hBorland )
set resources to
clear memory
ResAllFree()
if ! empty( oWnd )
    oWnd:end()
endif
quit
Hope this helps,
Jeff
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Post by ShumingWang »

Jeff,
Working !
Thank you !
Shuming Wang
Post Reply