call another excute file and close itself ?

call another excute file and close itself ?

Postby ShumingWang » Mon Apr 30, 2007 4:38 am

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
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Postby Antonio Linares » Mon Apr 30, 2007 6:12 am

Shuming,

Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby ShumingWang » Sat May 05, 2007 8:08 am

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
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Postby Antonio Linares » Sat May 05, 2007 8:38 am

Shuming,

In downloadfiles.exe do this:
Code: Select all  Expand view
while GetModuleHandle( "my.exe" ) != 0
   SysRefresh()
end

So it will wait until my.exe finishes
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby ShumingWang » Sun May 06, 2007 1:42 am

Antonio,

Sometime works, sometimes fail .

Thank you!

Shuming Wang
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Postby Jeff Barnes » Fri May 11, 2007 5:43 pm

I have done this in the past:

Code: Select all  Expand view
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
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby ShumingWang » Sat May 12, 2007 2:37 am

Jeff,
Working !
Thank you !
Shuming Wang
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 17 guests