【问题标题】:Launch password protected database and close existing one启动受密码保护的数据库并关闭现有数据库
【发布时间】:2018-02-21 22:00:37
【问题描述】:

我正在尝试设置一个包含 VBA 代码的“启动器”数据库,该代码将打开第二个受密码保护的数据库。然后我可以将启动器 db 转换为 accde,这样就无法读取包含密码的 VBA。

到目前为止,我有以下代码。

Private Sub Form_Load()
 Dim acc As Access.Application
 Dim db As DAO.Database
 Dim strDbName As String

 strDbName = "C:\database Folder\secureDB.accdb"
 Set acc = New Access.Application
 acc.Visible = True
 Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=swordfish")

 acc.OpenCurrentDatabase (strDbName)
 
 Application.Quit
  
End Sub

当启动器数据库打开时,会加载一个表单,该表单随后会触发上述代码。它可以工作,但问题是最后一行旨在仅关闭启动器数据库但关闭两个数据库。我也尝试过使用 Shell 打开主数据库,但无法通过这种方式传递密码。

如何关闭第一个数据库,同时保持第二个数据库打开?

【问题讨论】:

  • 我建议在 shell 脚本中使用命令行选项打开或搜索“访问前端更新程序”以查看它们是如何执行此操作的(我认为一个称为 mdbloader)。
  • 或者试试 `acc.Application.Quit'。
  • 请注意,访问数据库可以反编译,因此可以读取字符串(通过一些努力)。正如我之前的评论中所说,我有一个数据库,其中存储了一个带有用户密码的加密数据库密码,因此只有拥有有效密码的用户才能登录。
  • @ErikvonAsmuth:密码存储在键盘下;-)。也许更好地检查 Windows 登录以查看用户是否可以登录?
  • @BitAccesser 这是伪安全。您必须假设黑客可以读取数据库中所有未加密的部分。你可以修改我的实现(找到here)来检查它并默认使用Windows用户名,但这并不能真正加强它。当然,正确的密码管理就是一切,但 Windows 密码也可能被贴在键盘下面。

标签: ms-access vba ms-access-2010


【解决方案1】:

您可以使用以下内容:

Private Sub Form_Load()
 Dim acc As Access.Application
 Dim db As DAO.Database
 Dim strDbName As String

 strDbName = "C:\database Folder\secureDB.accdb"
 Set acc = New Access.Application
 acc.Visible = True
 acc.OpenCurrentDatabase strDbName, False, "swordfish"
 Set db = acc.CurrentDb() 'Don't know why you want a reference to the db
 acc.UserControl = True
 Application.Quit
End Sub

相关部分是acc.UserControl = True,它强制数据库保持可见状态,并在对应用程序对象的引用被破坏时阻止它关闭。

可以在this answer中找到一个存储主数据库密码的示例数据库,该数据库使用加盐用户密码加密

【讨论】:

  • 谢谢。我以前没有听说过 UserControl 方法。我多年来一直坚持这一点。我试图避免为每个用户提供密码,这就是为什么我不能使用你的其他方法。再次感谢您的帮助
  • 顺便说一句,如果您想将此作为我第一个问题的答案,我也很乐意接受。如果没有,我会自己添加它,这样问题就不会悬而未决。只是认为你应得的功劳
【解决方案2】:

我无法让接受的答案正常工作。我能够与:

Public Function OpenAccessDb(strVerPath, strFileName, sRecordset, strPwd)
    'You may also need to have the following References Added:
    'Microsoft Access 16.0 Object Library & Microsoft Office 16.0 Access Database Engine Object
    'Visual Basic for Applications// Microsoft Excel 16.0 Object Library// OLE Automation//
    'Microsoft Forms 2.0 Object Library// Microsoft Outlook 16.0 Object Library// Microsoft Office 16.0 Object Library
    Dim oDAO As DAO.DBEngine, oDB As DAO.Database, oRS As DAO.Recordset
    Dim sPath As String
    'sPath = GetProperDirectory(strVerPath, strFileName) ' you can bypass this function by setting the path manually below and commenting this out.
    sPath = "C:\database Folder\secureDB.accdb"'manually set the path here and comment out line above
    Set oDAO = New DAO.DBEngine
    Set oDB = oDAO.OpenDatabase(sPath, False, True, "MS Access;PWD=" & strPwd)
    Set oRS = oDB.OpenRecordset(sRecordset)

    ''paste to call this function
    ''note this function utilizes the GetProperDirectory function.
    ''The GetProperDirectory function uses xxxxx as the location source
    ''therefore the strVerPath should start after \xxxxx\yyyyyy\yyyyy\DB.accdb
    'strVerPath = "\yyyyyy\yyyyy\"
    'strFileName= "DB.accdb"
    'sRecordSet= "table in access DB" 'the table you are sending the data to
    'strPwd = "password' 'this is the password that allows access to the database
    'booOpenSend= OpenAccessDb(strVerPath, strFileName, sRecordSet, strPwd)
    ''end paste
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 2014-10-02
    相关资源
    最近更新 更多