我需要能够从Go应用程序中管理Windows本地用户帐户,并且似乎在不使用CGo的情况下,没有本机绑定。
我的最初搜索使人们说,最好使用“ exec.Command”来运行“ net user”命令,但是在解析响应代码时,这似乎是混乱且不可靠的。
我发现可以在netapi32.dll库中找到处理此类事件的函数,但是由于Go本身不支持Windows头文件,因此调用这些函数似乎并不容易。
以https://github.com/golang/sys/tree/master/windows中的示例为例,看来Go团队一直在重新定义其代码中的所有内容,然后调用DLL函数。
我很难将其包装在一起,但是我已经有了我要针对的低级API模板,然后像在Go运行时核心一样将高级API包装在其上。
type LMSTR ????
type DWORD ????
type LPBYTE ????
type LPDWORD ????
type LPWSTR ????
type NET_API_STATUS DWORD;
type USER_INFO_1 struct {
usri1_name LPWSTR
usri1_password LPWSTR
usri1_password_age DWORD
usri1_priv DWORD
usri1_home_dir LPWSTR
usri1_comment LPWSTR
usri1_flags DWORD
usri1_script_path LPWSTR
}
type GROUP_USERS_INFO_0 struct {
grui0_name LPWSTR
}
type USER_INFO_1003 struct {
usri1003_password LPWSTR
}
const (
USER_PRIV_GUEST = ????
USER_PRIV_USER = ????
USER_PRIV_ADMIN = ????
UF_SCRIPT = ????
UF_ACCOUNTDISABLE = ???? …Run Code Online (Sandbox Code Playgroud) 我想获取特定机器上的共享列表.所以我决定使用Windows API NetApi32.dll.这是我的代码片段:
Dim svr As String = Environment.MachineName
Dim level As Integer = 2
Dim sharesRead As Integer, totalEntries As Integer, nRet As Integer, hResume As Integer = 0
Dim pBuffer As IntPtr = IntPtr.Zero
nRet = NetApi32.NetShareEnum(svr, level, pBuffer, -1, sharesRead, totalEntries, hResume)
Run Code Online (Sandbox Code Playgroud)
我得到了1231的返回码,但似乎无法找到相同的东西.如果不正确的话,有人能指出我如何做到这一点的正确方向吗?