function RefreshMappedDrive(cDrvLetter: Char): Boolean;
const
WbemUser ='
';
WbemPassword ='
';
WbemComputer ='
localhost';
wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
WshNetwork : OLEVariant;
begin;
Result := False;
FSWbemLocator := CreateOleObject('
WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, '
root\CIMV2', WbemUser, WbemPassword);
FWbemObjectSet:= FWMIService.ExecQuery('
SELECT LocalName,ConnectionState,RemotePath FROM Win32_NetworkConnection','
WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum)
as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0
do
begin
if String(FWbemObject.LocalName) = (cDrvLetter+'
:')
then //if this drive
begin
if String(FWbemObject.ConnectionState) <> '
Connected'
then //if disconnected
begin
//try to reconnect ....
try
WshNetwork := CreateOleObject('
WScript.Network');
WshNetwork.MapNetworkDrive(cDrvLetter+'
:',
String(FWbemObject.RemotePath));
except
end;
Result := True;
end
else
begin
Result := True;
end;
Break;
end;
FWbemObject:= Unassigned;
end;
end;