Форум: "Основная";
Текущий архив: 2003.09.04;
Скачать: [xml.tar.bz2];
Вниз
Переобразование сетевого имени файла Найти похожие ветки
← →
vv_fran (2003-08-23 17:26) [0]Как сетевое имя файла в формате UNC: \\serverName\sharedName\fileName преобразовать в вид:
serverName:C:\DirName\fileName ?
← →
Opuhshii (2003-08-23 19:59) [1]NetShareEnum / NetShareGetInfo
level=2 для NT/XP
и
level=50 для W9x
← →
Verg (2003-08-23 20:18) [2]unit netshare;
interface
function GetShareLocalPath(const Path : string):string;
implementation
uses Windows, Common, SysUtils;
const
STYPE_DISKTREE = 0;
STYPE_PRINTQ = 1;
STYPE_DEVICE = 2;
STYPE_IPC = 3;
NERR_BASE = 2100;
NERR_BufTooSmall = NERR_BASE + 23;
CNLEN = 15; // Computer name length
LM20_CNLEN =15; // LM 2.0 Computer name length
DNLEN = CNLEN; // Maximum domain name length
LM20_DNLEN = LM20_CNLEN; // LM 2.0 Maximum domain name length
UNCLEN = (CNLEN+2); // UNC computer name length
LM20_UNCLEN = (LM20_CNLEN+2); // LM 2.0 UNC computer name length
NNLEN = 80; // Net name length (share name)
LM20_NNLEN = 12; // LM 2.0 Net name length
RMLEN = (UNCLEN+1+NNLEN); // Max remote name length
LM20_RMLEN =(LM20_UNCLEN+1+LM20_NNLEN); // LM 2.0 Max remote name length
SHPWLEN = 8; // Share password length (bytes)
type
PSHARE_INFO_2 = ^SHARE_INFO_2;
SHARE_INFO_2 = record
shi2_netname : PWideChar;
shi2_type : DWORD;
shi2_remark : PWideChar;
shi2_permissions : DWORD;
shi2_max_uses : DWORD;
shi2_current_uses : DWORD;
shi2_path : PWideChar;
shi2_passwd : PWideChar;
end;
Pshare_info_50 = ^Tshare_info_50;
Tshare_info_50 = packed record
shi50_netname : array[0..LM20_NNLEN] of char;
shi50_type : byte;
shi50_flags : word;
shi50_remark : pchar;
shi50_path : pchar;
shi50_rw_password : array[0..SHPWLEN] of char;
shi50_ro_password : array[0..SHPWLEN] of char;
end;
TFNNetShareGetInfo = function(ServerName, netname : pwidechar;
Level : DWORD; var PBuffer: pointer):DWORD; stdcall;
TFNNetShareGetInfo9x = function(pszServer, pszNetName : pchar;
sLevel : smallint;
pbBuffer : pointer; cbBuffer: word;
var pcbTotalAvail : word):DWORD; stdcall;
TFNNetApiBufferFree = function(Buffer : pointer):DWORD; stdcall;
var
NetApiDll : string = "NETAPI32.DLL";
NetApiDll9x : string ="Svrapi.DLL";
NetApiModule : HModule = 0;
ShareGetInfo : TFNNetShareGetInfo = nil;
ShareGetInfo9x : TFNNetShareGetInfo9x = nil;
ApiBufferFree : TFNNetApiBufferFree = nil;
procedure InitNetApi;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
if NetApiModule=0 then NetApiModule:=LoadLibrary(Pchar(NetApiDll));
end else
if NetApiModule=0 then NetApiModule:=LoadLibrary(Pchar(NetApiDll9x));
end;
function NetShareGetInfo(ServerName, netname : pwidechar;
Level : DWORD; var PBuffer: pointer):DWORD;
begin
InitNetApi;
if @ShareGetInfo=nil then @ShareGetInfo:= GetProcAddress(NetApiModule, "NetShareGetInfo");
if @ShareGetInfo<>nil then
result:=ShareGetInfo(ServerName, netname,Level,PBuffer)
else result:=1;
end;
function NetShareGetInfo9x(ServerName, netname : pchar;
Level : smallint; PBuffer: pointer; BuffSize : word; var BytesAvail: word):DWORD;
begin
InitNetApi;
if @ShareGetInfo9x=nil then @ShareGetInfo9x:= GetProcAddress(NetApiModule, "NetShareGetInfo");
if @ShareGetInfo9x<>nil then
result:=ShareGetInfo9x(ServerName, netname,Level,PBuffer, BuffSize, BytesAvail)
else result:=1;
end;
function NetApiBufferFree(Buffer : pointer):DWORD;
begin
InitNetApi;
if @ApiBufferFree=nil then @ApiBufferFree:= GetProcAddress(NetApiModule, "NetApiBufferFree");
if @ApiBufferFree<>nil then
result:=ApiBufferFree(Buffer)
else result:=1;
end;
function Win9xGetShare(const S: string) : string;
var P : Pshare_info_50;
Ba, Cb : word;
D : DWORD;
begin
P:=nil;
result:="";
Cb:=0;
D:=NetShareGetInfo9x(nil, pchar(S), 50, P, Cb, Ba);
if D=NERR_BufTooSmall then
begin
Cb:=Ba;
GetMem(P, Cb);
try
D:=NetShareGetInfo9x(nil, pchar(S), 50, P, Cb, Ba);
if D=0 then
begin
result:=P^.shi50_path;
end// else result:="2#"+IntToStr(D);
finally
FreeMem(P);
end;
end// else result:="#"+IntToStr(D);
end;
function GetShareLocalPath(const Path : string):string;
var Buffer : array[0..MAX_PATH-1] of WideChar;
CompName : array[0..MAX_COMPUTERNAME_LENGTH] of char;
P : PSHARE_INFO_2;
Rslt : DWORD;
S, SCn : string;
begin
result:="";
Rslt:=sizeof(CompName);
if GetComputerName(@CompName, Rslt) then
begin
S:=Path;
Scn:=GetParameter("\\",S,["\"],[]);
S:=GetParameter("\\"+SCN+"\",S,["\"],[]);
if AnsiUpperCase(Scn)=AnsiUpperCase(string(CompName)) then
begin
if Win32Platform <> VER_PLATFORM_WIN32_NT then
begin
result:=Win9xGetShare(S);
end else
begin
P:=nil;
Rslt := NetShareGetinfo(nil,StringToWideChar(S, @Buffer[0], sizeof(Buffer)),2, pointer(P));
if (Rslt=0) and (P<>nil) then
begin
if P^.shi2_type=STYPE_DISKTREE then
result:=WideCharToString(P^.shi2_path);
if NetApiBufferFree(P)<>0 then
LocalFree(integer(P));
end;
end;
end;
end;
end;
initialization
finalization
if NetApiModule<>0 then FreeLibrary(NetApiModule);
end.
← →
Verg (2003-08-23 20:22) [3]Насчет Common и GetParameter - уже спрашивали, поищите - где-то в форуме есть... - пустяк
← →
vv_fran (2003-08-24 18:46) [4]Уважаемый Verg, не наше я Common и GetParameter нигде.
Подскажи, пожалуйста, что это такое.
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2003.09.04;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.025 c