New topic: 

ServiceApplication on windows.

<http://forums.realsoftware.com/viewtopic.php?t=47656>

         Page 1 of 1
   [ 10 posts ]                 Previous topic | Next topic          Author  
Message        abhimmit          Post subject: ServiceApplication on 
windows.Posted: Sun Apr 21, 2013 8:00 am                         
Joined: Mon Jan 10, 2011 1:29 pm
Posts: 19                I have created a consoleapplication and changed it to 
a service application. I have followed the documentation.
When installed and started on my machine, I'm getting the following error;
"No automation server present"

This is my Run method;
  App.TMR = New myTimer
  App.TMR.mode =Timer.ModeMultiple
  App.TMR.Period = App.TD  ' ** The amount of seconds the application is to 
wait.
  App.TMR.Enabled = True
  do
  App.DoEvents
  loop
  Quit(0)   
                             Top                msssltd          Post subject: 
Re: ServiceApplication on windows.Posted: Mon Apr 22, 2013 4:27 am              
                   
Joined: Fri Oct 28, 2005 7:05 am
Posts: 555
Location: Emsworth, UK                That looks like a Windows error rather 
than an RS error.

Are you using ActiveX / OLE / Com  controls somewhere in your application?      
_________________
Yes it's me in the avatar  
                             Top                abhimmit          Post subject: 
Re: ServiceApplication on windows.Posted: Mon Apr 22, 2013 4:54 am              
           
Joined: Mon Jan 10, 2011 1:29 pm
Posts: 19                I catch this error in the UnhandledException method of 
the application. When the service is started, I immediately get this error. I 
use no ActiveX or other external components.  

 Dim f as FolderItem = GetfolderItem("ErrorLog.txt")
  If f <> Nil then
  Try
  Dim t as TextOutputStream = TextOutputStream.Create(f)
  Try
    t.WriteLine(error.Message)
  Finally
    t.Close
    t = nil
  End Try
  Catch e as IOException
  //handle error
  End Try
  End if   
                             Top                msssltd          Post subject: 
Re: ServiceApplication on windows.Posted: Mon Apr 22, 2013 5:30 am              
                   
Joined: Fri Oct 28, 2005 7:05 am
Posts: 555
Location: Emsworth, UK                I just made a quick test using RS2012R1 
on Windows7 x64

//Add properties to app
// mTimer as Timer
// mCount as Integer

//Add methods to app
// evtTimerAction(tmr as Timer)

sub app.Run
  mTimer = new Timer
  AddHandler mTimer.Action, AddressOf evtTimerAction
  
  mTimer.Period = 1000
  mTimer.Mode = Timer.ModeMultiple
  mTimer.Enabled = True
  
  Do
  app.DoEvents
  Loop until mCount > 10
  
  Quit(0)
End

Sub evtTimerAction(tmr as timer)
  dim ts as TextOutputStream, f as folderitem
  dim dtNow as new Date
  
  mCount = mCount +1
  f = SpecialFolder.SharedApplicationData.Child("test.txt")
  If f.Exists Then
  ts = TextOutputStream.Append(f)
  Else
  ts = TextOutputStream.Create(f)
  End if
  ts.WriteLine str(mCount) + chr(9) + dtNow.LongTime
  ts.Close
End

sub App.Pause
  mTimer.Enabled = False
end

Sub App.Resume
  mTimer.Enabled = True
End

Sub App.Stop
  mCount = 100
End


Which compiles and runs as a service, as expected and without errors.      
_________________
Yes it's me in the avatar  
                             Top                abhimmit          Post subject: 
Re: ServiceApplication on windows.Posted: Mon Apr 22, 2013 9:30 am              
           
Joined: Mon Jan 10, 2011 1:29 pm
Posts: 19                Below is how my run method looks like. I would expect 
the program to open my database, which is the first method it should execute. 
When run from the editor, it works fine. When run as a windows service no luck. 
How did you register your service in windows 7? I also use windows 7 (64).

  mPaused = False
  App.TMR = New Timer
  
  if not mPaused then
  DBConnection()
  
  AddHandler App.TMR.action , AddressOf evtTimerAction
  App.TMR.Period = App.TD  ' ** The amount of seconds the application is to 
wait.
  App.TMR.mode =Timer.ModeMultiple
  App.TMR.Enabled = True
  do
  App.DoEvents
  loop 'until mCount > 10
  else
  quit(0)
  end if   
                             Top                msssltd          Post subject: 
Re: ServiceApplication on windows.Posted: Mon Apr 22, 2013 10:34 am             
                    
Joined: Fri Oct 28, 2005 7:05 am
Posts: 555
Location: Emsworth, UK                When services run fine from the IDE and 
fail when started by the Service Controller, it's most often a permissions 
problem.  The IDE starts processes in the security context of the user logged 
into the Desktop.  The Service Controller, starts processes with the security 
context configured in the Service Control Manager (registry).  If you don't 
configure a context, the service will most likely use Local System, which does 
not usually have access to user files and folders (post Vista).

