I have a client.exe Executable, that will replace itself with the file starting with "autoupdate-client.exe. For example: if client.exe runs and autoupdate-client.exe is in the same folder, then the program will delete client.exe and rename autoupdate-client.exe to client.exe. The following code is implemented in widows:
if {[regexp -nocase \
"autoupdate-(.*)" \
[file tail [info nameofexecutable]] - binaryname]} {
after 5000
set dirname [file dirname [info nameofexecutabe]
set targetname [file join $dirname $binaryname]
catch {vfs::mk4::Unmount exe [info nameofexecutable]]
file copy -force [infor nameofexecutable] $targetname
catch {file attributes $targetname -permission 0755}
exec $targetname {*}$argv &
exit 0
} else {
set dirname [file dirname [infor nameofexecutable]
set targetname [file join $dirname \
"autoupdate-[file tail [info nameofexecutablle]]}\
]
if {[file exists $targetname]} {
after 5000 catch {file delete -force $targetname}
I get the following error:
error copying "autoupdate-client.exe" to "client.exe": permission denied
while executing "
file copy -force [info nameofexecutable] $targetname"
I suspect the file attribute $targetname -permission 0755 is giving an error. I wanted to know how can I give permission to in windows
For windows, you need to take the following steps:
# Rename the original file to a new name.
file rename -force client.exe client-old.exe
# Rename (or copy) the new file to the target name.
file rename -force autoupdate-client.exe client.exe
# Now (try) to remove the old file
catch { file delete -force client-old.exe }
There is no guarantee that the old executable can be removed at this time. You may need to remove it at a later time.
C:\Users\bll\Desktop\BallroomDJ\windows\64\tcl\bin>copy tclsh.exe t1.exe
1 file(s) copied.
C:\Users\bll\Desktop\BallroomDJ\windows\64\tcl\bin>copy tclsh.exe t2.exe
1 file(s) copied.
C:\Users\bll\Desktop\BallroomDJ\windows\64\tcl\bin>.\t1.exe
% file rename -force t1.exe t1-old.exe
% file rename -force t2.exe t1.exe
% file delete -force t1-old.exe
error deleting "t1-old.exe": permission denied
% exit
C:\Users\bll\Desktop\BallroomDJ\windows\64\tcl\bin>dir t*.exe
Directory of C:\Users\bll\Desktop\BallroomDJ\windows\64\tcl\bin
2017-10-23 10:37 453,579 t1-old.exe
2017-10-23 10:37 453,579 t1.exe
2017-10-23 10:37 453,579 tclsh.exe
C:\Users\bll\Desktop\BallroomDJ\windows\64\tcl\bin>
Edit:
Windows has no notion of execute permissions. The file attributes
command may not be doing what you think.