Validate network path in windows service

R

Rajeev

Hi

I have developed a windows service using C#. I am checking a folder
path using "DirectoryInfo" class which is in local network. It always
returns false, even folder exists on local network.

folderPath = "\\MyServer\IO\XYZ_Folder";
DirectoryInfo di = new DirectoryInfo(folderPath);
return di.Exists; //This returns false

Above code works properly, when I use inside windows application. Can
any body tell me the problem of Windows Service?

Thanks in advance.

Regards
Rajeev
 
W

Willy Denoyette [MVP]

Rajeev said:
Hi

I have developed a windows service using C#. I am checking a folder
path using "DirectoryInfo" class which is in local network. It always
returns false, even folder exists on local network.

folderPath = "\\MyServer\IO\XYZ_Folder";
DirectoryInfo di = new DirectoryInfo(folderPath);
return di.Exists; //This returns false

Above code works properly, when I use inside windows application. Can
any body tell me the problem of Windows Service?

Thanks in advance.

Regards
Rajeev

That means that the service identity has no access to the remote share.
There are several ways to tackle this issue, or you can create a logon
session (search MSDN for LogonUser and Impersonate for a sample) and
impersonate a user account that has the appropriate access rights, or you
can run the service as a user that has appropriate access rights to the
remote resource.

Willy.
 
R

Rajeev

Dear Brian

I don't think it is rights issue, because both machines are accessible
without any userid/password. Even I create Map network drive then also
Windows Service is not able to access. Windows Service is running under
Administrator account.

Thanks & Regards
Rajeev
 
W

Willy Denoyette [MVP]

Rajeev said:
Dear Brian

I don't think it is rights issue, because both machines are accessible
without any userid/password. Even I create Map network drive then also
Windows Service is not able to access. Windows Service is running under
Administrator account.

Thanks & Regards
Rajeev

The windows service runs under "administrator" doesn't mean anything, it
runs in it's own logon session which is separate from the interactive
"administrator" logon session. Network connections are tied to their logon
sessions, not to the logon account.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top