我使用c#创建一个Windows服务,在网络驱动器上找到新的zip文件并将它们解压缩到本地目录。我使用此Map Network Drive API进行映射。我首先调用map函数,如果失败,我取消映射驱动器并尝试重新映射驱动器。 错误:
private bool unmapDrive()
{
try
{
NetworkDrive oNetDrive = new aejw.Network.NetworkDrive();
oNetDrive.LocalDrive = driveLetter;
oNetDrive.Force = true;
oNetDrive.ShareName = @"\\IPADDRESS\LogFiles";
oNetDrive.UnMapDrive();
return true;
}
catch(Exception e)
{
Log(e.Message);
return false;
}
}
private bool mapDrive()
{
try
{
NetworkDrive oNetDrive = new aejw.Network.NetworkDrive();
oNetDrive.LocalDrive = driveLetter;
//oNetDrive.SaveCredentials = true;
oNetDrive.ShareName = @"\\IPADDRESS\LogFiles";
oNetDrive.PromptForCredentials = true;
oNetDrive.MapDrive();
return true;
}
catch(Exception e)
{
Log(e.Message);
return false;
}
}
他们被称为
if (!mapDrive())
{
unmapDrive();
if (!mapDrive())
{
//if drive cannot be mapped, program will not work
Log("Discoverer has failed to map drive, shutting down");
this.Stop();
}
}