怎样才能获得本地网上的用户名,组,或计算机名。

luoqing 2002-07-18 05:01:02
怎样才能获得本地网上的用户名,组,或计算机名。
...全文
62 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
junwhj 2002-07-19
http://www.csdn.net/expert/topic/784/784649.xml?temp=.3798334
回复
Laney 2002-07-19
用winsock对象,
winsock1.localhostname获得用户计算机名
winsock1.localip获得本机ip
回复
hudawq 2002-07-19
用WshNetwork.username 和WshNetwork.ComputerName,wsh.UserDomain也可以完成,其中WshNetwork是Window script host 运行库中的类
回复
FUXINZHU 2002-07-19
用API GETUSER函数取得用户名
GETCOMPUTERNAME函数取得计算机名
回复
螺丝刀2000 2002-07-19
Up
回复
mfkzj 2002-07-19
WNetOpenEnum
WNetEnumResource
下面式一段VC代码 你用API改一下就OK了
HANDLE hEnum = 0;
DWORD dwScope = RESOURCE_GLOBALNET ;
if( dwFlags_p & CONNECTED ) dwScope = RESOURCE_CONNECTED ;
else if( dwFlags_p & REMEMBERED ) dwScope = RESOURCE_REMEMBERED ;
// else GLOBALNET ...

DWORD dwType = RESOURCETYPE_ANY ;
if( dwFlags_p & TYPE_DISK ) dwType = RESOURCETYPE_DISK ;
else if( dwFlags_p & TYPE_PRINT ) dwType = RESOURCETYPE_PRINT ;
// else TYPE_ANY ...

DWORD dwResult = WNetOpenEnum(
dwScope, // scope of enumeration
dwType, // resource types to list
0, // enumerate all resources
lpNetRC_p, // pointer to resource structure (NULL at first time)
&hEnum // handle to resource
) ;

if( dwResult != NO_ERROR )
return NetError(dwResult, TEXT("WNetOpenEnum"));

DWORD dwBuffer = 16384 ; // 16K is reasonable size
DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
LPNETRESOURCE lpnrLocal = 0;

BOOL bRet = TRUE;

try {
do {
// first allocate buffer for NETRESOURCE structures ...
lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ;

dwResult = WNetEnumResource(
hEnum, // resource-handle
&dwEntries,
lpnrLocal,
&dwBuffer
) ;

if( dwResult == NO_ERROR ) {
for( register DWORD i = 0 ; i < dwEntries ; i++ ) {
::AfxMessageBox(lpnrLocal[i].lpRemoteName);
if( ! OnHitResource( lpnrLocal[i] ) ) {
TRACE0("CNetwork::Enumerate(): OnHitResource() breaks enumeration\n");
throw CNetworkBreak(FALSE) ;
}
//判断读出来的数据是否是网络上的网络组
//如果是网络组的话就将该网络组的信息为标准循环查询
if( RESOURCEUSAGE_CONTAINER ==
(lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER) &&
lpnrLocal[i].dwDisplayType != RESOURCEDISPLAYTYPE_SERVER )
if( !Enumerate( &lpnrLocal[i], dwFlags_p ) ) {
TRACE0( "CNetwork::Enumerate(): recursiv call failed\n" );
throw CNetworkBreak(FALSE);
}

}
} else if( dwResult != ERROR_NO_MORE_ITEMS ) {
throw CNetworkError(NetError(dwResult, TEXT("WNetEnumResource")));
}
} while( dwResult != ERROR_NO_MORE_ITEMS );
} catch( CNetworkError err ) {
bRet = err.m_bRet;
}

if( lpnrLocal )
GlobalFree((HGLOBAL) lpnrLocal) ;

WNetCloseEnum(hEnum) ;

return bRet;
}
回复
发帖
VB基础类
创建于2007-09-28

7479

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2002-07-18 05:01
社区公告
暂无公告