歌舞程序

导航

使用C#在XP系统上获取当前使用的SSID

using System;
using System.Collections.Generic;
using System.Text;


using System.Management;//System.Management.dll

namespace test_get_current_connect_console
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI","SELECT * FROM MSNdis_80211_ServiceSetIdentifier where active = true");

            try
            {
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("MSNdis_80211_ServiceSetIdentifier instance");
                    Console.WriteLine("-----------------------------------");

                    if (queryObj["Ndis80211SsId"] == null)
                        Console.WriteLine("Ndis80211SsId: {0}", queryObj["Ndis80211SsId"]);
                    else
                    {
                        Byte[] arrNdis80211SsId = (Byte[])(queryObj["Ndis80211SsId"]);
                        Console.Write("Ndis80211SsId:");
                        foreach (Byte arrValue in arrNdis80211SsId)
                        {
                            if (i++ > 3)
                            {
                                if (arrValue > 0)
                                {
                                    Console.Write("{0}", (char)arrValue);
                                }
                            }
                        }
                        Console.WriteLine("");
                        break;
                    }
                }//end fereach
                Console.ReadLine();
            }
            catch
            {
                Console.WriteLine("Error");
                Console.ReadLine();
            }
        }// end Main
    }//end class Program
}

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hqq01025/archive/2009/02/14/3890226.aspx

posted on 2009-08-28 20:14  歌舞程序  阅读(595)  评论(0编辑  收藏  举报