网站首页  词典首页

请输入您要查询的函数:

 

术语 wnetgetuser
释义 WNetGetUser
语法:
C++
DWORD WNetGetUser(
__in LPCTSTR lpName,
__out LPTSTR lpUserName,
__inout LPDWORD lpnLength
);
WNetGetUser功能
该WNetGetUser函数检索当前的默认用户名,用户名或用于建立网络连接。
参数
lpName [in]
阿为一个恒定的空指针结尾的字符串,或者指定了一个本地设备已被重定向到网络资源,或一个网络资源的连接一直没有重定向本地设备使远程名称。
如果此参数为NULL或空字符串,系统将返回该进程的当前用户名。
lpUserName [out]
阿一个缓冲区,它接收空终止用户名指针。
lpnLength [ in , out ]
一个变量指定lpUserName以字符缓冲区的大小,指针。如果调用失败,因为缓冲区不够大,这个变量包含所需的缓冲区大小。
返回值
如果函数成功,返回值为NO_ERROR。
如果函数失败,返回值是一个系统错误代码,如下列值之一。
返回codeDescription
ERROR_NOT_CONNECTEDThe设备的lpName参数指定不是重定向设备或连接的网络名称。
ERROR_MORE_DATAMore项可提供后续调用。
ERROR_NO_NETWORKThe网络不可用。
ERROR_EXTENDED_ERRORA网络特定的错误。要获取该错误的描述,调用WNetGetLastError功能。
对供应商ERROR_NO_NET_OR_BAD_PATHNone承认有一个连接的本地名称。然而,网络不可用至少一个供应商,其中可能属于该连接。
备注
该WNetGetUser功能并不知道股票的分布式文件系统(DFS)。如果被lpName参数指定的名称是一个本地设备重定向到DFS共享或远程资源,是一个DFS共享的WNetGetUser函数ERROR_NOT_CONNECTED失败。
实例
下面的代码示例演示如何使用WNetGetUser函数来检索与一个重定向的本地设备或远程网络资源相关联的用户名。
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "mpr.lib")
#include
#include
#include
#include
int wmain(int argc, wchar_t * argv[])
{
DWORD dwRetVal;
WCHAR UserName[MAX_PATH];
DWORD dwNameLength = MAX_PATH;
if (argc != 2) {
wprintf
(L"Usage: %s [Redirected-LocalDevice or Network-Resource-Remote-name\\n",
argv[0]);
exit(1);
}
wprintf(L"Calling WNetGetUser with Network-Resource = %s\\n", argv[1]);
dwRetVal = WNetGetUser(argv[1], UserName, &dwNameLength);
//
// If the call succeeds, print the user information.
//
if (dwRetVal == NO_ERROR) {
wprintf(L"WNetGetUser returned success\\n");
wprintf(L"\\tUsername=%s NameLength=%d\\n", &UserName, dwNameLength);
exit(0);
}
else {
wprintf(L"WNetGetUser failed with error: %u\\n", dwRetVal);
exit(1);
}
}

要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinnetwk.h
LibraryMpr.lib
DLLMpr.dll
Unicode和ANSI namesWNetGetUserW(Unicode)和WNetGetUserA(ANSI)的
参见
Windows网络(WNet)概述
Windows网络函数
检索用户名
WNetGetConnection
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月6日
==英文原文==WNetGetUser Function
The WNetGetUser function retrieves the current default user name, or the user name used to establish a network connection.
Syntax
C++
DWORD WNetGetUser(
__in LPCTSTR lpName,
__out LPTSTR lpUserName,
__inout LPDWORD lpnLength
);
Parameters
lpName [in]
A pointer to a constant null-terminated string that specifies either the name of a local device that has been redirected to a network resource, or the remote name of a network resource to which a connection has been made without redirecting a local device.
If this parameter is NULL or the empty string, the system returns the name of the current user for the process.
lpUserName [out]
A pointer to a buffer that receives the null-terminated user name.
lpnLength [in, out]
A pointer to a variable that specifies the size of the lpUserName buffer, in characters. If the call fails because the buffer is not large enough, this variable contains the required buffer size.
Return Value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is a system error code , such as one of the following values.
Return codeDescription
ERROR_NOT_CONNECTEDThe device specified by the lpName parameter is not a redirected device or a connected network name.
ERROR_MORE_DATAMore entries are available with subsequent calls.
ERROR_NO_NETWORKThe network is unavailable.
ERROR_EXTENDED_ERRORA network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function.
ERROR_NO_NET_OR_BAD_PATHNone of the providers recognize the local name as having a connection. However, the network is not available for at least one provider to whom the connection may belong.

Remarks
The WNetGetUser function is not aware of shares on the Distributed File System (DFS). If the name specified by the lpName parameter is a local device redirected to a DFS share or a remote resource that represents a DFS share, the WNetGetUser function fails with ERROR_NOT_CONNECTED.
Examples
The following code sample illustrates how to use the WNetGetUser function to retrieve the name of the user associated with a redirected local device or a remote network resource.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "mpr.lib")
#include
#include
#include
#include
int wmain(int argc, wchar_t * argv[])
{
DWORD dwRetVal;
WCHAR UserName[MAX_PATH];
DWORD dwNameLength = MAX_PATH;
if (argc != 2) {
wprintf
(L"Usage: %s [Redirected-LocalDevice or Network-Resource-Remote-name\\n",
argv[0]);
exit(1);
}
wprintf(L"Calling WNetGetUser with Network-Resource = %s\\n", argv[1]);
dwRetVal = WNetGetUser(argv[1], UserName, &dwNameLength);
//
// If the call succeeds, print the user information.
//
if (dwRetVal == NO_ERROR) {
wprintf(L"WNetGetUser returned success\\n");
wprintf(L"\\tUsername=%s NameLength=%d\\n", &UserName, dwNameLength);
exit(0);
}
else {
wprintf(L"WNetGetUser failed with error: %u\\n", dwRetVal);
exit(1);
}
}

Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinnetwk.h
LibraryMpr.lib
DLLMpr.dll
Unicode and ANSI namesWNetGetUserW (Unicode) and WNetGetUserA (ANSI)
See Also
Windows Networking (WNet) Overview
Windows Networking Functions
Retrieving the User Name
WNetGetConnection
Send comments about this topic to Microsoft
Build date: 8/6/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa385476(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:25:30