98下可以改注册表,但2K下就麻烦了,涉及到权限问题。
unit RegOptUnt;
interface
uses
Windows, SysUtils;
const
SubKeys='Software/Microsoft/Windows/CurrentVersion/Network/LanMan';
WRITE_SHARED = 258;
READ_SHARED = 401 ;
function gfunAddToRegRun(KeyName,KeyValue:String):Boolean;
procedure SharedFolder(Shared_Name
Char;Shared_Mode
WORD;file_path
Char;remark
Char);
implementation
//功能:共享一个目录
//
//输入:共享名(Shared_Name);
// 共享模式(Shared_Mode);
// 本地机路径(file_paht);
// 备注(remark)
//
//输出:无
procedure SharedFolder(Shared_Name
Char;
Shared_Mode
WORD;
file_path
Char;
remark
Char);
var
retLng:integer;
tmpParam:integer;
sa:SECURITY_ATTRIBUTES;
h_key:HKEY;
p_dword
DWORD;
values
WORD;
ptmpChar
Char;
begin
p_dword:=nil;
ptmpChar:=new(pchar);
ptmpChar:='';
//建立主键SubKeys
//Shared_Name是共享后的共享文件夹的名字
//h_key是建好后返回的主键句柄
strCat(ptmpChar,SubKeys);
strCat(ptmpChar,'/');
strCat(ptmpChar,Shared_Name);
retLng:=RegCreateKeyEx(HKEY_LOCAL_MACHINE,
ptmpChar,
0,
Shared_Name,
REG_OPTION_VOLATILE,
KEY_ALL_ACCESS,
@sa,
h_key,
p_dword);
//创建主键时,失败!
if(retLng<>ERROR_SUCCESS) then exit;
{
p_dword是windows返回的错误编号
if (p_dword^=REG_OPENED_EXISTING_KEY) then
Application.MessageBox('','',MB_OK)
else if (p_dword^=REG_CREATED_NEW_KEY) then
Application.MessageBox('','',MB_OK);
}
//建Dword值:Flags
//共享的模式分别:完全共享、只读共享
retLng := RegSetValueEx(h_key,
'Flags',
0,
REG_DWORD,
@Shared_Mode,
sizeof(Shared_Mode));
//建二进制值串:parm1enc
//完全共享的密码
tmpParam:=0;
retLng := RegSetValueEx(h_key,
'Parm1enc',
0,
REG_BINARY,
0,
0);
//建二进制值串:parm2enc
//只读共享的密码
tmpParam:=0;
retLng := RegSetValueEx(h_key,
'Parm2enc',
0,
REG_BINARY,
0,
0);
//建字符串:Path
//要共享的文件夹的绝对地址
retLng := RegSetValueEx(h_key,
'Path',
0,
REG_SZ,
file_path,
length(file_path));
//建字符串:Remark
//共享文件夹的备注
retLng := RegSetValueEx(h_key,
'Remark',
0,
REG_SZ,
remark,
sizeof(remark));
//建DWORD值:Type
//我也不知道,反正windows中大多是0x0
tmpParam:=0;
retLng := RegSetValueEx(h_key,
'Type',
0,
REG_DWORD,
@tmpParam,
sizeof(tmpParam));
//关闭
ptmpChar:='';
RegCloseKey(h_key);
end;