|
Hey,
Great code, truly was a big help for me.
Just a quick question, I'm using this code in my windows service and when my service returned an error saying the file I was trying to read was already in use by another process, I stopped my service and tried again an hour later.
When I restarted the service I got the following error:
"The local device name is already in use."
So I tried to Unmap the drive but it return this error:
"This network connection does not exist"
I was wondering if there is a work around for is...
Also the drive letter only does not work with your code, I have been able to suucessfully map to that drive letter through NetUse, and window's map network drive without issues.
|
|
|
|
|
Ok the lastest version of my class is on my site, aejw.com... This version is a little out of date, I am updating it in the next week or so. Thanks for reporting any bugs, I will do my best to sort them all out.
As for your service, it sounds like another application is maybe accessing / using a driveless "use" connection??? im not so sure. Try unmapping the share, using null as the drive value.
Please keep me posted, I really should also look into writing a demo service application (there are some ways of re-routing a service to load under a local user account).
(aejw)
|
|
|
|
|
Hi,
I am actually using your newest verison of this code, from your website.
Also, I tried unmapping using null as the drive value, but I still got the same error.
I then followed through the drive letters effected and found no other programs accessing set drive letters, or a program using a driveless connection. So, I tried using the force command on the mapping function in hopes it would go through but had no such luck.
Thanks for the response, I guess I'll just use a different drive letter, I mean its not that big of a problem for me cause the drive letters are still able to map using windows mapping.
oh one more question, is there a way of using this code to connect to the next open drive letter (say drives A:,B:,C:, and D: are in use, it than uses E:, much like the * in a Net use cmdline), if yes is there a way remembering that drive letter so it could be placed in a server log message
Andrew
|
|
|
|
|
Thank you, Thank you, Thank you!!!
I've been searching for a way to get my service to read from a mapped drive
for a few days now!! This is exactly what I needed!!
|
|
|
|
|
Unmapping a network drive that is not bind to a local drive will fail whereas the class allows the mapping of a network drive without assigning it to a local drive.
To make it work, update the zUnMapDrive() :
<br />
int i;<br />
if (ls_Drive != "")<br />
i = WNetCancelConnection2A(ls_Drive, iFlags, Convert.ToInt32(pfForce));<br />
else<br />
i = WNetCancelConnection2A(ls_ShareName, iFlags, Convert.ToInt32(pfForce));<br />
A new version of this class that already has the fix and more features can be found here[^]
- Daniel B.
-- modified at 12:01 Monday 18th June, 2007
|
|
|
|
|
I'm sorry I really should update this article... I will get it done soon.
|
|
|
|
|
I have to Thank you a lot.
|
|
|
|
|
|
If you want to write an application in VB.NET you get errors that the namespace cannot be found. Adding a reference to networkdrive.dll does not work. I compiled the class to a new DLL which can be referenced to in VB.NET projects. Enjoy it!
http://rapidshare.com/files/7669042/NetWorkDrive.dll.html (will be deleted by rapidshare if not downloaded for 45 days)
|
|
|
|
|
The DllImport of WNetRestoreConnectionW needs to specify CharSet = CharSet.Unicode to be used to reconnect single drives. Useful because DriveInfo, FileInfo and DirectoryInfo does not reconnect drives when accessing them like explorer does.
[DllImport("mpr.dll", CharSet = CharSet.Unicode)]
public static extern int WNetRestoreConnectionW(IntPtr phWnd, string psLocalDrive);
Works for reconnecting net drives like so:
int i = WNetRestoreConnectionW(IntPtr.Zero, "z:");
Hope it helps someone
|
|
|
|
|
ta mate... will sent code project an update soon with that in it...
|
|
|
|
|
Anyone got sComment to work? I need to change the name of the mounted disk instad of "myFiles on file32". Anyone know a way to do this, without finding the entry in registry and change it here?
|
|
|
|
|
Hi,
I have implemented this in a .NET 2.0 console application which works fine on my XP development PC, but the production PC is Windows 2003, which is causing me a lot of problems with security.
I have tried with the mapped PC as name, and IP and with and without user (with and without PC name)and password.
Can you help me?
|
|
|
|
|
Windows 2003 is tricky because of its server security. Have you tried putting complete domain details in the username, eg. "DOMAIN\Username"? (This commonly turns out to be peoples problems with 2003). Other wise it could be a policy restriction.
|
|
|
|
|
No i dont think about it.
it is not any problem
|
|
|
|
|
Hi,
Just wanna contribute some input, as I'm searching for answer high and low few hours ago, Am using VB version of code (which running on win 2k3) for mapping the drive and get some files from another win 2k3 server, as far as I realize, this error occur while the workstation service is stopped.
To those who are really clueless, you can restart the service at Control Panel > Administrative Tools > Services > select the services from the list and press start on the left hand portion.
For more details you can refer to the link below:
http://www.chicagotech.net/Networking/ntbemapped1.htm
Hope this helps up.
Rgds,
G
|
|
|
|
|
Hi,
I tried to used your code in my web applcation with the following codes to map network drives but I got an error message.
try<br />
{<br />
oNetDrive.LocalDrive = "T";<br />
oNetDrive.ShareName = ConfigurationSettings.AppSettings["FileLocation"];<br />
oNetDrive.MapDrive("admin","123"); <br />
Response.Write("Mapped");<br />
}<br />
catch (Exception errs)<br />
{<br />
Response.Write(errs.Message);<br />
}
Error Message :A specified logon session does not exist. It may already have been terminated
Thanks
Dabuskol
|
|
|
|
|
This is rather complex... you are getting the error message because the application is isolated as such, meaning because of the security on the .net web server your web application does not have the security rights to allow you to map a network drive. I would suggest you modify the assembly / user access rights on your web server under the “Control Panel\Administrative Tools\Microsoft .NET Framework x.x Configuration” to allow the assembly full access. If you continue to have issues, notify me and ill try and hunt down another solution.
------------------------------------------------------------------------------------
aejw (http://www.aejw.com/)
|
|
|
|
|
I still get the same problem. This is the scenario.
My web applcation is in web server1 with .net installation and everything. Then My program will connect to server 2 with (W2K3 OS, no .net installation, just a plain server with files) then download/insert files on it. In order for the program to get the files it needs to connect to server 2 though I used a username that has administrator priveledge still I am getting the same message.
On the other side, If I run your windows applcation using the same parameters as above I was able to connect to server2 from server1. It means the user access has the right to access server 2. Where is the problem, is it in my web app? I did follow your instrustions in README and everything but with no Luck.
Sorry to disturb you but everything on my application is working except this part.
Dabuskol
|
|
|
|
|
No its does not sounds like the application / code, this will be rather hard to work out... it sounds like its a privileges problem. For example, if one machine is in a domain and the other is not (or different domain), you will need to include the domain on the front of username, for example. "DOMAIN\username". Also make sure the username does have access to the share... etc etc.
----------------------------
aejw.com
|
|
|
|
|
I created a similar program in windows .net and it works fine. But like you said all I need is to add the DOMAIN before the username of my server2 which luckly worked. I did tried it before but for no reason it didn't work.
Thanks for your help and Ideas my web application is working fine.
Server1/admin
Great
Dabuskol
Dabsukol
|
|
|
|
|
Thank-you for putting this wrapper out here.
Very grateful. Saved me a bit of time.
-smiles- Just another perl hacker shifting gears.
|
|
|
|
|
Is there any way to actually delete the drive? The unmapped function just disconnects it. Is there a way to make it actually delete the drive so it doesn't show up in My Computer?
Thanks in advance
|
|
|
|
|
As long as it a maped network drive and you ensure Persistant is set to false
----------------------------
aejw.com
-- modified at 1:00 Monday 1st May, 2006
|
|
|
|
|
The shared location, Ex : \\hostname\folder1, is not getting mapped using windows service in Windows Server 2003.
I am using following code:
NetworkDrive networkDrive = new NetworkDrive ();
networkDrive.Force = true;
networkDrive.Persistent = false;
networkDrive.LocalDrive = "V:";
networkDrive.PromptForCredentials = false;
networkDrive.ShareName = strSharedLocation;
networkDrive.SaveCredentials = false;
networkDrive.MapDrive();
Please help me...
Thanks,
Samir
|
|
|
|