FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour call another excute file and close itself ?
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
call another excute file and close itself ?
Posted: Mon Apr 30, 2007 04: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

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
call another excute file and close itself ?
Posted: Mon Apr 30, 2007 06:12 AM
Shuming,

#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
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
call another excute file and close itself ?
Posted: Sat May 05, 2007 08: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
http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
call another excute file and close itself ?
Posted: Sat May 05, 2007 08:38 AM
Shuming,

In downloadfiles.exe do this:
while GetModuleHandle( "my.exe" ) != 0
   SysRefresh()
end

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

Antonio Linares
www.fivetechsoft.com
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
call another excute file and close itself ?
Posted: Sun May 06, 2007 01:42 AM

Antonio,

Sometime works, sometimes fail .

Thank you!

Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
call another excute file and close itself ?
Posted: Fri May 11, 2007 05:43 PM
I have done this in the past:

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
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
call another excute file and close itself ?
Posted: Sat May 12, 2007 02:37 AM

Jeff,
Working !
Thank you !
Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651

Continue the discussion