Not able to map a network drive using WshNetwork_Class.mapnetworkdrive in c#

0

I have created a windows service to map a network drive.In Onstart method am trying to map the drive using below code

IWshNetwork_Class network = new IWshNetwork_Class();
network.MapNetworkDrive(drive, @remoteName, Type.Missing, UserName, Password]);

It always throws an exception as

The local device name is already in use. (Exception from HRESULT: 0x80070055)."

But when i check with explorer the drive is not connected.When I map using mycomputer->map networkdrive am able to map it. Please help me to sort this out.

protected override void OnStart(string[] args)
{ 
  string drive = "Z:";
  string remote = @remoteName;
  if (!Directory.Exists(drive))
  {
     IWshNetwork_Class network = new IWshNetwork_Class();
     network.MapNetworkDrive(drive, @remoteName, Type.Missing, ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]);
  }
}
c#
asked on Stack Overflow Jun 15, 2015 by kns • edited Jun 15, 2015 by Shubham Bhave

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0