NetUserGetInfo / NetLocalGroupGetInfo返回错误1722 [英] NetUserGetInfo/NetLocalGroupGetInfo returning error 1722
问题描述
我有以下的code(VB.NET),其目的是确定给定的帐户名是指一个本地组或用户帐户。这将只要求用户/群组一台机器,而不是一个域上。
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
我的问题是,NetUserGetInfo / NetLocalGroupGetInfo总是调用返回错误code 1722(RPC服务器不可用)。我使用本地计算机名和远程Windows服务器,关于这一点我有管理员权限,具有相同的结果的名字尝试。
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?
更新:不知道这会有所帮助,但我试着运行上面的两个运7和Win XP SP3。我的编译目标定位在.NET 4.0客户端框架。
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.
推荐答案
NetUserGetInfo
和 NetLocalGroupGetInfo
既期待统一code(宽)字符串参数。你能声明的Uni code
这些方法和确定问题是否依然存在?
NetUserGetInfo
and NetLocalGroupGetInfo
both expect Unicode (wide) string parameters. Can you Declare Unicode
these methods and confirm whether the problem persists?
另请参见 http://www.xtremedotnettalk.com/showthread.php?t= 69609
这篇关于NetUserGetInfo / NetLocalGroupGetInfo返回错误1722的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!