Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2007, 05:30 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default Installer Context.Parameters doesn't instantiate

I have created a service and I need to take the name of the service from the assembly file during installation. I need to do this because the user will need to run multiple instances of this service. I plan to allow the user to rename the executable and install the renamed service.

The only way I have found so far to do this is to use the Installer Context which, according to MSDN "Gets or sets information about the current installation" including the command line parameters passed to InstallUtil. However, whenever I attempt to get the Context.Parameters I get the following runtime error (during installation):

"Object Reference not set to an instance of an object."

Here are the lines that fail:

Code:
        InstallContext ic = this.Context;
        StringDictionary sd = ic.Parameters;
Only the second line fails. "ic" gets created with no errors.

Does anyone know how to get Context Parameters to work on an installer object? or how to get the "assemblypath" which is the parameter I believe I need. Or anyother way to get the file name of the installed file using the Installation technique implemented in C#?

Thanks for the help.

What you don't know can hurt you!
__________________
What you don\'t know can hurt you!
 
Old December 20th, 2007, 05:52 PM
Registered User
 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the same problem - for the same reason. Context is null, and I can't get the parameter values passed from installutil.exe. have you found a solution? I may be exploring reading another value from the console, but that's a kludge, and I don't want to do it.

 
Old December 20th, 2007, 06:56 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

I do have a solution that is very kludgie, but works for me with some caveats:

Code:
        String[] arFiles = System.IO.Directory.GetFiles(".", "*.exe");
        if (arFiles.Length > 0)
        {
          String[] tokens = arFiles[0].Split(new char[] { '.' });
          ServiceName = tokens[1].Substring(1, tokens[1].Length - 1);
        }
This takes the first file with and extension of "exe" and uses that. My intent is that my service will always reside in a folder by itself along with it's various supporting files. So this works, but I would really be intersted in another solution!


What you don't know can hurt you!
 
Old January 15th, 2008, 06:47 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

I finally found the solution. This should work in all circumstances!

<code>
String[] args = System.Environment.GetCommandLineArgs();
String[] tokens = args[1].Split(new char[] { '.' });
ServiceName = tokens[0];
</code>



What you don't know can hurt you!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to set context in web.xml or context.xml. dchicks Apache Tomcat 1 March 7th, 2008 07:59 AM
Instantiate a control vbwrangler Reporting Services 0 January 3rd, 2008 05:19 PM
Instantiate Integer array in a stucture hashtlishnii VB.NET 2002/2003 Basics 2 June 18th, 2004 11:56 AM
instantiate a form object by its name in MS Access sky2000 Access VBA 1 May 6th, 2004 03:44 AM
Could not instantiate ActiveX control because the karthey VS.NET 2002/2003 0 July 1st, 2003 05:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.