So, if your database is a file saved somewhere in your home folder, the service 
might not have permission to open it when started by the Service Controller.  
As a temporary test, start services.msc, find your service and change it's 
security context (logon as) to  your own user account, changing the password 
accordingly.  Does that fix it?  If so, it's a permissions problem.

Because services are background tasks, which do not require a user to be logged 
in, it's best to create and save any files the services needs, using RS 
SpecialFolder.SharedApplicationData folder item object.

Windows 7 includes the SC console command for registering services.
E.g.
// First create a sub folder for your executable, call it C:\Program Files 
(x86)\MyService
// Copy the executable into the new folder. Let's say the exe is called 
myservice.exe
// Start an elevated command prompt
// Type the following, making sure a space follows the = signs
SC create myservice binpath= "%ProgramFiles(x86)%\MyService\myservice.exe" 
DisplayName= "My Service"
Start services.msc

//Find the newly created "My Service" and adjust the configuration (logon, 
password, start up etc) as needed.

//Remove the service using
SC delete myservice
      
_________________
Yes it's me in the avatar  
                             Top                abhimmit          Post subject: 
Re: ServiceApplication on windows.Posted: Mon Apr 22, 2013 1:44 pm              
           
Joined: Mon Jan 10, 2011 1:29 pm
Posts: 19                Thanks for all your advice. All you have explained I 
have tried. I have changed the service to run under an administrator account. I 
have created a new folder where the exe file and libraries are stored. When the 
service is started, I should see an ldb file coming up in the folder, which is 
a database lock file. But in my case this file is not created. Which gives me 
the impression that the run method is not executed when my program is run as a 
service. The service shuts down after a couple of minutes.

I have checked the event viewer and found the following error;

Faulting application name: monitormailservice.exe, version: 2.1.0.9, time 
stamp: 0x50d4fc8b
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc0000005
Fault offset: 0x00b3f599
Faulting process id: 0x1574
Faulting application start time: 0x01ce3f86142ef296
Faulting application path: 
d:\servicetools\monitormailservice\monitormailservice.exe
Faulting module path: unknown
Report Id: 7689e3ae-ab79-11e2-801b-08002700c897   
                             Top                msssltd          Post subject: 
Re: ServiceApplication on windows.Posted: Tue Apr 23, 2013 2:50 am              
                   
Joined: Fri Oct 28, 2005 7:05 am
Posts: 555
Location: Emsworth, UK                abhimmit wrote:Exception code: 0xc0000005
That's an Access Denied error, which makes it almost certainly a file 
permissions problem.

Post Vista and UAC.  An Administrator account is not really an Administrator 
account and members of the Administrators group, do not get access to 
everything on the file system (by default).  

Unless you have good reasons to do things differently;
1. Create a folder for your executable in c:\Program Files
2. Create a folder for the data files (accessed by your executable) in 
c:\ProgramData
3. Move your executable and data files to the folders you created (above)
4. Register your service using SC (or whatever)
5. Open services.msc  (or navigate to Control Panel/Administrative 
Tools/Services).
6. Find and select your newly created service.  Right click, select Properties.
7. Select the Log On tab.
8. Select the Log as Local System Account, option
9. Allow service to interact with the desktop should (usually) be unchecked
10. Click OK

Provided you have not altered the permissions on the c: drive, the Service 
Controller should be able to start your executable (read and execute) within 
Program Files, and the executable should be able to modify (read and write) 
files but not execute them, in ProgramData.      
_________________
Yes it's me in the avatar  
                             Top                abhimmit          Post subject: 
Re: ServiceApplication on windows.Posted: Tue Apr 23, 2013 8:19 am              
           
Joined: Mon Jan 10, 2011 1:29 pm
Posts: 19                As I said before. The application is going into error 
immediately before the run method is executed.

Below is what I have inserted in the UnhandeldException method. This is what 
gets run when run as a service. I have played with access authorities, folder 
settings and other stuff. But nothing seems to work. The only thing I'm getting 
is the "No automation server present" error from described method.

  Dim f as FolderItem
  
  if debugBuild then // running in IDE
  f=  GetFolderItem("").Parent.child("Exception.txt")
  else // compiled app
  f=GetFolderItem("Exception.txt")
  end if
  If f <> Nil then
  Try
  Dim t as TextOutputStream = TextOutputStream.Create(f)
  Try
    t.WriteLine(error.Message)
  Finally
    t.Close
    t = nil
  End Try
  Catch e as IOException
  //handle error
  End Try
  End if   
                             Top                msssltd          Post subject: 
Re: ServiceApplication on windows.Posted: Wed Apr 24, 2013 3:24 am              
                   
Joined: Fri Oct 28, 2005 7:05 am
Posts: 555
Location: Emsworth, UK                abhimmit wrote:I have played with access 
authorities, folder settings and other stuff. But nothing seems to work. The 
only thing I'm getting is the "No automation server present" error from 
described method.
What I would suggest, is that you go back to the example service I posted 
earlier and install it, as I posted earlier.  Does it work?      
_________________
Yes it's me in the avatar  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 10 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to