Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[3441] Creating a Windows Service in VB.NET

Last post 05-23-2008 10:35 AM by mekaushik. 102 replies.
Page 6 of 7 (103 items) « First ... < Previous 3 4 5 6 7 Next >
Sort Posts: Previous Next
  • 08-10-2005 10:45 AM In reply to

    • vanj
    • Not Ranked
    • Joined on 07-26-2005
    • Junior Member
    • Points 80
    "net start ServiceName"  is the command line argument to run the windows service without going to the ControlPanel-->Administrative Tools-->Services.

    I think you can create a .abt file with the above command and run that file from your application.

    And select StartType as Automatic under the ServiceInstaller properties.

    Hope that helps
    ~vanj
    • Post Points: 0
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 08-10-2005 10:47 AM In reply to

    • vanj
    • Not Ranked
    • Joined on 07-26-2005
    • Junior Member
    • Points 80
    sorry there was a spelling mistake in the last reply.

    I meant to create .bat file not .abt file.

    ~vanj
    • Post Points: 0
  • 09-16-2005 11:16 AM In reply to

    Service with UI

    Hi,

    in the article you say it is possible to create a service with a user interface.
    I have tryed this but for some reason my service doesn't want to run.
    First I added a windows form to my project.
    In my service I have a global variable that is my form.
    Code:
    Public oForm as FormUI


    In the onStart I set the oForm as new instance.
    Code:
    oForm = new FormUI


    After building my service and installing it with success I try to start the service but I get the following message:
    Code:
    ...service on local computer started and then stopped...


    I can't find any article that describes the implementation of a UI for a service.
    Could somebody please help me out?

    Kind regards,

    Steve
    • Post Points: 0
  • 09-20-2005 1:03 AM In reply to

    • TheToad
    • Not Ranked
    • Joined on 09-19-2005
    • New Member
    • Points 10

    Service doesn't start, has ADODB

    I have created a VB.Net windows service exactly as you outline, and it works a treat , I have then extended this so it interacts with a MS SQL, this installs and works, "again a treat", on the same machine I developed it on (VS 2003.)  When I install DOTnet on another machine and then install this service, it installs OK, BUT it won't start.  I've trimmed the code right back to find that the problem seems to be  "Public conDB As New ADODB.Connection"
    • Post Points: 0
  • 09-20-2005 4:08 AM In reply to

    • TheToad
    • Not Ranked
    • Joined on 09-19-2005
    • New Member
    • Points 10
    When you build the service (create the exe) it is placed usually under a \bin sub-folder of the project, I have found that you must place every file in that folder in the exactly same directory and drive letter if installing it to another machine.  eg c:\myservice\bin for this example.

    remember that you can't be in the services view, if you want it to uninstall properly.

    Below is a batch file that will install, and start the service you create via the  "Creating a Windows Service in VB.NET" topic.

    c:
    cd \WINNT\Microsoft.NET\Framework\v1.1.4322\
    net stop "MyService"
    pause
    installutil /u "C:\MyService\bin\MyService.exe"
    pause
    installutil "C:\MyService\bin\MyService.exe"
    pause
    net start "MyService"
    pause
    • Post Points: 0
  • 10-10-2005 2:47 PM In reply to

    windows service

    hi all

    There is a small problem, cud u all help me.
    I created a windows service and when i tried to install it using InstallUtil from .net framework it gives me system.io.filenotfound exception, although the service has been created free of errors n warnings.

    Regards
    Akansha
    • Post Points: 0
  • 11-29-2005 12:09 PM In reply to

    Same Error

    Quote:
    [1]Posted by akansha_kesarwani on 10 Oct 2005 02:47 PM[/1]
    hi all

    There is a small problem, cud u all help me.
    I created a windows service and when i tried to install it using InstallUtil from .net framework it gives me system.io.filenotfound exception, although the service has been created free of errors n warnings.

    Regards
    Akansha



    Hi evrybody....

               We r also getting the same error as above.....kindly help us.....
    • Post Points: 0
  • 12-05-2005 1:57 PM In reply to

    • maxfalc
    • Not Ranked
    • Joined on 12-05-2005
    • New Member
    • Points 5

    try this

    I had the same problem... I have noticed that InstallUtil has problem when you use directory with empty space inside
    (C:\mydata\vb projects\MyService)
    So simply I have tried to create the project in a directory without empty space and it works now..
    (C:\test\MyService)...
    But this is crazy... because the directory with empty space vb projects has been created by .net by default!!!
    I hope this useful for you...
    MAX
    • Post Points: 0
  • 12-07-2005 3:13 PM In reply to

    Spaces in name

    I had the same problem.  The command line does not like spaces in the file name without quotes.  It's not bothered by spaces in the path, I guess, because they are delineated by the "\"s.

    Instead of:

    InstallUtil c:\path name\file name.exe

    try...

    InstallUtil "c:\path name\file name.exe"

    • Post Points: 0
  • 01-27-2006 10:29 AM In reply to

    • mcouzin
    • Not Ranked
    • Joined on 01-27-2006
    • New Member
    • Points 5

    Windows Service with Visual Studio 2005

    Hi! How can I create and debug a windows service with Visual Studio 2005?

    Thanks.

    Marco.
    • Post Points: 0
  • 01-27-2006 9:11 PM In reply to

    Running a UI

    I got one step further than you, but only the one.  In the Services panel, double-click your new service and go to the second tab, Login.  Check the box that says "allow service to interact with the desktop".

    My service ran after I did that, but if a form displayed, the only thing that showed up was the window frame itself with none of the controls.  The service, form and all stopped accepting events and I had to attach and stop the service from the VS2005 IDE.  (A simple stop service didn't do it.)

    If anyone can demonstrate how to have a service that may occasionally interact with a desktop, we'd love ya forever mean it.

    I created two "use them only if you need them" forms for my service.  One allows interactive configuration and the other is a status form that has some informational boxes and progress meters.

    Breadcrumbs... need 'em.

    Bill
    • Post Points: 0
  • 02-02-2006 9:37 AM In reply to

    • grim234
    • Not Ranked
    • Joined on 02-02-2006
    • New Member
    • Points 10
    I'm also really interested in learning how a service can support a UI.

    dragonsteve: how do you get your forms to come up? I was thinking of having a seperate application somehow "unhiding" the service's UI, and I was wondering if you used a similar approach? Hmm.. that might sound like a dumb idea, but I haven't really gotten to the whole service bit yet. Basically I wrote an application that does a bunch of stuff on a user-defined schedule and I only realized later that it would be very useful to have my app run as a service, so the whole service bit is essentially an afterthought.
    • Post Points: 0
  • 02-02-2006 1:39 PM In reply to

    Service with a UI

    So far, not so good.  I made my service with two forms that I added to the project once the service class was set up.  My goal was the same as yours -- to have the forms pop up only when they're needed.  One piece of the mystery was to go into Services from the Control Panel, double click my service, then under the second tab, tick the box for "Allow service to interact with the desktop".

    After that, the service would start.  When it found that it was running for the first time and wanted configuration, it dutifully attempted to show the configuration form.  All I got was just the window frame, but none of the controls would display.  The entire application stopped accepting any event except for the shutdown.  At least that worked.

    I read further on MS's site and they suggest that we create two pieces: the service part that runs in the background and the UI part that runs as a typical desktop app.  They suggested that we use named pipes or some other form of IPC to communicate between the two pieces.

    Decidedly, this is a weird and nastily inconvenient way to create a service with a UI.  Me, I'm a *nix kinda guy; I'm used to a service being a program or a program being a service as the situation dictates.  So far, VS2005 and VB.Net are well short of Eclipse, but it's what I've got to work with for a particular small set of customers.

    If you guys find a workaround or decide to use the two-sided approach, would you be so kind as to repost here?  Thanks!
    Bill

    PS: OH! By the way:  if you use InstallUtil.exe to install the service, then wish to use InstallUtil.exe /U to uninstall the service, make sure that you have the Services window of the control panel closed.  Otherwise, the service will be marked for deletion and will remain in the Services window until you reboot.  Nasty, but that's the way it works.
    • Post Points: 0
  • 02-03-2006 7:32 AM In reply to

    • grim234
    • Not Ranked
    • Joined on 02-02-2006
    • New Member
    • Points 10
    OK, I got it to work. Here's what I have so far: I created a thread to handle the UI, so basically it creates the form, and runs it

    Code:

    //coding in thin air, likely to have a number of bugs, but I'm sure you'll get the jist of things
    private Form1 myForm = null;
    private Thread myThread = null;

    public override void OnStart()
    {
      myThread = new Thread(new ThreadStart(ThreadEntry));  //or something like that
      myThread.Start();
    }

    public override void OnStop()
    {
      myThread.Abort();
    }

    private void ThreadEntry()
    {
      myForm = new Form1();
      Application.Run(myForm);
    }


    Then, I did some crappy stuff just to see if this works, so I used an overridden OnContinue to show the form

    Code:

    public override void OnContinue()
    {
      myForm.Show();
      base.OnContinue();
    }


    ...and I had a button that would hide the entire form.

    I think the reason your controls weren't showing up was due to a threading issue (i.e. the service is probably busy doing it's own thing, and doesn't get around to refreshing the controls). Errm... other than that, yeah you basically have to have the "Interact with Desktop" thing turned on. I hope this helps. Let me know if you have any questions!

    Oh, and thanks for the great tip about removing the service :) Saved me tons of restarting I bet.

    -Z
    • Post Points: 0
  • 02-03-2006 3:12 PM In reply to

    Bravo!

    Well done.  I had considered threads, but since I'm not familiar with Windows' notion of environment containment, I wasn't sure if that would work.  Glad you got ahead of me there.  I'm going to create another service project and move bits into it from the desktop project.

    Glad the tip worked for ya.  I discovered it quite by accident whilst installing and uninstalling the original service project. For what it saved me in hair-tearing (and I haven't much left!) I thought it might be worth a mention ;-)

    BTW, I was pleasantly surprised with the new tickbox in class projects that will expose a Dot Net component to COM.  In VS2003 it was a PITA to create a COM wrapper for classes you'd like to use with IIS.  Well, boyhowdy, in VS2005, just tick the box and the next time the class compiles, you can take that resulting DLL, plonk it in your \inetpub\www folder and use it as if really had belonged there all along.

    I tried a Hello World ASPx form using my database transport DLL that I created in VS2005 as described and miracle of miracles, it worked perfectly the first time.

    After that, I think I'll quit for the week; not to press my good luck :-D

    Best,
    Bill
    • Post Points: 0
Page 6 of 7 (103 items) « First ... < Previous 3 4 5 6 7 Next >