Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Replace In Use File Restart
IntControl (12,1+4,0,0,0) ;Suppress OK to close messages IntControl (49,1,0,0,0) ;Enables Min/Max/Close Widgets IntControl (1002,0,0,0,0) ;Sets display state of WinBatch box IntControl (1003,0,0,0,0) ;Prevents WinBatch icon from being opened IntControl (1008,1,0,0,0) ;Enables Close command WorkingDir=StrCat (DirWindows(1),"RoRFiles\") DirChange ("C:\") ;=============================================================================== ;+-----STYLE-----------------------+-----ICONS-----------------------+ ;| OK = 0 | STOP = 16 | ;| OKCANCEL = 1 | QUESTION = 32 | ;| ABORTRETRYIGNORE = 2 | EXCLAIM = 48 | ;| YESNOCANCEL = 3 | INFO = 64 | ;| YESNO = 4 | WINICON = 4096 | ;| RETRYCANCEL = 5 | | ;+-----BUTTONS---------------------|----RETURN VALUES----------------| ;| DEFAULTBUTTON1 = 0 | IDOK = 1 | ;| DEFAULTBUTTON2 = 256 | IDCANCEL = 2 | ;| DEFAULTBUTTON3 = 512 | IDABORT = 3 | ;+---------------------------------| IDRETRY = 4 | ;| Combine flags with OR operator: | IDIGNORE = 5 | ;| Flags=4|48|256|4096 | IDYES = 6 | ;| | IDNO = 7 | ;+---------------------------------+---------------------------------+ #DefineFunction xMsgBox(Caption,Text,Flags) ; Thanks, Guido! xMsg=DllCall(StrCat(DirWindows(1),"User32.dll"),long:"MessageBoxA",long:DllHwnd(""),lpstr:Text,lpstr:Caption,long:Flags) Return (xMsg) #EndFunction ;=============================================================================== #DefineSubRoutine DlgCallback (DlgName,DlgEvent,DlgCtrl,Res4,Res5) If DlgEvent==00 ;Dialog initialization DialogProcOptions (DlgName,2,1) ;Watch for button presses ;Disables Min/Max/Restore/Close widgets in windows Thanks, Guido! hwnd=DllHwnd("Replace On Restart") ;Window Title of desired window goes here sysmenu=DllCall(StrCat(DirWindows(1),"User32.dll"),long:"GetSystemMenu",long:hwnd,long:0) DllCall (StrCat(DirWindows(1),"User32.dll"),long:"RemoveMenu",long:sysmenu,long:61488,long:0) ;Remove maximize from system menu OldStyle=DllCall(StrCat(DirWindows(1),"User32.dll"),long:"GetWindowLongA",long:hwnd,long:-16) NewStyle=OldStyle & ~65536 ;Disable Maximize widget Result = DllCall(StrCat(DirWindows(1),"User32.dll"),long:"SetWindowLongA",long:hwnd,long:-16,long:NewStyle) EndIf If DlgEvent==02 ;Button press event If DlgCtrl==005 TgtFile=AskFilename("Select File to Replace",FilePath(TgtFile),"","",1) DialogControlSet (DlgName,002,3,TgtFile) EndIf If DlgCtrl==006 SrcFile=AskFilename("Select Replacement File",FilePath(SrcFile),"","",1) DialogControlSet (DlgName,004,3,SrcFile) EndIf If DlgCtrl==007 TgtFile=DialogControlGet (DlgName,002,3) SrcFile=DialogControlGet (DlgName,004,3) If !FileExist (TgtFile) xMsgBox ("Invalid Filename",StrCat("File not found:",@CRLF,TgtFile),48) Return (-2) EndIf If !FileExist (SrcFile) xMsgBox ("Invalid Filename",StrCat("File not found:",@CRLF,SrcFile),48) Return (-2) EndIf If !ItemLocate (ItemExtract(1,TgtFile,"\"),DiskScan(2),@TAB) xMsgBox ("Invalid Drive","Target file must be on a local drive",48) Return (-2) EndIf CfmMsg=StrCat ("Are you SURE you want to replace ",TgtFile,@CRLF,"with ",SrcFile) CfmMsg=StrCat(CfmMsg," at next restart?",@CRLF,@CRLF,"This operation cannot be undone.") If xMsgBox ("Confirm File Replacement:",CfmMsg,4|48|256)==7 Then Return (-2) If !DirExist (WorkingDir) Then DirMake (WorkingDir) CpySrc=FileCopy (SrcFile,StrCat(WorkingDir,FileRoot(TgtFile),".new"),@FALSE) If CpySrc<>@TRUE xMsgBox ("FileCopy Failed","Unable to create replacement file cache",48) Return (-2) EndIf CpyTgt=FileCopy (SrcFile,StrCat(WorkingDir,FileRoot(TgtFile),".old"),@FALSE) Message ("",CpyTgt) If CpyTgt==@FALSE If xMsgBox ("FileCopy Failed",StrCat("Backup of current version failed.",@CRLF,@CRLF,"Continue anyway?"),52)==7 Then Return (-2) Return (-2) EndIf SrcFile=StrCat(WorkingDir,FileRoot(TgtFile),".new") RoR=IntControl (30,SrcFile,TgtFile,0,0) If RoR==1 Then Display (2,"Replacement Successful","File has been flagged for replacement at next restart") If RoR<>1 Then xMsgBox ("Replacement Failed","File not successfully flagged for replacement",48) EndIf If DlgCtrl==008 Then Exit ; EndIf :CANCEL Return (-2) #EndSubRoutine FileRepFormat=`WWWDLGED,6.1` FileRepCaption=`Replace On Restart` FileRepX=155 FileRepY=079 FileRepWidth=200 FileRepHeight=060 FileRepNumControls=008 FileRepProcedure=`DlgCallback` FileRepFont=`DEFAULT` FileRepTextColor=`DEFAULT` FileRepBackground=`DEFAULT,DEFAULT` FileRepConfig=123 FileRep001=`003,005,033,008,STATICTEXT,DEFAULT,"&Target File:",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT` FileRep002=`038,003,116,012,EDITBOX,TgtFile,"",DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` FileRep003=`003,021,033,008,STATICTEXT,DEFAULT,"&Replacement:",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT` FileRep004=`038,019,116,012,EDITBOX,SrcFile,"",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT` FileRep005=`157,003,036,012,PUSHBUTTON,DEFAULT,"Browse",2,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` FileRep006=`157,019,036,012,PUSHBUTTON,DEFAULT,"Browse",3,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT` FileRep007=`117,039,036,012,PUSHBUTTON,DEFAULT,"&Next",1,7,32,DEFAULT,DEFAULT,DEFAULT` FileRep008=`157,039,036,012,PUSHBUTTON,DEFAULT,"&Quit",0,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT` FileRepButtonPushed=Dialog("FileRep",1) Exit
Article ID: W16201
File Created: 2004:03:30:15:43:14
Last Updated: 2004:03:30:15:43:14