Function ChangeMdbPassword ( tcMdbFile, tcOldPswd, tcNewPswd )
* 修改 Access 数据库的密码,必须独占打开数据库,使用前请确保没有其他程序使用数据库
Local IsOK
IsOK = .F.
lcRetuStr = []
tcMdbFile = iif(Type([tcMdbFile])=[C], tcMdbFile, [])
tcOldPswd = iif(Type([tcOldPswd])=[C], tcOldPswd, [])
tcNewPswd = iif(Type([tcNewPswd])=[C], tcNewPswd, [])
If File( tcMdbFile )
IsOK = .T.
Local loADODB, lcOldError
lcOldError = On([ERROR])
On Error IsOK = .F.
loADODB = CreateObject( [ADODB.Connection] )
loADODB.Mode = 12
loADODB.Provider = [Microsoft.Jet.OLEDB.4.0]
loADODB.Properties([Jet OLEDB
atabase Password]) = tcOldPswd
loADODB.Open([Data Source=] + tcMdbFile)
loADODB.Execute('ALTER DATABASE PASSWORD [' + tcNewPswd + '][' + tcOldPswd + ']')
loADODB.Close
Release loADODB
loADODB = Null
On Error &lcOldError.
Endif
Return IsOK
Endfunc