|
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
|
|
|
|
|
I have had some feedback about Windows 2003 and all reports apart from yours appears well... It could be your policy / security settings on the 2003 machine. Also check that V: is not already mapped and you are passing all the values correctly...
----------------------------
aejw.com
|
|
|
|
|
My application is windows service. On start of the service it tries to map the network location using your code. Due to security difference in Win2k3 servers I had to do this coz the mapped location using windows explorer will not be accessable in my service session.
So wat happens if I try to map the drive V, which is already mapped using windows explorer, using your code ? Coz I have to map the location in my service session, the other one is not accessable.
Thanks,
-Samir
-- modified at 14:16 Wednesday 17th May, 2006
|
|
|
|
|
I have the same issue except that I am calling it from a Scheduled Task and it can't get the drive to be mapped.
Any clue?
My code is parctically the same as his code.
Thanks,
Nic.
|
|
|
|
|
I would pass the username and password via the credentials options.
----------------------------
aejw.com
|
|
|
|
|
working sample (windows service on win2003):
try{
NetworkDrive drive = new NetworkDrive();
drive.Force = true;
// drive.LocalDrive = ... <- not needed
drive.Persistent = true;
drive.SaveCredentials = true;
drive.ShareName = SourceDir;
drive.MapDrive("User", "Pass");
....
asa
|
|
|
|
|
Hi..
FOL thanks for posting this code...its really useful...
I am facing problem. I have included this class in my windows service project.On startup I am mapping a shared location on the machine. It works differently on server operation system. I am not able to map drive in my service in Windows 2000 server.
How different it is on Windows 2000 server ??
regards,
Samir
|
|
|
|
|
I have not had much feedback about Windows 2000, it should have no issues... Maybe Windows is not allowing you to map a drive with the service because its using the SYSTEM account when executed as a service...
----------------------------
aejw.com
|
|
|
|
|
I am having the same issue too. The project can establish the mapping on Windows Server 2003, but not on 2000. Both servers are using Active Directory ( don't know if that has an effect ). Does anyone have any idea?
Best Regards,
ron
|
|
|
|
|
is there a way to use oNetDrive.ShareName to get a list of the drives and their paths?
|
|
|
|
|
I use WMI to get a list of shares from a given
machine. Although you can always use a wrapper
for Shell.Application if you don't have local admin.
You can also use WMI to get a list of drives.
"Select size,freespace from Win32_LogicalDisk where name = '" + DriveL + "'
When you do the share query you need to make sure you don't pull in Administrative shares.. Here is the WMI query for that..
"Select name,path from Win32_Share where type != '2147483648' and type != '2147483651'"
Please, keep in mind that if you use the Shell.Application method, that you do not have the ability to see any hidden or administrative shares. With WMI you can see them, if you need to.
|
|
|
|
|
Is it oke to use this code.
As I read in the license and i need your permissions i see.
But i cann't mail you?.
All i want to do is map 4 drives on a custommer who doesn't allow net use or vbscript.
jipijie i'm on VB
jipijee i'm on C
|
|
|
|
|
Hello and sorry about the very slow reply, yes it can be used... An updated version is on my site www.aejw.com - which has an updated and very lax EULA. I will update code project before long...
----------------------------
aejw.com
|
|
|
|
|
help.
i use Asp.net to implement map network drive, but can't complete.
Arne
-- modified at 23:41 Tuesday 13th December, 2005
|
|
|
|
|
Hi,
what difference you expect here by using p/ Invoke when..
Map Drives are any way session bound
Map drives are unstable/ disconnect as session ends
Map dirves connection depends on various other factors like net work connectivity etc.
So if any of these problems cannot be solved with p/Invoke, why don't you just use the dos command to map the network drive via your application and aslo to delete it.
Simply writting a simple class to simulate DOS prompt will do this, doesn't it?
L.W.C. Nirosh,
Tech Lead,
TextCENTRIC Technology,
Colombo,
Sri Lanka
|
|
|
|
|
wa??? I have no idea what your on about, but never mind... Try getting feedback / error messages from a command prompt, lol...
----------------------------
aejw.com
|
|
|
|
|
Sorry for the late reply..
But mate do you wanna code to do it??
Just say yes.. I will pass it.
L.W.C. Nirosh,
Colombo,
Sri Lanka.
|
|
|
|
|
if the requirement is just to be able to connect to an untrusted domain, say to work with files then disconnect, this code might suffice: (no need for a drive letter, if you know the share name)
public bool InvokeComMember(string progID, string member, System.Reflection.BindingFlags invokeAttr, params object[] param)
{
try
{
Type type = Type.GetTypeFromProgID(progID);
object o = Activator.CreateInstance(type);
type.InvokeMember(member, invokeAttr, null, o, param);
}
catch{}
finally
{
type = null;
o = null;
}
}
InvokeComMember("WScript.Network", "MapNetworkDrive", System.Reflection.BindingFlags.InvokeMethod, "", remoteName, false, user, password);
InvokeComMember("WScript.Network", "RemoveNetworkDrive", System.Reflection.BindingFlags.InvokeMethod, remoteName);
|
|
|
|
|
Beautiful. Exactly what I needed. Thank you so much!
|
|
|
|
|
Thanks for a great this great article. One thing that I desperatly needed was the inclusion of a function to automatically find an open drive letter for a faceless application. Very simple, so expand at your own leasure.
//Under the Function mapping region, add the following...
Public bool GetNextOpenDriveLetter(ref string Driveletter) {return zGetNextOpenDriveLetter(ref Driveletter);}
//Under the Core functions region, add the following...
private bool CheckDriveLetter(string DriveLetter) {
bool retVal = false;
DriveLetter += @":\";
string[] drives = System.IO.Directory.GetLogicalDrives();
foreach (string str in drives) {
if (str.ToString() == DriveLetter.ToString()) {
retVal = true;
break;
}
}
return retVal;
}
private bool zGetNextOpenDriveLetter(ref string Driveletter) {
string[] openletters = {"L", "M", "N"}; //ect.
bool retVal = false;
//See if letter given is open
if (CheckDriveLetter(Driveletter)) {
foreach (string str in openletters) {
if (!CheckDriveLetter(str.ToString())) {
Driveletter = str;
retVal = true;
break;
}
}
}
return retVal;
}
//Example...
NetworkDrive drive = new NetworkDrive();
string driveletter = "L";
if (drive.GetNextOpenDriveLetter(ref driveletter)) {
drive.ShareName = @"\\server\share";
drive.LocalDrive = driveletter;
drive.Force = true;
drive.MapDrive();
}
Enjoy!
It needs more cowbell!
|
|
|
|
|
Good plan, ill sort out an update for build 0016, what name would like for credit?
----------------------------
Adam Woods
|
|
|
|
|
Wow, never thought anyone would even care...
Thanks Adam, you may credit me as Hannes "the zipper" Burger.
|
|
|
|