WIN2000与WIN98中创建共享文件夹的方法

时间:2010-01-28 08:40:47  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:列出(包括相关的一系列网络函数等),以慰大家。unit PubLib;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,Menus, ComCt...
  正文:在去年写的使用SQLSERVER的扩展存储过程实现远程备份与恢复一文中许多人都提到如何在程序中创建共享文件夹的问题,我当时因为工作忙,只看到了留言没有及时去回复,对读者造成的不便深感抱歉。在此文中,我就把如何在WIN2000与WIN98中创建共享文件夹的代码一一列出(包括相关的一系列网络函数等),以慰大家。


unit PubLib;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ComCtrls, ToolWin, Db, ADODB, DBCtrls, StdCtrls,Math,dbgrids,
Buttons, ExtCtrls,clipbrd,Registry, variants;

const
NTlib = 'NETAPI32.DLL';
MElib = 'SVRAPI.DLL';
{共享类型}
STYPE_DISKTREE = 0 ;
STYPE_PRINTQ = 1 ;
STYPE_DEVICE = 2 ;
STYPE_IPC = 3 ;
{访问权限}
ACCESS_READ = 0 ;
ACCESS_WRITE = 1 ;
ACCESS_CREATE = 2 ;
ACCESS_EXEC = 3 ;
ACCESS_DELETE = 4 ;
ACCESS_ALL = 7 ;

type
NET_API_STATUS = Dword;
//纪录类型声明,注意参数类型的正确对应,最好别看 Delphi 的帮助,引起误导
TSHARE_INFO_502 = record
shi502_netname: PWideChar;
shi502_type: DWORD;
shi502_remark: PWideChar;
shi502_permissions: DWORD;
shi502_max_uses: DWORD;
shi502_current_uses: DWORD;
shi502_path: PWideChar;
shi502_passwd: PWideChar;
shi502_reserved: DWORD;
shi502_security_descriptor: photoshop/ target=_blank class=infotextkey>psECURITY_DESCRIPTOR;
end;
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;

//******************************************网络函数********************
function IsWinNT: Boolean; //判断是否NT系统
function GetPDCName: string; //取得主域控制器名称
function GetDomainName: AnsiString; //获取域名
//建立、删除共享文件夹
//for win2000,winnt
function AppendShareResource(ServerName,FilePath,NetName, Remark : string): Integer;
function DeleteShareResource(ServerName: string; NetName: string): Integer;
//for win98
function AddShareResource (ServerName : PChar; FilePath : PChar;
NetName : PChar; Remark : PChar ) : Integer;
function DelShareResource(ServerName: string; NetName: string): Integer;

var NTNetGetDCName : function(Server, Domain: pWideChar; var DC: pWideChar): NET_API_STATUS; StdCall; NTNetApiBufferFree: function(lpBuffer: Pointer):NET_API_STATUS; StdCall; NTNetShareAdd : function (servername:Widestring; level: DWORD; Buf: PBYTE; var parm_err: PDWORD ): DWORD; stdcall;//建立共享目录函数 NTNetShareDel : function (ServerName:Widestring; NetName: Widestring; Reserved: DWord): Integer; stdcall; //撤销共享目录函数 MENetShareAdd : function (ServerName : PChar; ShareLevel : SmallInt; Buffer : Pointer; Size : Word) : Integer; StdCall; MENetShareDel : function (ServerName : PChar; NetName : PChar; Reserved : Word) : Integer; StdCall;

implementation

function IsWinNT: Boolean;
var
VersionInfo: TOSVersionInfo;
begin
  VersionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  Result := GetVersionEx(VersionInfo);
  if Result then
  Result := VersionInfo.dwPlatformID = VER_PLATFORM_WIN32_NT;
end;

function GetPDCName: string;
var
pDomain : PWideChar;
LibHandle : THandle;
begin
  Result := '';
  LibHandle := LoadLibrary(NTlib);
  if LibHandle = 0 then
  raise Exception.Create('Unable to map library: ' + NTlib);
  try
    @NTNetGetDCName := GetProcAddress(Libhandle, 'NetGetDCName');
    @NTNetApiBufferFree := GetProcAddress(Libhandle, 'NetApiBufferFree');
    try
      if NTNetGetDCName(nil, nil, pDomain) = 0 then
      Result := WideCharToString(pDomain);
      finally
        NTNetApiBufferFree(pDomain);
      end;
      finally
        FreeLibrary(Libhandle);
      end;
    end;
    
    function GetDomainName: AnsiString;
    type
    WKSTA_INFO_100 = record
    wki100_platform_id: Integer;
    wki100_computername: PWideChar;
    wki100_langroup: PWideChar;
    wki100_ver_major: Integer;
    wki100_ver_minor: Integer;
  end;
  
  WKSTA_USER_INFO_1 = record
  wkui1_username: PChar;
  wkui1_logon_domain: PChar;
  wkui1_logon_server: PChar;
  wkui1_oth_domains: PChar;
end;
type

"WIN2000与WIN98中创建共享文件夹的方法"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12533.html

 1/4    1 2 3 4 下一页 尾页


关键字:

关于《WIN2000与WIN98中创建共享文件夹的方法》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td