471,594 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

.NET Windows Service accessing network drive problem

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: mb*@email.it

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>vYfZDKECAU2njkPvbIpjlA==</Id>
Nov 16 '05 #1
1 3164
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

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Bonj | last post: by
4 posts views Thread by marc.gibian | last post: by
1 post views Thread by mbah Sumani via .NET 247 | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.