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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DirectoryInfo in a Service 1

Status
Not open for further replies.

bakershawnm

Programmer
Joined
Apr 18, 2007
Messages
84
Location
US
I have a program that I am trying to convert to a service (using VS 2008). The program uses DirectoryInfo to search for files in a specified folder. I use absolute path names as I can never be confident that I will have a drive mapped. The path names do have spaces in them and the ultimate subpath is date specific (i.e 7-26-10). In that date folder will be numerous files and I need to weed through them to find the ones I need and import their data into a SQL server.

So my path looks like this \\Theta2\Public1\Polaris\CAWG\Widgets Received Data\Received Drops\7-26-10

Everything works just great if the program is run interactively and the user selects the path to import from.

I have done all the threading and built the service and everything in the service seems to be working fine except where the initial search of the folder is concerned. It seems that (when running in a service) the folder does not exist.

This is my proof code that tells me it does not recognize the folder. It is the exact same code in the interactive program as in the service.

Dim configfl As String = "C:\ServicesTesting\BCADataService.ini"
Dim srcfldr As String

If File.Exists(configfl) Then
Dim strmrdr As New StreamReader(configfl)
srcfldr = strmrdr.ReadLine
srcfldr = Mid(srcfldr, InStr(srcfldr, "=") + 2)
strmrdr.Close()

Dim rootfldr As DirectoryInfo = New DirectoryInfo(srcfldr)
If rootfldr.Exists Then
evntlog.WriteEntry(srcfldr & " exists.")
End If
End If

and then in a subfunction this:

Dim fldrinfo As DirectoryInfo = New DirectoryInfo(srcfldr)
evntlog.WriteEntry(fldrinfo.FullName)
If (fldrinfo.Exists = True) Then
evntlog.WriteEntry("folder exists")
.
.
.
Else
evntlog.WriteEntry("Source folder " & fldrinfo.FullName & " does not exist")
End If

I do not get the first entry in the event log at the rootfldr. I do get the last event log entry that says it does not exist.

So my question is this:
Do the spaces and/or dashes in the path name provide different results when running as a service?

If so, recommendations other than renaming the path (I will do that if there are no other options) would be welcome.

If not then is it possible that I am doing something wrong somewhere in the initial installation and registration of my service?



 
Are you running this service under credentials which differ from your interactive application? Perhaps it's a security issue.
 
running under ServiceAccount.LocalService Might very well be a security issue. I am currently running this service on my local machine and trying to pickup data from a server. The plan is to run this on our SQL server and get the data from the current server that it is on. So I may need to create an account that can do that.

Thanks
 
have a start riverguy. i am getting much further in the execution now.

Thanks
 
the fix (so far) seems to be to running it as a networkservice not a localservice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top