Click here to Skip to main content
15,914,109 members
Home / Discussions / C#
   

C#

 
GeneralRe: Code-Completion Pin
Peter Nirschl27-Mar-04 20:56
Peter Nirschl27-Mar-04 20:56 
GeneralRe: Code-Completion Pin
leppie27-Mar-04 21:51
leppie27-Mar-04 21:51 
GeneralRe: Code-Completion Pin
Peter Nirschl28-Mar-04 5:07
Peter Nirschl28-Mar-04 5:07 
GeneralRe: Code-Completion Pin
leppie28-Mar-04 7:29
leppie28-Mar-04 7:29 
GeneralWindows Services Installation Pin
opopov26-Mar-04 7:32
opopov26-Mar-04 7:32 
GeneralRe: Windows Services Installation Pin
Heath Stewart26-Mar-04 7:46
protectorHeath Stewart26-Mar-04 7:46 
GeneralRe: Windows Services Installation Pin
opopov26-Mar-04 10:10
opopov26-Mar-04 10:10 
GeneralRe: Windows Services Installation Pin
Heath Stewart26-Mar-04 11:16
protectorHeath Stewart26-Mar-04 11:16 
I threw together a simple example using the following code and it worked fine:
static void Main(string[] args)
{
  if (args.Length > 0)
  {
    string[] rest = new string[args.Length - 1];
    if (rest.Length > 0) args.CopyTo(rest, 1);

    if (string.Compare(args[0], "/install", true) == 0)
    {
      Install(rest);
      return;
    }
    else if (string.Compare(args[0], "/uninstall", true) == 0)
    {
      Uninstall(rest);
      return;
    }
  }

  ServiceBase.Run(new Service1());
}

static void Install(string[] args)
{
  AssemblyInstaller installer = new AssemblyInstaller(
    typeof(Service1).Assembly.Location, args);
  IDictionary state = new Hashtable();
  try
  {
    installer.UseNewContext = true;
    installer.Install(state);
    installer.Commit(state);
  }
  catch (Exception e)
  {
    installer.Rollback(state);
    Console.Error.WriteLine(e.Message);
  }
}

static void Uninstall(string[] args)
{
  AssemblyInstaller installer = new AssemblyInstaller(
    typeof(Service1).Assembly.Location, args);
  IDictionary state = new Hashtable();
  try
  {
    installer.Uninstall(state);
  }
  catch (Exception e)
  {
    Console.Error.WriteLine(e.Message);
  }
}
While Application.Location should return the correct path, it puts a possibly unnecessary dependency on the System.Windows.Forms.dll assembly. If you don't need to reference that assembly, just use Assembly.Location instead (there's many ways to get the current assembly, I just got it from the Type).

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Windows Services Installation Pin
opopov26-Mar-04 22:29
opopov26-Mar-04 22:29 
GeneralRe: Windows Services Installation Pin
Heath Stewart26-Mar-04 22:35
protectorHeath Stewart26-Mar-04 22:35 
GeneralDatagrid, handling events Pin
benqazou26-Mar-04 7:09
benqazou26-Mar-04 7:09 
GeneralRe: Datagrid, handling events Pin
Charlie Williams26-Mar-04 7:38
Charlie Williams26-Mar-04 7:38 
GeneralRe: Datagrid, handling events Pin
Heath Stewart26-Mar-04 7:58
protectorHeath Stewart26-Mar-04 7:58 
Generalrunning application in windows Pin
amal_pro8326-Mar-04 6:25
amal_pro8326-Mar-04 6:25 
GeneralRe: running application in windows Pin
tonaxxl26-Mar-04 6:38
tonaxxl26-Mar-04 6:38 
GeneralRe: running application in windows Pin
Dave Kreskowiak26-Mar-04 7:27
mveDave Kreskowiak26-Mar-04 7:27 
GeneralRe: running application in windows Pin
amal_pro8326-Mar-04 19:31
amal_pro8326-Mar-04 19:31 
GeneralRe: running application in windows Pin
Dave Kreskowiak27-Mar-04 3:37
mveDave Kreskowiak27-Mar-04 3:37 
GeneralRe: running application in windows Pin
amal_pro8327-Mar-04 21:46
amal_pro8327-Mar-04 21:46 
GeneralRe: running application in windows Pin
Dave Kreskowiak28-Mar-04 4:31
mveDave Kreskowiak28-Mar-04 4:31 
QuestionHow to pass null to a ref bool or out bool parameter? Pin
yyf26-Mar-04 5:52
yyf26-Mar-04 5:52 
AnswerRe: How to pass null to a ref bool or out bool parameter? Pin
Charlie Williams26-Mar-04 6:41
Charlie Williams26-Mar-04 6:41 
GeneralRe: How to pass null to a ref bool or out bool parameter? Pin
partyganger26-Mar-04 9:41
partyganger26-Mar-04 9:41 
AnswerRe: How to pass null to a ref bool or out bool parameter? Pin
Judah Gabriel Himango26-Mar-04 6:45
sponsorJudah Gabriel Himango26-Mar-04 6:45 
GeneralRe: How to pass null to a ref bool or out bool parameter? Pin
Heath Stewart26-Mar-04 7:54
protectorHeath Stewart26-Mar-04 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.