sql - 表单打开的 Microsoft Access 用户日志
问题描述
我有一个带有 sql 后端的 Microsoft 访问数据库。我需要成功打开表单的日期和时间的 Windows 用户日志。我更喜欢将数据记录到链接的 sql server 表中。有没有办法做到这一点?
解决方案
作为 Lee Macs 答案的附录:
出于安全原因,您应该使用
CreateObject("Wscript.Network").UserName
代替
Environ("username")
检索到当前登录的 Windows 用户,因为环境变量username
很容易被覆盖(意味着有人可以假装不同的用户)。
或者,如果您愿意,也可以使用 Windows API:
Private Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetWindowsUserName() As String
Dim buffer As String * 255
Dim result As Long
result = GetUserName(buffer, 255)
If result > 0 Then _
GetWindowsUserName = Left(buffer, InStr(buffer, Chr(0)) - 1)
End Function
推荐阅读
- node.js - 从android设备发送http请求到PC上的nodejs本地服务器
- javascript - 我想将我的圆圈标记(请参阅我的创建圆圈的代码)更改为三角形标记。我需要什么代码?
- r - 合并R中多个excel文件中的特定列?
- java - 如何在 Java Spring @PropertySource 注释中将字符串更改为小写
- javascript - flatpickr 更改事件中的清除日期
- visual-studio - SFML 2.5.1 错误 LNK1112 模块机器类型“x86”与目标机器类型“x64”冲突
- python - 如何在 Python 中指定可选的排序键
- r - 循环特定列数据并将结果添加为 R 中的新列
- r - 在 r 中填充一个 4-D 数组
- javascript - 专注于 v-for 问题中的 textarea