Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
// the structures needed:
Share_Info50 = Packed Record
shi50_netname : Array[0..12] of Char; {13}
shi50_type : Byte;
shi50_flags : Word;
shi50_remark : PChar;
shi50_path : PChar;
shi50_rw_password : Array[0..8] of Char; {9}
shi50_ro_password : Array[0..8] of Char;
End;
Share_Info2 = Packed Record
shi2_netname : Lpwstr;
shi2_type : DWord;
shi2_remark : Lpwstr;
shi2_permis : DWord;
shi2_maxusers : DWord;
shi2_curusers : DWord;
shi2_path : Lpwstr;
shi2_password : Lpwstr;
shi2_eof: DWord;
End;
// The function declarations & parameters
{ ShareResource: Shares a resource on the specified machine.
Parameters:
ServerName= Name of server on which to share resource. Nil = Local Machine.
FilePath = Path to the resource to be shared. (This should be ALL upper-case);
NetName = Network Name to give the shared resource. Must be 12 characters or less.
Remark = Comment. Can be an empty string.
ShareType = Type of resource. See Constants declared above.
Flags = Sharing flags. See Constants declared above.
RWPass = Full Access Password - Must be 8 characters or less. Can be an empty string.
ROPass = Read Only Password - Must be 8 characters or less. Can be an empty string.
Example Call: ShareResource(Nil, 'C:\TEMP', 'TESTING', 'My Comment', STYPE_DISKTREE, SHI50F_RDONLY, '','MYPASS');
This Shares Disk Resource C:\TEMP as 'TESTING' with comment 'My Comment' on the local machine.
Access is Read Only, with Read Only password = 'MYPASS'. No Full Access Password specified.
(It would be ignored if specified) }
function ShareResource(ServerName : PChar; FilePath : PChar;
NetName : PChar; Remark : PChar;
ShareType : Byte; Flags : Word;
RWPass : PChar; ROPass : PChar ) : Integer;
{ DeleteShare: Deletes a shared resource on the specified machine.
Parameters:
ServerName= Name of server on which to share resource. Nil = Local Machine.
NetName = Network Name of the shared resource.
Example Call: DeleteShare(Nil, 'TESTING');
This Deletes The network share named 'TESTING' on the local machine.}
function DeleteShare(ServerName : PChar; NetName : PChar) : Integer;
{ GetShareInfo: Gets information about a shared resource on the specified machine.
Parameters:
ServerName = Name of server where the shared resource resides. Nil = Local Machine.
NetName = Network Name of the shared resource. Must be 12 characters or less.
ShareStruct = Share_Info50. This structure will be filled with information on the
specified share if the function succeeds.
Example Call:
var MyShareStruct : Share_Info50;
GetShareInfo(Nil, 'TESTING', MyShareStruct);
This fills MyShareStruct with share information about 'TESTING' on the local machine.}
function GetShareInfo(ServerName : PChar; NetName : PChar; Var ShareStruct : Share_Info50) : Integer;
{ SetShareInfo: Sets information for a shared resource on the specified machine.
Parameters:
ServerName = Name of server where the shared resource resides. Nil = Local Machine.
NetName = Network Name of the shared resource. Must be 12 characters or less.
ShareStruct = Share_Info50. This structure contains the new information for the shared
resource. It is easiest to fill this structure first with GetShareInfo and
then change desired parameters; however you may fill it completely yourself.
You may not change the path of a shared resource, if you change this
parameter in the structure, it will be ignored.
Example Call: SetShareInfo(Nil, 'TESTING', MyShareStruct);
This changes the share information for 'TESTING' to reflect the data in MyShareStruct}
function SetShareInfo(ServerName : PChar; NetName : PChar; ShareStruct : Share_Info50) : Integer;
// The mapping of the function to the correct DLL entry:
Var
NetShareAdd: function(ServerName : PChar; ShareLevel : SmallInt; Buffer : Pointer; Size : Word) : Integer; StdCall;
NetShareAddNT: function(ServerName : PChar; ShareLevel : DWord; Buffer : Pointer; Error : Pointer) : Integer; StdCall;
NetShareDel: function(ServerName : PChar; NetName : PChar; Reserved : Word) : Integer; StdCall;
NetShareGetInfo: function(ServerName : PChar; NetName : PChar; ShareLevel : SmallInt; Buffer : Pointer; Size : Word; Var Used : Word) : Integer; StdCall;
NetShareSetInfo: function(ServerName : PChar; NetName : PChar; ShareLevel : SmallInt; Buffer : Pointer; Size : Word; Reserved : SmallInt) : Integer; StdCall;
// Initializing the mappings:
Var Hand : LongWord;
Initialization
If IsNT then
Hand := LoadLibrary('NetApi32')
Else
Hand := LoadLibrary('SvrApi');
If Hand <> 0 then
Begin
If IsNT then
NetShareAddNT := GetProcAddress(Hand,'NetShareAdd')
Else
NetShareAdd := GetProcAddress(Hand,'NetShareAdd');
NetShareDel := GetProcAddress(Hand,'NetShareDel');
NetShareGetInfo := GetProcAddress(Hand,'NetShareGetInfo');
NetShareSetInfo := GetProcAddress(Hand,'NetShareSetInfo');
End;
Finalization
If Hand <> 0 then
FreeLibrary(Hand);
End.
// Higher level functions to separate between W9x & NT variants:
function ShareResource(ServerName : PChar; FilePath : PChar;
NetName : PChar; Remark : PChar;
ShareType : Byte; Flags : Word;
RWPass : PChar; ROPass : PChar ) : Integer;
var MyShare : Share_Info50;
MyShareNT : Share_Info2;
PMyShare : ^Share_Info50;
NoError : DWord;
b : Integer;
begin
If IsNT then
Begin
NoError := 0;
MyShareNT.shi2_netname := @NetName;
Case ShareType of
0 : Begin
MyShareNT.shi2_type := STYPE_DISKTREE;
MyShareNT.shi2_permis := $7F; // => ACCESS_ALL
End;
1 : Begin
MyShareNT.shi2_type := STYPE_PRINTQ;
MyShareNT.shi2_permis := $7F; // => ACCESS_WRITE + ACCESS_CREATE
End;
End;
MyShareNT.shi2_remark := @Remark;
MyShareNT.shi2_maxusers := $FFFFFFFF;
b := 1;
While b < Length(FilePath) do
Begin
If FilePath[b] = ';' then
Begin
FilePath[b] := ',';
End;
Inc(b);
End;
MyShareNT.shi2_path := @FilePath;
MyShareNT.shi2_password := @RWPass;
MyShareNT.shi2_eof := $0;
// PMyShareNT := @MyShareNT; stype_disktree
Result := NetShareAddNT(ServerName,2,@MyShareNT,@NoError);
ShowMessage('FilePath : ' + FilePath + ' Size : ' + IntToStr(SizeOf(MyShareNT))+ #13 + #10 + 'Result : ' + IntToStr(Result) + ' ' + GetNetErrorString(2100+Result) + ' Error : ' + IntToStr(NoError));
End
Else
Begin
strLcopy(MyShare.shi50_netname,NetName,13);
MyShare.shi50_type := ShareType;
MyShare.shi50_flags := Flags;
MyShare.shi50_remark := Remark;
MyShare.shi50_path := FilePath;
strLcopy(MyShare.shi50_rw_password,RWPass,9);
strLcopy(MyShare.shi50_ro_password,ROPass,9);
PMyShare := @MyShare;
Result := NetShareAdd(ServerName,50,PMyShare,SizeOf(MyShare));
End;
end;
function DeleteShare(ServerName : PChar; NetName : PChar) : Integer;
begin
Result := NetShareDel(ServerName,NetName,0);
end;
function GetShareInfo(ServerName : PChar; NetName : PChar; Var ShareStruct : Share_Info50) : Integer;
var PMyShare : ^Share_Info50;
AmountUsed : Word;
Error : Integer;
begin
PMyShare := AllocMem(255);
Error := NetShareGetInfo(ServerName,NetName,50,PMyShare,255,AmountUsed);
If Error = 0 Then
Begin
ShareStruct.shi50_netname := PMyShare.shi50_netname;
ShareStruct.shi50_type := PMyShare.shi50_type;
ShareStruct.shi50_flags := PMyShare.shi50_flags;
ShareStruct.shi50_remark := PMyShare.shi50_remark;
ShareStruct.shi50_path := PMyShare.shi50_path;
ShareStruct.shi50_rw_password := PMyShare.shi50_rw_password;
ShareStruct.shi50_ro_password := PMyShare.shi50_ro_password;
End;
FreeMem(PMyShare);
Result := Error;
end;
function SetShareInfo(ServerName : PChar; NetName : PChar; ShareStruct : Share_Info50) : Integer;
var PMyShare : ^Share_Info50;
begin
PMyShare := @ShareStruct;
Result := NetShareSetInfo(ServerName,NetName,50,PMyShare,SizeOf(ShareStruct),0);
end;
// some constants:
{Resource Type Constants}
STYPE_DISKTREE = 0; {Directory Share}
STYPE_PRINTQ = 1; {Printer Share}
{Flag Constants}
SHI50F_RDONLY = 1; { Share is Read Only}
SHI50F_FULL = 2; { Share is Full Access}
SHI50F_DEPENDSON = (SHI50F_RDONLY or SHI50F_FULL); {Access depends upon password entered by user}
{OR the following with access constants to use them.
I.E.: flags := (SHI50F_RDONLY OR SHI50F_SYSTEM) }
SHI50F_PERSIST = 256; {The share is restored on system startup}
SHI50F_SYSTEM = 512; {The share is not normally visible}
// The actual sharing:
Flags := SHI50F_FULL;
If fDelen.NetPermanent.Checked then
Flags := (SHI50F_FULL + SHI50F_PERSIST);
ShareResource(Nil,PChar(Local_),PChar(Share_),PChar(Comment_),STYPE_DISKTREE,Flags,@GeenPass,@GeenPass); { Full Access and no passwords for RO or RW access }