http://www.delphibbs.com/keylife/iblog_show.asp?xid=101
修改ACCESS数据库的密码//引用ComObj单元
//=============================================================================
// Procedure: ChangeAccessPassword
// Author : ysai
// Date : 2004-02-10
// Arguments: const AFileName : string; const AOldPassword : string; const ANewPassword : string
// Result : Boolean
//=============================================================================
function ChangeAccessPassword(
const AFileName : string;
const AOldPassword : string;
const ANewPassword : string
):Boolean;
//修改ACCESS数据库密码,必须独占打开数据库,使用前请确保没有其他程序使用数据库
const
SAlterDatabasePassword = 'ALTER DATABASE PASSWORD %s %s';
var
acn : OleVariant;
sOld : string;
sNew : string;
begin
if AOldPassword = '' then
sOld := 'Null'
else
sOld := '[' + AOldPassword + ']';
if ANewPassword = '' then
sNew := 'Null'
else
sNew := '[' + ANewPassword + ']';
try
acn := CreateOleObject('ADODB.Connection');
//Delphi中的cmShareExclusive,ADO中的adModeShareExclusive
//用排它方式打开,直接用数字可以不用引用ADO单元
acn.Mode := 12;
acn.Provider := 'Microsoft.Jet.OLEDB.4.0';
acn.Properties('Jet OLEDB
atabase Password') := AOldPassword;
acn.Open('Data Source=' + AFileName);
try
acn.Execute(Format(SAlterDatabasePassword,[sNew,sOld]));
finally
acn.Close;
end;
Result := True;
except
Result := False;
end;
end;