Encontré esta función para conectar unidades de red la utilizo después de borrar la unidad anterior con
Código Delphi
[-]WNetCancelConnection(PChar(unidad),True);
Pero igualmente me corre si la ejecuto con botón pero no corre en un servicio, la función:
Código Delphi
[-]function ConnectShare(Drive, RemotePath, UserName, Password : String):Integer;
var
NRW : TNetResource;
begin
with NRW do
begin
dwType := RESOURCETYPE_ANY;
if Drive <> '' then
lpLocalName := PChar(Drive)
else
lpLocalName := nil;
lpRemoteName := PChar(RemotePath);
lpProvider := '';
end;
Result := WNetAddConnection2(NRW, PChar(Password), PChar(UserName), 0);
end;
function DisconnectShare(Drive : String):Integer;
begin
Result := WNetCancelConnection2(PChar(Drive), 0, false);
end;
El resultado que me devuelve cuando se ejecuta es 1312:
ERROR_NO_SUCH_LOGON_SESSION
1312 (0x520)
A specified logon session does not exist. It may already have been terminated.