I have a Win UI 3 app that checks it here is a new update available, it dowloads the installer, but is it possible to execute such installer without closing the app?
How execute the installer from the code?
How to handle tha installation from within the app without closing?
Is it to complex? or should I just have the user do it manually?
NO. The executable is in memory (and may have locked files or resources). In order to get an update it will have to be relaunched. If your code is modular, think plugins, these could be updated in place.
Most applications launch a helper app then close themselves, because Windows usually blocks changes to executable files that are in use.
The app might pass its own process ID to the helper app so that it can wait for the process ID to disappear before attempting to update the file.
If not, the helper app might scan the process list for the EXE name, and pop up a message asking you to close the main app. It repeats this until there are no instances of the EXE in the process list.
Related
I was wondering if it is possible to open a second project (in the same solution as the first one) by code in the first project.
For example i have one form application project and another console application project.
The form application starts and when the user clicks a button i want the console application to run and the form application to stop.
Or could someone tell me how to delete my application .exe file?
The projects don't need to be in the same solution to do that. Just use Process.Start to start the executable for another application, and then close the main form to end the current application.
If you don't want to run the code as an entirely different process then it may also make sense to have a 3rd project that is a "class library" that the other two projects could add a reference to. This would allow you to define common code used in either application, using classes that are generalized to be helpful in either project.
I'm not sure what you're trying to do; but Process class has Start and Kill methods that will let you launch / exit processes.
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
I have a small application which is a single executable. For context, this is deployed to Thin Client computers and runs automatically at boot. Users do not have the rights to close this application.
However, I need the application to be easy to update. I can't write my software to do any kind of auto-update routine, because these stations often have a write-blocker* which must be disabled beforehand.
The simplest solution as an administrator is to copy the new EXE over the old using the various tools provided with the Thin Client, or Group Policy / scripting where required. The update doesn't have to be instantly effective - the next reboot is fine.
The problem with this is that, of course, the executable is in use and can't be overwritten. What's the best way to allow this to happen? Load the software completely into memory and run from there? Do some kind of routine which copies the exe to a temporary folder and then executes it with a command line switch so it doesn't endlessly loop?
*This may have caused some confusion. These are Windows XP / Windows 7 Embedded machines. For the most part they work like normal computers, except file system writes are transparently redirected to a cache drive. On a reboot, all changes are completely reverted. A normal script to update the machine would go something like:
Disable Write Blocker
Reboot Machine
Copy Files
Reboot Machine
Enable Write Blocker
Reboot Machine
However, my application will autostart after every reboot as there's no mechanism to inform it. As such, when the scripts get run the executable is still in use.
You might be able to use Windows' MoveFileEx with the DelayUntilReboot option.
To do this from C#, see this answer which shows how to set up the call to the Windows API.
Note: I think the call needs administrator privileges.
You could make of use of something called Shadow copying assemblies. Search the net, you'll find lots of examples (also on SO and Codeproject).
Obviously the application can only update if your write protection is disabled. Are you using FBWF or EWF? You might even exclude the application folder from write protection.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Writing a Windows system tray application with .NET
I want to develop a tray application. What this should do is it must keep looking for recently modified files.. once a file is get caught it a copy of that file to the web server. Therefore, user will be able to login to the website and later on user will be able to download those backing up files. what i want to know is how do i develop the tray application? Do i have to write a windows service for that? If so, i need a tray application to control the service (tray application must have sfunctionalities to start and stop service [Backup service], An option to choose the file extensions)
I'm using c#.
Thanks a lot in advance.
Sounds pretty straightforward.
Create a basic WinForms app. The app's main window should start "minimized" and should not show in the taskbar. But, it should have a "NotifyIcon" component, which allows the app to show in the system tray. Double-clicking the NotifyIcon would restore the window, show the window in the taskbar and hide the NotifyIcon until the window is minimized or closed again.
This application can do the file watching on its own, or it can edit the configuration used by a Windows service; either way would work. Either way, you need to set up a FileSystemWatcher (or several of them) that monitors files in the directories the user wants you to check. When a FileSystemWatcher sees a file change, it'll fire an event that you can handle by performing the upload to the web server.
Just as an aside to the whole design; if you're implementing an online backup system (which it appears that you are), I would make sure that the user has access to several past iterations of the file, in case they want to restore a previous version. You should also have virus-checking; the last thing a user would need is for a virus to wreck their files AND for your backup system to have backed up the wrecked files.
I personally wouldn't make it like a Windows Service, but would choose a simple application that "lives" on behind of system. It's easier to maintain and update, uninstall from the client (on his request). In short, for something simple I wouldn't go for Windows Service.
I would add a sys-tray component, with some menus.
You can have a look at WPF NotifyIcon from Philipp Sumi.
One of menu items can have an item that registers executable to run on startup of the OS.
You can achieve that with kind of code:
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
Assembly curAssembly = Assembly.GetExecutingAssembly();
key.SetValue(curAssembly.GetName().Name, curAssembly.Location);
If for some reason, cause it's not very clear from your post, your application, indeed, goes to manage some serious amount of data on considerable production environment, go for WindowsService and manage all related to it stuff.
Hope this helps.
I have a question. The problem is that I have another process which invoked ShowDialog() method, I need to close this dialog from another process but I need to close it with returning DialogResult.OK.
So from my .net program(another process) I want to close it successfully. I tried to use winapi to solve this problem, tried EndDialog function, but it returns error that ACCESS_DENIED. Tried to use hooks but those return error_no_token.
I need this to start msi installer silently. I start it with /qn switch, but this damn installer has embedded action that shows dialog in any case. I tried to close this window with sendmessage function, but in this case installer says that it is error, and rolls back the install process. I can fill all the values programmatically and click OK button on the dialog, but it requires to fill ALL THE VALUES, and there are lots of them, so it is time consuming. The purpose of this dialog is to create config file, which I can create manually later, after installation.
Is there any way to accomplish this task?
It sounds like the main issue you are having is doing a end-run around the validation for the text fields. As you said you would be editing the configuration files later just put some dummy values in each box and click the OK the way that causes the validation to happen.
Sometimes you need to change a bad design to remove the need to do a hard task, rather then keep fighting the system.
A UI is owned by one process, and apart from automating tests, should only be changed by that process or the user.
There used to be installer toolkits aims at system admins, that would watch the registry and file system while running a installer and then create a custom MSI file to automate the process. This may be another way for you to go.
Is there any good way to handle a forced exit in C#?
I have a formless C# application that talks to an LCD over serial. Once the application is running, the only way to kill it is with task manager. The trouble with this is that the program needs to turn the LCD off when it is done, and it doesn't look as if my Application.ApplicationExit event is ever fired in this condition.
Any ideas?
Once the application is running, the only way to kill it is with task manager.
My big idea would be to change this.
Stick an icon in the notification area that the user can use to shut your app down properly, or set it up so that running the app again will instead shut down an already-running instance if one exists, or any other way that sounds like a good idea.
Requiring a user to use Task Manager to shut down your application screams poor design.
Write a code in your program loop (with a timer perhaps) to read a file or a registry key. For example if a file at C:\YOURPROGRAM\CLOSEME contains text "closeme", close your program gracefully. Write another program that write that C:\YOURPROGRAM\CLOSEME file. So, whenever you want to shutdown your program, don't use taskmanager, instead, open second program.
Some options:
Write a separate process with a GUI that can start and stop the main process. For example, when you install the Apache web server on Windows the server itself is installed as a service. It can be started and stopped from the system services management panel, but it also comes with a "monitor" process that sits in the notification area, tells you whether Apache is running and lets you start or stop it manually.
If it's acceptable for your use-case, make the application a console application. You can register a handler for when the user presses CTRL+C (see Console.CancelKeyPress) that performs your cleanup before your process exits. This still won't let you handle someone killing the process from Task Manager, but it's very easy to do and might be good enough depending on your situation.