About Windows EXE Executable Release

Asked 2 years ago, Updated 2 years ago, 123 views

Compiled with Visual Studio (C#),
I have a question about the release of the Windows EXE executable.

Boot to Task Scheduler as a batch system, but
Due to frequent system fixes, releases are required each time.

However, if you release (overwrite the EXE file) while the system is running,
An overwrite error occurs during startup.


for running EXE
To reflect the latest system refresh from the next run What should I do?

I have a plan below, but it's not smart, so
There are disadvantages that it takes time to start running.
Do you have any other smart ideas?

Do you have a startup framework?

<Proposal>
1.Create an executable EXE file by copying the main body EXE file at the start of the process (same EXE file)
2. Launch the executable EXE file
3. Release the EXE file (overwrite the EXE file) because the EXE file can be overwritten even if it is running

c# visual-studio winexe

2022-09-30 17:53

2 Answers

The direct attack method is Windows Installer.If the file is in use, try to replace it after reboot using Restart Manager.If you don't like rebooting, it's out of the question.

774RRR's proposed ClickOnce has automatic update functionality.However, since ClickOnce assumes interaction on the desktop, booting from the task scheduler may not work properly.Starting as a service is not supported at least.

Other than this, I don't think there is a startup framework available.

Is it necessary to separate the loader program from the main unit?

  • The installer places the main program with a certain file name, such as serial numbers
  • The loader program removes unnecessary files, leaving the latest ones
  • The loader program starts the latest unit

and so on.Loader programs are easy to understand and may be good to write in scripting languages such as PowerShell.


2022-09-30 17:53

If you want to keep the system running and replace only the affected programs,
US>Explicitly exit and replace the applicable program with one of the following:
You may want to restart the program.

Also, this is behind-the-scenes, but you can rename the program you are running.
You can rename EXE files while the program is running!

  • Renaming the current program
  • Copy new programs to the same location
  • Remove old files that you renamed after starting the program

Traditionally, if you can wait until the system reboots, you can use the PendMoves and MoveFile tools in Windows Sysinternals.
You can also create your own tools using the MoveFileEx API that you use in the tool.

If you have a large number of files and you have dependencies or configuration changes, it is recommended that you create an installation package that matches the Windows Installer.
There's a tool like this.WiX Tutorial Japanese translation

@774RR After reading the comments, it seems that VisualStudio can do it easily.
Publish the application in ClickOnce

However, I'm not sure if this information will still be applied, but it may not be suitable for the purpose of the questioner.
Permissions - ClickOnce

"ClickOnce" requires lowering the installation barriers to enable use like web applications distributed from the Internet to an unspecified number of people, and allows installation without administrator privileges.

  • For this reason, the destination (or cache space, to be exact) cannot be changed from a directory below "%USERPROFILE%\Local Settings\Apps" (this will cause applications to be cached separately for each user in storage).
  • It is customary to use a directory below this environment variable "USERPROFILE" for storage where resources and data are stored (for security reasons, this is to prevent other users from viewing the data).
  • Using "isolated storage" you can also protect data between "ClickOnce applications").

UAC-ClickOnce

The ClickOnce application with administrator privileges cannot be run.
~Omitted in the middle~
There is a hack here, and you can start a new process with administrator privileges.


2022-09-30 17:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.