|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Cannot Map a Network Drive in C#I am tring to map the network drive (C$) in c# from ASP.NET page and it seems it is not working...What I really want is to delete the file from the netwrok computer. This file is present in the default share C$. I search the google and what I got is that this is not possible to do in c# from web as it requires a user with appropriate rights, Based on this I have created a new user and added him into the Administrators group and use the Impersonate in the web.config but after this also it is not wroking at all. Same thig is working from C# consol application or windows application. I have used Process object of System.IO namespace to use the net use function and I have also tried WMI Management Class and both are not working Can anyone suggest where I am going wrong.... Help is much appriciated...this has taken by 4 days and still i have not finished yet. regards, -pb- Um..show the error, and show the code?
And why use "net use.."?? Just delete the file using a full UNC path? Similar to File.Delete @\\someserver\someshare\somefile.doc; Show quote "-pb-" <prateekb***@gmail.com> wrote in message news:1162979668.064946.101000@i42g2000cwa.googlegroups.com... > Hi, > > I am tring to map the network drive (C$) in c# from ASP.NET page and it > seems it is not working...What I really want is to delete the file from > the netwrok computer. This file is present in the default share C$. > > I search the google and what I got is that this is not possible to do > in c# from web as it requires a user with appropriate rights, Based on > this I have created a new user and added him into the Administrators > group and use the Impersonate in the web.config but after this also it > is not wroking at all. Same thig is working from C# consol application > or windows application. > > I have used Process object of System.IO namespace to use the net use > function and I have also tried WMI Management Class and both are not > working > > Can anyone suggest where I am going wrong.... > > Help is much appriciated...this has taken by 4 days and still i have > not finished yet. > > regards, > > -pb- > Hi,
File object of .NET doesn't work on share drive. It gives me an error saying "Login failed". Here is the piece of code which uses Process object of System.Diagnostic using (Process mapDrive = new Process()) { mapDrive.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; mapDrive.StartInfo.RedirectStandardOutput = true; mapDrive.StartInfo.UseShellExecute = false; mapDrive.StartInfo.FileName = "net.exe"; mapDrive.StartInfo.Arguments = " use x: " + networkPath + " " + password + " /user:" + userName; mapDrive.Start(); mapDrive.WaitForExit(); string output = mapDrive.StandardOutput.ReadToEnd().ToLower(CultureInfo.InvariantCulture); string output1 = output; } Jeff Dillon wrote: Show quote > Um..show the error, and show the code? > > And why use "net use.."?? Just delete the file using a full UNC path? > Similar to > > File.Delete @\\someserver\someshare\somefile.doc; > > "-pb-" <prateekb***@gmail.com> wrote in message > news:1162979668.064946.101000@i42g2000cwa.googlegroups.com... > > Hi, > > > > I am tring to map the network drive (C$) in c# from ASP.NET page and it > > seems it is not working...What I really want is to delete the file from > > the netwrok computer. This file is present in the default share C$. > > > > I search the google and what I got is that this is not possible to do > > in c# from web as it requires a user with appropriate rights, Based on > > this I have created a new user and added him into the Administrators > > group and use the Impersonate in the web.config but after this also it > > is not wroking at all. Same thig is working from C# consol application > > or windows application. > > > > I have used Process object of System.IO namespace to use the net use > > function and I have also tried WMI Management Class and both are not > > working > > > > Can anyone suggest where I am going wrong.... > > > > Help is much appriciated...this has taken by 4 days and still i have > > not finished yet. > > > > regards, > > > > -pb- > > Someone with more of an idea about Windows might be able to help but I think
this doesnt work because aspnet is not logged on with a desktop and things and therefore drive letter persistence will not work. Try making a batch file that will map the drive, delete the file, and drop the drive in one go e.g net use x: %1 del x:\deadfile.txt net use x: /d Ciaran O'Donnell Show quote "-pb-" wrote: > Hi, > > File object of .NET doesn't work on share drive. It gives me an error > saying "Login failed". > > Here is the piece of code which uses Process object of > System.Diagnostic > > using (Process mapDrive = new Process()) > { > mapDrive.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; > mapDrive.StartInfo.RedirectStandardOutput = true; > mapDrive.StartInfo.UseShellExecute = false; > mapDrive.StartInfo.FileName = "net.exe"; > mapDrive.StartInfo.Arguments = " use x: " + networkPath + " " + > password + " /user:" + userName; > mapDrive.Start(); > mapDrive.WaitForExit(); > > string output = > mapDrive.StandardOutput.ReadToEnd().ToLower(CultureInfo.InvariantCulture); > string output1 = output; > } > > Jeff Dillon wrote: > > Um..show the error, and show the code? > > > > And why use "net use.."?? Just delete the file using a full UNC path? > > Similar to > > > > File.Delete @\\someserver\someshare\somefile.doc; > > > > "-pb-" <prateekb***@gmail.com> wrote in message > > news:1162979668.064946.101000@i42g2000cwa.googlegroups.com... > > > Hi, > > > > > > I am tring to map the network drive (C$) in c# from ASP.NET page and it > > > seems it is not working...What I really want is to delete the file from > > > the netwrok computer. This file is present in the default share C$. > > > > > > I search the google and what I got is that this is not possible to do > > > in c# from web as it requires a user with appropriate rights, Based on > > > this I have created a new user and added him into the Administrators > > > group and use the Impersonate in the web.config but after this also it > > > is not wroking at all. Same thig is working from C# consol application > > > or windows application. > > > > > > I have used Process object of System.IO namespace to use the net use > > > function and I have also tried WMI Management Class and both are not > > > working > > > > > > Can anyone suggest where I am going wrong.... > > > > > > Help is much appriciated...this has taken by 4 days and still i have > > > not finished yet. > > > > > > regards, > > > > > > -pb- > > > > > I had already tried this solution and still it doesn't work so finally
I came with a workaround. I have developed a VBCOM component which do all ncessary task and referenced that component in .net component ot use RCW and it works. I belive in all cases, the security settgin og launching application user is inherited by managed code but this doesn't apply to unmanaged code and hence it works now... thanks for your reply... Ciaran O''Donnell wrote: Show quote > Someone with more of an idea about Windows might be able to help but I think > this doesnt work because aspnet is not logged on with a desktop and things > and therefore drive letter persistence will not work. Try making a batch file > that will map the drive, delete the file, and drop the drive in one go > e.g > > net use x: %1 > del x:\deadfile.txt > net use x: /d > > > Ciaran O'Donnell > > "-pb-" wrote: > > > Hi, > > > > File object of .NET doesn't work on share drive. It gives me an error > > saying "Login failed". > > > > Here is the piece of code which uses Process object of > > System.Diagnostic > > > > using (Process mapDrive = new Process()) > > { > > mapDrive.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; > > mapDrive.StartInfo.RedirectStandardOutput = true; > > mapDrive.StartInfo.UseShellExecute = false; > > mapDrive.StartInfo.FileName = "net.exe"; > > mapDrive.StartInfo.Arguments = " use x: " + networkPath + " " + > > password + " /user:" + userName; > > mapDrive.Start(); > > mapDrive.WaitForExit(); > > > > string output = > > mapDrive.StandardOutput.ReadToEnd().ToLower(CultureInfo.InvariantCulture); > > string output1 = output; > > } > > > > Jeff Dillon wrote: > > > Um..show the error, and show the code? > > > > > > And why use "net use.."?? Just delete the file using a full UNC path? > > > Similar to > > > > > > File.Delete @\\someserver\someshare\somefile.doc; > > > > > > "-pb-" <prateekb***@gmail.com> wrote in message > > > news:1162979668.064946.101000@i42g2000cwa.googlegroups.com... > > > > Hi, > > > > > > > > I am tring to map the network drive (C$) in c# from ASP.NET page and it > > > > seems it is not working...What I really want is to delete the file from > > > > the netwrok computer. This file is present in the default share C$. > > > > > > > > I search the google and what I got is that this is not possible to do > > > > in c# from web as it requires a user with appropriate rights, Based on > > > > this I have created a new user and added him into the Administrators > > > > group and use the Impersonate in the web.config but after this also it > > > > is not wroking at all. Same thig is working from C# consol application > > > > or windows application. > > > > > > > > I have used Process object of System.IO namespace to use the net use > > > > function and I have also tried WMI Management Class and both are not > > > > working > > > > > > > > Can anyone suggest where I am going wrong.... > > > > > > > > Help is much appriciated...this has taken by 4 days and still i have > > > > not finished yet. > > > > > > > > regards, > > > > > > > > -pb- > > > > > > > > Well another thing...I want to acess the default share of the network
computer i.e. c$ and not any already shared resource Jeff Dillon wrote: Show quote > Um..show the error, and show the code? > > And why use "net use.."?? Just delete the file using a full UNC path? > Similar to > > File.Delete @\\someserver\someshare\somefile.doc; > > "-pb-" <prateekb***@gmail.com> wrote in message > news:1162979668.064946.101000@i42g2000cwa.googlegroups.com... > > Hi, > > > > I am tring to map the network drive (C$) in c# from ASP.NET page and it > > seems it is not working...What I really want is to delete the file from > > the netwrok computer. This file is present in the default share C$. > > > > I search the google and what I got is that this is not possible to do > > in c# from web as it requires a user with appropriate rights, Based on > > this I have created a new user and added him into the Administrators > > group and use the Impersonate in the web.config but after this also it > > is not wroking at all. Same thig is working from C# consol application > > or windows application. > > > > I have used Process object of System.IO namespace to use the net use > > function and I have also tried WMI Management Class and both are not > > working > > > > Can anyone suggest where I am going wrong.... > > > > Help is much appriciated...this has taken by 4 days and still i have > > not finished yet. > > > > regards, > > > > -pb- > > |
|||||||||||||||||||||||