Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / November 2003

Tip: Looking for answers? Try searching our database.

Creating Windows Service using JScript.NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Harjit S. Batra - 31 Oct 2003 16:36 GMT
I am trying to create a windows service in JScript and am confused. I have
two files, SimpleService.JS and SimpleServiceInstaller.JS as follows:

SimpleService.JS
/------------------------------------------------------------------------
import System;
import System.ServiceProcess;
import System.Diagnostics;
import System.Timers;

class SimpleService extends ServiceBase
{
  private var timer : Timer = null;

  function SimpleService()
  {
     this.CanPauseAndContinue = true;
     this.ServiceName = "SimpleService";
     this.timer = new Timer();
     this.timer.Interval = 1000;
     this.timer.add_Elapsed(OnTimer);
  }

  protected override function OnStart(args : String[])
  {
     EventLog.WriteEntry("Simple Service started");
     this.timer.Enabled = true;
  }

  protected override function OnStop()
  {
     EventLog.WriteEntry("Simple Service stopped");
     this.timer.Enabled = false;
  }

  protected override function OnPause()
  {
     EventLog.WriteEntry("Simple Service paused");
     this.timer.Enabled = false;
  }

  protected override function OnContinue()
  {
     EventLog.WriteEntry("Simple Service continued");
     this.timer.Enabled = true;
  }

  function OnTimer(source : Object, e : ElapsedEventArgs)
  {
     EventLog.WriteEntry("Hello World from SimpleService!");
  }
}

ServiceBase.Run(new SimpleService());
/------------------------------------------------------------------------

and SimpleServiceInstaller.JS
/------------------------------------------------------------------------
import System;
import System.Collections;
import System.ComponentModel;
import System.Configuration.Install;
import System.ServiceProcess;

public RunInstallerAttribute(true) class SimpleServiceInstaller extends
Installer
{
   private var serviceInstaller : ServiceInstaller = null;
   private var serviceProcessInstaller : ServiceProcessInstaller = null;

   public function SimpleServiceInstaller()
   {
       serviceInstaller = new ServiceInstaller();
       serviceInstaller.ServiceName = "SimpleService";
       serviceInstaller.DisplayName = "Simple Service";
       serviceInstaller.StartType = ServiceStartMode.Manual;
       this.Installers.Add(serviceInstaller);

       serviceProcessInstaller = new ServiceProcessInstaller();
       serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
       this.Installers.Add(serviceProcessInstaller);
   }
}
/------------------------------------------------------------------------

I compiled both of them in the following manner:
jsc /t:exe SimpleService.js
and
jsc /t:exe SimpleServiceInstaller.js

And then installed the installer with:
installutil SimpleServiceInstaller.exe

On examining the Services.MMC, I see the service "SimpleService" in there
but whenever I attempt to start the service I get the dialog "Could not
start the Simple Service service on Local Computer, Error 1053: ..."!

Can someone please tell me what am I doing wrong and how do I fix it?

What confuses me is how the Installer knows which executable to look into
for the implementation of the service - should either the service or the
installer be written as a package and referenced by the other and if so
which one? OR should one of them be written as a DLL (which one)? OR should
they both be part of the same package? In short, where is the link between
"serviceInstaller.ServiceName = "SimpleService";" in the Installer and
"this.ServiceName = "SimpleService";" in the Service?

Thanks,

Harjit S. Batra
Harjit S. Batra - 31 Oct 2003 23:00 GMT
OK Folks, I figured this one out, thanks to help from Steve Brown at
Microsoft.

My compile line should have looked like :
jsc /t:exe /out:SimpleService.exe SimpleService.js SimpleServiceInstaller.js

and therefore my install line should have read:
installutil SimpleService.exe

I was then able to start and stop the service with
net start SimpleService
and
net stop SimpleService

Once again, Thank You - Steve!

Harjit

> I am trying to create a windows service in JScript and am confused. I have
> two files, SimpleService.JS and SimpleServiceInstaller.JS as follows:
[quoted text clipped - 106 lines]
>
> Harjit S. Batra
Code Ronin - 13 Nov 2003 14:21 GMT
Thanks for sharing the code.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.