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"]);
}
}
User contributions licensed under CC BY-SA 3.0