Windows XP 中从 wlanapi.dll 进行 WlanConnect 失败

发布于 2024-12-18 13:06:38 字数 783 浏览 0 评论 0原文

我正在创建一个能够自动连接到无线网络的程序。为此,我使用一个名为 ManagedWifi 的库,它使用库“wlanapi.dll”。当我尝试在 Windows Vista 上使用该代码时,一切正常,但当我在 Windows XP 上使用它时,它会失败。我检查过它是否安装了 Service Pack 3,并且“wlanapi.dll”位于 Windows/system32 中。问题是当 ManagedWifi 调用此方法时:

[DllImport("wlanapi.dll")]
    public static extern int WlanConnect(
        [In] IntPtr clientHandle,
        [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
        [In] ref WlanConnectionParameters connectionParameters,
        IntPtr pReserved);

它会抛出错误 System.ComponentModel.Win32Exception:找不到元素。但是,如果该库正确位于 system32 中,为什么会抛出此错误?为什么只在 Windows XP 中而不在 Vista 中?

非常感谢大家

编辑:我已经检查了 Vista 和 XP 这两个文件版本,我发现它们是不同的(XP:5.1,Vista:6.0),但我已将 Vista 的版本复制到XP和我还是有同样的问题

I am creating a program which will be able to connect automatically to a wireless network. For doing that, I am using a library called ManagedWifi, which uses the library "wlanapi.dll". When I try to use the code on Windows Vista, everything is fine, but when I use it on Windows XP it fails. I have checked that it has Service Pack 3 installed, and "wlanapi.dll" is located in Windows/system32. The problem is when ManagedWifi calls this method:

[DllImport("wlanapi.dll")]
    public static extern int WlanConnect(
        [In] IntPtr clientHandle,
        [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
        [In] ref WlanConnectionParameters connectionParameters,
        IntPtr pReserved);

It throws an error System.ComponentModel.Win32Exception: Element not found. But, if the library is correctly located in system32, why does it throw this error? And why only in Windows XP and not in Vista?

Thank you very much to everyone

EDIT: I have checked boith file versions, Vista and XP, and I've seen they are different (XP: 5.1, Vista: 6.0) but I have copied Vista's version to XP and I still have the same problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守护在此方 2024-12-25 13:06:38

已解决

问题是,当网络是 adhoc 网络时,Windows XP 会在名称中添加“-adhoc”后缀。当我尝试连接它时,它没有找到“xxx”网络

Solved

The problem is that Windows XP, when the network is an adhoc network, adds the "-adhoc" sufix to the name. When I was trying to connect to it, it didn't find the "xxx" network

書生途 2024-12-25 13:06:38

使用:

[DllImport("wlanapi.dll")]
    internal static extern int WlanSetProfile(
        [In] IntPtr hClientHandle,
        [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
        [In] WlanProfileFlags dwFlags,
        [In, MarshalAs(UnmanagedType.LPWStr)] string strProfileXml,
        [In, MarshalAs(UnmanagedType.LPWStr)] string strAllUserProfileSecurity,
        [In] bool bOverwrite,
        [In, Out] IntPtr pReserved,
        [Out] out WlanReasonCode dwReasonCode
    ); 

您必须首先创建配置文件,未找到元素表示您尝试连接的配置文件不可用

Using :

[DllImport("wlanapi.dll")]
    internal static extern int WlanSetProfile(
        [In] IntPtr hClientHandle,
        [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
        [In] WlanProfileFlags dwFlags,
        [In, MarshalAs(UnmanagedType.LPWStr)] string strProfileXml,
        [In, MarshalAs(UnmanagedType.LPWStr)] string strAllUserProfileSecurity,
        [In] bool bOverwrite,
        [In, Out] IntPtr pReserved,
        [Out] out WlanReasonCode dwReasonCode
    ); 

You have to create the profile first, Element not found says that the profile which you are trying to connect is not available

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文