Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 27th, 2007, 05:30 PM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
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!
Reply With Quote
  #2 (permalink)  
Old December 20th, 2007, 05:52 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
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.

Reply With Quote
  #3 (permalink)  
Old December 20th, 2007, 06:56 PM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
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!
Reply With Quote
  #4 (permalink)  
Old January 15th, 2008, 06:47 PM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:04 PM.


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