• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphi中WNetAddConnection2的使用

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1楼:MSDN中例子:
Adding a Network Connection
Windows NT/Windows 2000

To make a connection to a network resource described by a NETRESOURCE structure, an application can call the WNetAddConnection2, the WNetAddConnection3, or the WNetUseConnection function. The following example demonstrates use of the WNetAddConnection2 function.

The code sample calls the WNetAddConnection2 function, specifying that the system should update the user's profile with the information, creating a "remembered" or persistent connection. The sample calls an application-defined error handler to process errors, and the TextOut function for printing.

DWORD dwResult;
NETRESOURCE nr;
//
// Call the WNetAddConnection2 function to make the connection,
// specifying a persistent connection.
//
dwResult = WNetAddConnection2(&nr, // NETRESOURCE from enumeration
(LPSTR) NULL, // no password
(LPSTR) NULL, // logged-in user
CONNECT_UPDATE_PROFILE); // update profile with connect information

// Process errors.
// The local device is already connected to a network resource.
//
if (dwResult == ERROR_ALREADY_ASSIGNED)
{
TextOut(hdc, 10, 10, "Already connected to specified resource.", 40);
return FALSE;
}

// An entry for the local device already exists in the user profile.
//
else if (dwResult == ERROR_DEVICE_ALREADY_REMEMBERED)
{
TextOut(hdc, 10, 10,
"Attempted reassignment of remembered device.", 44);
return FALSE;
}
else if(dwResult != NO_ERROR)
{
//
// Call an application-defined error handler.
//
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetAddConnection2");
return FALSE;
}

//
// Otherwise, report a successful connection.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
理解 Delphi 的类(十) - 深入方法[17] - 提前声明发布时间:2022-07-18
下一篇:
Delphi保存写字板程序,并进行打印发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap