Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Service Permissions? 1

Status
Not open for further replies.

wdp

Programmer
Nov 25, 2002
16
0
0
GB
Can anyone help ?
I am trying to run a Windows Service in .Net that reads and writes XMLFiles.
I have ran the code from a standard exe and it works fine, however after installing the service and starting it, it seems to not bother reading and writing the xml file. Is this a permissions thing? I am able to write a log entry.
The Account I am using is 'LocalService'.

My only other option may be to create another exe that is started by the service.
 
One of the things you will find with services is that they believe that they are running in the system32 directory (in WinNT, not sure about other OSes but would beleive they are the same)!
so never assume that they are reading/writing to a file unless you give the full path to the file.
if you are giving the full path, you need to write log records to a dump file that will track all you want tracked. such as errors. services sometimes have problems giving verbose messages to the console as they are not really for that purpose (for behind-the scenes processes).

hope this helps.

 
Thanks for the help, but I still cant get the dammned thing to work, I have even tried creating an exe that does work as a normal program, this does read and write files, so I made the service shell the application. Guess what, It don't work. Its as though the permissions have been inherited from the service????

 
Without looking at the code i am not sure I can help (and this may not help me, as i usually write services in C++ and have never tried in VB.Net).
But, another item to look at is whether your file is too large that you are trying to read! I know that I usually have to send update messages to the Service Control Manager (SCM) when doing intensive processing as services are not usually supposed to have control of the CPU for an extended period of time.
Given that you can write to the event log, i would:
* write some debug messages there to see where in the code you are going, such that you might be able to trace the problem there.
* write the result of a curdir to the eventlog.
* Install the service as an administrator.
* I am assuming that you are on a WinNT/Win2K system, as i have never heard of a service running on any other platform though i believe WinXP supports services.
* Try to write a file only, this should be a simple open,write line,close. give the file some unique name that you can search for.
* Use the try-catch-finally and output any catches to the event log as this should set some light on errors that we can not think of. it is a possibility that the problem does lie with permissions, but this catch may provide enough information to identify the problem specifically.

please let me know what you find.


 
Look at the service properties (in Windows not in VS), and try checking the Interact with Desktop box on the Log On tab.
 
Hi - after a lot of head scratching recently I managed to figure out some things about windows services which may help you

Put this in your OnStart sub

Code:
 Static blnAddedHandler As Boolean
        If Not blnAddedHandler Then
            Dim currentDomain As AppDomain = AppDomain.CurrentDomain
            AddHandler currentDomain.UnhandledException, AddressOf MyHandler
            blnAddedHandler = True
        End If

Then in the MyHandler sub you can write the details of the exception of the event log.

Windows services do not seem to stop when the encounter an error, as far as I can tell, so chances are if you don't do this, you will not ever realise an exception has occured.

Also, the local service account can only access directories on the local machine. If it is a network location you are targeting, then you will have to set the service to log on with another account. You can do this from the Service control panel.

Finally, do you know how to debug services using VS.net? You attach to the running process, provided you've compiled the service in debug mode.

Hope this is of some help Mark [openup]
 

I have tried the Unhandled Exception handler and it works great if the exception
occurs in the "OnStart" sub.

However, I have a timer that fires after 5 seconds and if I throw an exception
within the timer elapsed event, the exception is not caught in the MyHandler
event.

Is there something peculiar about timer events and exception handling??

Any help would be appreciated!

Steve

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top