Question Use Windows Service to access files over a network

TBossAZ

Active member
Joined
Mar 31, 2009
Messages
43
Programming Experience
5-10
Greetings everyone,

Let me preface this by saying I have read other posts on this board that describe the problem I am having but I am not understanding the solutions, and I need some help.

I need to create a Windows Service that involves being able to access and move files saved on the network. I do know that I cannot use a network drive to access the network. I am able to provide the network path (\\servername\directory\subdirector\) and I have been told that anyone on the network can access this particular directory.

The Windows Service is setup as LocalSystem.

I use the following code to determine if I can access the specified network path:

VB.NET:
        If Not Directory.Exists(networkpath) Then
            'directory not found
        End If

When I try to change my Windows Service to be a NetworkService, I get an error that says I cannot run it as a NetworkService.

Can anyone please help me figure out how I can access files over the network with my Windows Service?

Let me know if you have any questions, and code examples would REALLY be nice. Thanks!
 
I figured out what it was I needed to do.

After I installed the service, I right-click My Computer and select Manage, then select Services and Applications -> Services to see all of the services in Windows XP, including the one I wrote myself. I then right-click on my service and select Properties.

There is a Log On tab, which has an option called This Account. I entered my username (actually for me it is domainname/username) and password. I was finally able to access the network.

FYI for anyone reading this, domainname is the name of the network you log into.

I still welcome anyone's ideas and thoughts about this solution, and I am still curious to know about running a service as a NetworkService.

I am developing my Windows Service on my PC but I understand it will be installed on a server, so if anyone has any roadblocks to warn me about, please let me know.

I also hope this will be of help to someone else.
 
NetworkService cannot access files on drives that are not local, as a security restriction. I don't think it's even a .NET security policy, as the net is filled with posts about how people cannot get their Serv-U FTP server software to serve up files on networked drives..

I've always run my services as a specific account, so it authenticates with the mail server, and oracle can determine the os username (for audit purposes) etc etc

Refer to the beardspeak:Windows service accessing the network - bytes
 
Back
Top