.NET Windows Service accessing network drive problem

  • Thread starter Max Baki via .NET 247
  • Start date
M

Max Baki via .NET 247

I all,

i've write a sample ftp Windows service which download files and copy them on remote share or remote mapped drive (the service works fine on local drives).

This part of code is the function to change the local path for downloaded files.

If the configured path is different from local drive C: the new path is selected.

The program works fine in debug or release mode into Visual Studio. All downloaded files were placed on remote share or remote mapped drive.

On Installed Service the SetCurrentDirectory(...) eg.. 'H:\' which is on remote server fall in an Exception. Same if the directory is a remote unc path like '\\server\root'.

I tried to install the service like System Account, Network Account or User Account granted to shares, but the SetCurrentDirectory fall always in an Exception.

Anybody has an idea how can i resolve this issue?
Thanks.
Max


CODE -----------------------------------------------------------------------------------------------
public void chlocaldir(string dirName)
{
string drive = dirName.Remove(1,dirName.Length-1);
string path = dirName.Remove(0,2);

try
{
if ( drive != "C")
{
// Change Drive
Directory.SetCurrentDirectory(drive + ":\\");
// Change Path
Directory.SetCurrentDirectory(drive + ":" + path);
}
else
Directory.SetCurrentDirectory(drive + ":" + path);
}
catch(Exception e)
{
Directory.SetCurrentDirectory("C:\\");

throw new IOException("Can't connect to Remote Drive: " + e.Message);
}

this.localPath = drive + ":" + path;

}

CODE ------------------------------------------------------------------------------------------------
From: Max Baki
email: (e-mail address removed)
 
M

Mohamoss

Hi max
may be it is a security issue , do you know under with account does you
service run ? may be it is an account that lakes the right privileges
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

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