[Download Sample Code]
This article demonstrates how to perform a "custom action" on the target computer at the end of an installation. Here we illustrate a sample to perform the custom action of copying the "Article.txt" file from the deployment destination directory, that is, from the ArticleSetup directory--where the Setup files will be installed on the target machine, to the Office 2003 XLSTART directory (i.e., Program Files/Microsoft Office/OFFICE11/XLSTART).
Here's the deployment destination directory structure:
Here's the Office 2003 XLSTART directory structure, which is where the Article.txt file will be copied from the deployment destination directory:
The following steps will implement the above concept.
- Add a Class Library project.
- To this project, add an Installer class. For more details, refer to the link http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemconfigurationinstallinstallerclasstopic.asp.
- Write the following code in the Install method of the Installer class.
1: public override void Install(IDictionary savedState)
2: {
3: string[] stradirs;
4:
5: foreach (String str in Directory.GetLogicalDrives())
6: {
7: try
8: {
9:
10: stradirs = Directory.GetDirectories(@str,
"Program Files/Microsoft Office/OFFICE11/XLSTART");
11:
12: if (stradirs.Length > 0)
13: {
14: Assembly objAssembly =
Assembly.GetAssembly(this.GetType());
15: string strPath = objAssembly.CodeBase;
16:
17:
18:
19: strPath = strPath.Replace("CustomDeployment.dll","");
20: strPath = strPath.Replace("
21: strPath = strPath.Replace("file:/","");
22:
23:
24: string strSetUpPath = strPath + "Article.txt";
25:
26: string strXLStartPath = stradirs[0] + "/Article.txt";
27:
28: if (File.Exists(strSetUpPath))
29: {
30:
31: if (File.Exists(strXLStartPath))
32: {
33: File.Delete(strXLStartPath);
34: File.Move(strSetUpPath, strXLStartPath);
35: }
36: else
37: {
38: File.Move(strSetUpPath, strXLStartPath);
39: }
40: }
41: break;
42: }
43: }
44: catch
45: {
46: }
47: }
48: }
- Add the SetUp project.
- In the File System Editor (SetUp), add the Article.txt file and set the class library project as the Primary Output project in the Application Folder.
- In the Custom Action Editor (Set Up), add the Primary Output project to the Install folder.
- Compile the Solution.
- Install the Deployment Project.
- Go to C:\Program Files\Microsoft Office\OFFICE11\XLSTART and find the Article.txt file.
Conclusion
Here we have demonstrated the process of executing custom code when the application is installed. This helps to implement the custom action during the Setup installation.
Software Requirements
- .NET Framework 1.0 or 1.1
- Office 2003