首页 > 开发 > 综合 > 正文

设置只有管理员才能改变AllowBypassKey属性

2024-07-21 02:12:32
字体:
来源:转载
供稿:网友

最大的网站源码资源下载站,

tmtony翻译:

在access的帮助文件中说明createproperty 方法的语法:

set property = object.createproperty (name, type, value, ddl)
其实最后一个参数是这个解释的(部分描述):

ddl 可选. 一个变量(逻辑子类型) 指定这个属性是否为ddl对象. 缺少值为false. 如果设置为true,除非他有 dbsecwritedef 权限,用户就不能改变或删除这个属性
createproperty 是用来创建或设置 allowbypasskey 属性如果这个属性设为true, 那就可以禁用户近shift键来禁止启动属性和autoexec 宏. 然而,access帮助中提供的例子没有使用第四个 ddl 参数. 这意味着任何人都可以打开数据据然后用程序复位allowbypasskey 属性.

所以,为了限制普通用户去改变这个属性,所以我们设置第四个参数为true 。

为了对比,我们也同时列出了access本身的例子以便参照

' *********** code start ***********
function changepropertyddl(stpropname as string, _
proptype as dao.datatypeenum, vpropval as variant) _
as boolean
' uses the ddl argument to create a property
' that only admins can change.
'
' current createproperty listing in access help
' is flawed in that anyone who can open the db
' can reset properties, such as allowbypasskey
'
on error goto changepropertyddl_err

dim db as dao.database
dim prp as dao.property

const conpropnotfounderror = 3270

set db = currentdb
' assuming the current property was created without
' using the ddl argument. delete it so we can
' recreate it properly
db.properties.delete stpropname
set prp = db.createproperty(stpropname, _
proptype, vpropval, true)
db.properties.append prp

' if we made it this far, it worked!
changepropertyddl = true

changepropertyddl_exit:
set prp = nothing
set db = nothing
exit function

changepropertyddl_err:
if err.number = conpropnotfounderror then
' we can ignore when the prop does not exist
resume next
end if
resume changepropertyddl_exit
end function

帮助本身的例子
function changeproperty(strpropname as string, _
varproptype as variant, varpropvalue as variant) as integer
' the current listing in access help file which will
' let anyone who can open the db delete/reset any
' property created by using this function, since
' the call to craeteproperty doesn't use the ddl
' argument
'
dim dbs as database, prp as property
const conpropnotfounderror = 3270

set dbs = currentdb
on error goto change_err
dbs.properties(strpropname) = varpropvalue
changeproperty = true

change_bye:
exit function

change_err:
if err = conpropnotfounderror then ' property not found.
set prp = dbs.createproperty(strpropname, _
varproptype, varpropvalue)
dbs.properties.append prp
resume next
else
' unknown error.
changeproperty = false
resume change_bye
end if
end function
' *********** code end ***********
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表