NetUserGetInfo/NetLocalGroupGetInfo 返回错误 1722
我有以下代码(VB.NET),旨在确定给定的帐户名称是指本地组还是用户帐户。这只会针对计算机上的帐户/组调用,而不是域。
Module netapi
Private Declare Function NetUserGetInfo Lib "Netapi32.dll" ( _
ByVal ServerName As String, _
ByVal UserName As String, _
ByVal level As Integer, _
ByRef BufPtr As IntPtr) As Integer
Private Declare Function NetLocalGroupGetInfo Lib "Netapi32.dll" ( _
ByVal ServerName As String, _
ByVal GroupName As String, _
ByVal level As Integer, _
ByRef BufPtr As IntPtr) As Integer
Declare Unicode Function NetApiBufferFree Lib "Netapi32.dll" _
(ByRef buffer As IntPtr) As Long
Public Function GetPrincipalType(ByVal MachineName As String, ByVal AccountName As String) As String
Dim bufPtr As IntPtr
Dim lngReturn As Integer = NetUserGetInfo("\\" & MachineName, AccountName, 0, bufPtr)
Console.WriteLine("NetUserGetInfo return value = " & lngReturn)
Call NetApiBufferFree(bufPtr)
bufPtr = IntPtr.Zero
If lngReturn = 0 Then
Return "User"
End If
lngReturn = NetLocalGroupGetInfo("\\" & MachineName, AccountName, 0, bufPtr)
Console.WriteLine("NetLocalGroupGetInfo return value = " & lngReturn)
Call NetApiBufferFree(bufPtr)
bufPtr = IntPtr.Zero
If lngReturn = 0 Then
Return "Group"
End If
Return "NotFound"
End Function
End Module
我的问题是 NetUserGetInfo/NetLocalGroupGetInfo 调用始终返回错误代码 1722(RPC 服务器不可用)。我尝试使用本地计算机名称和我拥有管理员权限的远程 Windows 服务器的名称,得到相同的结果。
如果我替换 "\\" & MachineName
与 Nothing
则无论 AccountName
引用的帐户/组是否实际存在,我都会收到错误 2221/2220(未找到用户/组)。
请帮忙。我做错了什么?
更新:不确定这是否有帮助,但我尝试在 Win 7 和 Win XP SP3 上运行上述内容。我的编译目标是 .NET 4.0 客户端框架。
I have the following code (VB.NET) which is designed to determine if a given account name refers to a local group or a user account. This will only be called for accounts/groups on a machine, not a domain.
Module netapi
Private Declare Function NetUserGetInfo Lib "Netapi32.dll" ( _
ByVal ServerName As String, _
ByVal UserName As String, _
ByVal level As Integer, _
ByRef BufPtr As IntPtr) As Integer
Private Declare Function NetLocalGroupGetInfo Lib "Netapi32.dll" ( _
ByVal ServerName As String, _
ByVal GroupName As String, _
ByVal level As Integer, _
ByRef BufPtr As IntPtr) As Integer
Declare Unicode Function NetApiBufferFree Lib "Netapi32.dll" _
(ByRef buffer As IntPtr) As Long
Public Function GetPrincipalType(ByVal MachineName As String, ByVal AccountName As String) As String
Dim bufPtr As IntPtr
Dim lngReturn As Integer = NetUserGetInfo("\\" & MachineName, AccountName, 0, bufPtr)
Console.WriteLine("NetUserGetInfo return value = " & lngReturn)
Call NetApiBufferFree(bufPtr)
bufPtr = IntPtr.Zero
If lngReturn = 0 Then
Return "User"
End If
lngReturn = NetLocalGroupGetInfo("\\" & MachineName, AccountName, 0, bufPtr)
Console.WriteLine("NetLocalGroupGetInfo return value = " & lngReturn)
Call NetApiBufferFree(bufPtr)
bufPtr = IntPtr.Zero
If lngReturn = 0 Then
Return "Group"
End If
Return "NotFound"
End Function
End Module
My problem is that the NetUserGetInfo/NetLocalGroupGetInfo calls always return error code 1722 (RPC Server unavailable). I've tried using the local machine name and the name of remote Windows servers, on which I have admin rights, with the same result.
If I replace "\\" & MachineName
with Nothing
then I get error 2221/2220 (User/Group not found) regardless of whether or not the account/group referenced by AccountName
actually exists.
Please help. What am I doing wrong?
Update: Not sure if this helps, but I've tried running the above on both Win 7 and Win XP SP3. My compilation is targetting the .NET 4.0 Client framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NetUserGetInfo
和NetLocalGroupGetInfo
都需要 Unicode(宽)字符串参数。您能否声明 Unicode
这些方法并确认问题是否仍然存在?另请参阅 http://www.xtremedotnettalk.com/showthread.php?t=69609< /a>
NetUserGetInfo
andNetLocalGroupGetInfo
both expect Unicode (wide) string parameters. Can youDeclare Unicode
these methods and confirm whether the problem persists?Also see http://www.xtremedotnettalk.com/showthread.php?t=69609