View Full Version : Running msi and shutting down/restarting an application
dwenco
07-21-2008, 06:13 PM
I would like to do the following:
1) Copy a .msi file + other data files onto the target (client) directory
2) Shut down the application to be updated (that is running) on my client's machine
3) Run the msi file on the client's machine
4) Restart the application after the installation
In my server script I am doing this once the files have been downloaded:
======================================
strExtractPath = "%SourceFolder%\\Patches\\Wenco Configuration Manager 3.5.0.msi";
strCommandLine = "-i \""..strExtractPath.."\" REINSTALL=ALL REINSTALLMODE=vomus";
Screen.Show(strCommandLine);
PatchReturnCode = MSI.RunMsiexec(strCommandLine);
=======================================
When I run trueupdate.exe on my client's machine, it is able to download the files, but the installation does not work. I am getting the error "This installation package could not be opened". Could you help me please?
And, I am also unable to figure out how to do a shut down/restart on the server script. Could you also give me some suggestions please?
Many thanks.
upeters
07-21-2008, 08:09 PM
There are some problems with the code you posted that might cause the misbehavior. You made several questions, I'll try to answer them individually...
1) Copy a .msi file + other data files onto the target (client) directory
You stated that this part works, so there isn't much to comment.
2) Shut down the application to be updated (that is running) on my client's machine
The easiest way to close the running application is sending a Windows message to it, ordering it to close. You need to know the window title of your running application. Let's assume that it is "My Application # Version 1.0.0.0". So we will cycle through all windows on the desktop to find part of this title, and get a handle to the window. Once you have the handle, order the corresponding window to close. You can force a shutdown, or order it to close gracefully, just look in the documentation for Window.Close().
wasative = 0;
-- close the running application
aplications = Window.EnumerateTitles(false)
for handle, title in aplicativos do
result = String.Find(title, "My Application #", 1, false);
if (result ~= -1) then
Window.Close(handle, CLOSEWND_SENDMESSAGE);
wasactive = 1;
end
end
That should close your application gracefully.
3) Run the msi file on the client's machine
strExtractPath = "%SourceFolder%\\Patches\\Wenco Configuration Manager 3.5.0.msi";
strCommandLine = "-i \""..strExtractPath.."\" REINSTALL=ALL REINSTALLMODE=vomus";
Screen.Show(strCommandLine);
PatchReturnCode = MSI.RunMsiexec(strCommandLine);
When I run trueupdate.exe on my client's machine, it is able to download the files, but the installation does not work. I am getting the error "This installation package could not be opened". Could you help me please?
Now here I see some problems. In the way you wrote, you are trying to show a screen, having the command line as name. This is probably wrong, and you shouldn't see anything here. If this was some kind of debug to see what you are doing, you should use Dialog.Message() instead. You should use Screen.Show() only to show some of the screens you have in your project, like "Update Required", "Download File", etc.
The next thing I see is that you are using a session variable %SourceFolder% without expanding it properly. If you want to use the contents of the session variable, use it like this:
strExtractPath = SessionVar.Expand("%SourceFolder%\\Patches\\Wenco Configuration Manager 3.5.0.msi");
strCommandLine = "-i \"" .. strExtractPath .. "\" REINSTALL=ALL REINSTALLMODE=vomus";
Dialog.Message("Debugging the command line", strCommandLine, MB_OK);
PatchReturnCode = MSI.RunMsiexec(strCommandLine);
I am just typing this, there could be an additional mistake somewhere, but you should now see how to make this work correctly.
4) Restart the application after the installation
Let's return to step 2. You see that variable "wasactive" I set there? If a window was found (and hopefully closed), that variable will be set with 1, if not it should contain 0. So, at the end of you update, you know if the application was running and should be restarted. You might want to restart the application after every update, but I chose to show you how to restart the application only if it was really running before the update, so make your modifications as desired.
if wasactive ~= 0 then
File.Run(SessionVar.Expand("%SourceFolder%\\ApplicationName.exe"), "", "", SW_SHOWNORMAL, false);
end
Hope this helps.
Ulrich
dwenco
07-22-2008, 04:25 PM
Thanks a lot for your help Ulrich. That really helps.
Sorry I am stuck on another problem again, could you help me again please?
I would like the Update Server Location to be configurable (because I won't know where the server is until after the application has been deployed to my clients) and I am setting the "TrueUpdate Server 1" under Project Settings to be a session variable (%UpdateServer%). In my Client Script I am doing the following:
=======================================
UpdateServerLocation = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Wenco\\ConfigurationManager", "Update_Server");
SessionVar.Set("%UpdateServer%", UpdateServerLocation);
tableTrueUpdateServers = TrueUpdate.GetUpdateServerList();
if(tableTrueUpdateServers) then
-- Loop through the list of TrueUpdate Servers
for index, ServerName in tableTrueUpdateServers do
-- Attempt to download the server configuration files
GotServerFiles = TrueUpdate.GetServerFile(ServerName, false);
-- If the download was successful, run the server script
if(GotServerFiles) then
TrueUpdate.RunScript("Server Script");
break;
end
end
end
============================================
I have verified that "tableTrueUpdateServers" is true, and there are server scripts (ts1) in the update server directory specified by %UpdateServer%, but "GotServerFiles" is always false. Could you give me some suggestion please? Many thanks!
upeters
07-22-2008, 06:45 PM
I am afraid that this won't work.
You have to know at least the first update server before you deploy your work. Afterwards, you can point to a new address, include new and delete obsolete servers, but to get the updating process started, the very first TrueUpdate Server has to be known, and it has to stay active as long as somebody may use the original installer you shipped. You will have to inform the location (ip address or domain name and folder, as well as the protocol to be used) in the menu > Project > TrueUpdate Servers. This information will be encrypted into a *.dat file, and has to be shipped/deployed with you first install of your product. After that, almost anything is possible. (Note that the first server can be an address on the same computer where you are installing, or on the local network - but you must make sure that the information is available before the first update is attempted.)
For example, if you chose from that point on that you will store your update files on another servers, just update the TrueUpdate files (*.ts1, *.ts2 and *.ts3), and place new versions on the new servers, and on the original (the startup) server as well. Once a client tries to update itself for the first time, it will have to use the *.dat file you originally shipped. Using the info embedded, it will try to get the current update information. If the servers changed, you will get a message that the TrueUpdate client has to be restarted - it will then load the new info and query the new server(s) for all future updates.
So even if you eventually will change your update servers some day, right now you will have to inform the first server you will use to initiate the whole process. I am not sure I made myself clear.
Ulrich
dwenco
07-23-2008, 12:37 PM
Thanks a lot for your help.
Actually I am seeing something quite different from what you mentioned in your response. The scenario I described in my last post wasn't working because of a problem with the setting of my client machine. After I fixed that it is actually working now, so I would like to confirm with you that it is not working for me for the wrong reasons (I wouldn't expect it to work if you said it wouldn't), because it is an important requirement for us. This is what I did:
1) Create a new TrueUpdate Project
2) On Project Wizard screen:
- Select "LAN" for Download Method
- Enter %UpdateServer% for TrueUpdate Server (LAN)
- "I will do this myself" for Upload Method
- Select "Custom" for Update Method
- Run Multiple Installer/Path Files (LAN)
3) In my client script, I pretty much have what I had before (retrieving the location of %UpdateServer% from the client's local registry), call TrueUpdate.GetUpdateServerList, TrueUpdate.GetServerFile, and run script.
4) Publish -> Build on TrueUpdate
5) Copy the TrueUpdateClient.exe and TrueUpdateClient.dat from the TrueUpdate output directory to my client machine (which is a virtual machine). The Local registry on the client machine stores the update server location to be a local directory ("C:\Local Update Server\"). I also store the server scripts (ts1, ts2, ts3, as well as my .msi update files on the same update server location.
5) When I run TrueUpdateClient.exe on my client machine, it does perform the installation all right.
I have confirmed that I only have %UpdateServer% as the TrueUpdate Server under Project Settings.
Thank you again for your assistance.
upeters
07-23-2008, 01:35 PM
Great. I thought that it wouldn't work, but it sure nice to see that it is indeed possible to proceed the way you used. If it works, leave it this way. If you want to be really sure if there won't be any problems, you might have to get word from the Indigo Rose staff itself, as everybody else here is just trying to help, but always subject to mistakes.
Ulrich
dwenco
07-23-2008, 03:41 PM
Thank you UPeters :)
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.