Hi,

I'm writing an application which is intended to run as a service. Everything works fine except if I try to read a file.

When running the app as a normal application I can read the file content. As soon I start the app as a service I got the error "input past end of file".

Code is written in VB6. The error occurs in Line "Line Input #2, sLic"
sDateiName is the placeholder for the filename.

Any idea why there is a difference if I try to read files in an application or in a service?

------

Public Function ReadLicKey(ByVal Application As String) As String
    On Error GoTo Errorhandling
    
    Dim sLic As String
    Dim sDateiName As String
    
    sDateiName = Application
    
    Open sDateiName For Input As #2
    Line Input #2, sLic
    Close #2
    
    ReadLicKey = sLic
    
    Exit Function
Errorhandling:
    Close #2
    Call LogError("Application in Module4", "Error getting the key. " + vbCr + Err.Description, Err.Number)
End Function

------

Since you are only reading a single line, store the license key in the registry. As for debugging purposes, you should also add the value of the parameter passed in to this function to you error logging call. That way you will know if for some reason your passing in bad data.

Good Luck

Thank you for the suggested workaround. Storing the data in the registry will be the last option.

I hope I can understand what is wrong with reading a simple file when the app is running as a service. The service is able to write, why not to read?!

By the way I have the same issue when I put this function in a DLL (c++). There it seems that the file could be opened but there is no data to read (as the error messages states). But also in this case everything works fine if the app is started as a normal program (not as a service).

Is there maybe a problem with the user context (user <-> system)?

I'm confused!

Maybe, it depends upon where you have put this file that you are trying to read. Once again, use the registry for your service.


Good Luck

Finally I decided to store the data in the database which the program uses also for other purposes.

Thanks,
Thomas

So then you service is able to read from disk but for some reason was failing on the specific file??? Well, that is interesting! Glad you got it figured out.

Not exactly. I do the database access over the network with DAO. Therefore I have no direct file access.

Thomas

Even more curious???


Well at least you have something working now.


Good Luck

don't forgot when u want open a file you must have windows access place the file in right access folder and set correct permission.
like set everyone to the you folder or file.

I agree with vb5Prgrmr, registry is the answer. You really need to know what you are doing to change any reg settings.

I agree with vb5Prgrmr, registry is the answer. You really need to know what you are doing to change any reg settings.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.