|
-
- Dim result, user, leng
- user = string(100, "*")
- leng = 100
- Extern.Declare micLong, "GetUserName", "advapi32.dll", "GetUserNameA", micString,micLong
- result = Extern.GetUserName(user, leng)
复制代码
原本在robot脚本中调用这个dll函数定义:
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
改到用在QTP中以后,为什么一跑这段代码就出错呢?而且会引起QTP崩溃。求助高手如何在QTP中得到当前机器的登陆用户名。谢谢。
API的定义:
VB声明 | Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long | 说明 | 取得当前用户的名字 | 返回值 | Long,TRUE(非零)表示成功,否则返回零。会设置GetLastError | 参数表 | 参数 | 类型及说明 | lpBuffer | String,一个字串缓冲区,预先初始化成由nSize指定的长度。它将用于容纳用户名 | nSize | Long,初始化成lpBuffer的长度。返回以后,它会包含载入lpBuffer的字符数量 | 示例 | Dim s$, cnt&, dl&
cnt& = 199
s$ = String$(200,0)
dl& = GetUserName(s$, cnt)
Debug.Print Left$(s$, cnt); cnt |
|
|