如何获取这台电脑上登陆过的全部QQ号,

获取登录过的全部QQ号码

QQ会在我的文档创建一个文件夹里面有登录过的所有QQ的信息,文件夹的名称就是QQ号码,这个程序就是获取文件夹名称。
代码如下

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;


namespace GetLogionedNumber
{
    internal class Program
    {

        [DllImport("Wtsapi32.dll")]
        protected static extern void WTSFreeMemory(IntPtr pointer);

        [DllImport("Wtsapi32.dll")]
        protected static extern bool WTSQuerySessionInformation(IntPtr hServer, int sessionId, WTSInfoClass wtsInfoClass, out IntPtr ppBuffer, out uint pBytesReturned);


        static void Main(string[] args)
        {
            string userName = GetCurrentUserName().Split('\\')[1];//获取当前登录账户的用户名
            string path1 = @"C:\Users\" + userName + "\\Documents\\Tencent Files";//路径拼接

            GetLogionedQQNumber(path1);//根据路径获取到这个文件夹下文件夹的名称

            Console.ReadKey();//后面这三行看不懂,但是删了会报错
            Console.ReadKey();//
            Console.ReadKey();
        }

		//获取文件夹名称
		//path 路径
        private static void GetLogionedQQNumber(string path)
        {
            string[] dirs = Directory.GetDirectories(path);
            List<string> list = new List<string>();
            foreach (string item in dirs)
            {
                list.Add(Path.GetFileNameWithoutExtension(item));
            }
            Console.WriteLine("在这台电脑上登录过的QQ号有" + (list.Count - 1) + "个,分别为:");
            for (int i = 0; i < list.Count - 1; i++)
            {
                Console.WriteLine(list[i]);
            }
        }


        /// <summary>
        /// 获取当前登录用户(可用于管理员身份运行)
        /// </summary>
        /// <returns></returns>
        private static string GetCurrentUserName()
        {
            IntPtr buffer;
            uint strLen;
            int cur_session = -1;
            var username = "SYSTEM"; // assume SYSTEM as this will return "\0" below
            if (WTSQuerySessionInformation(IntPtr.Zero, cur_session, WTSInfoClass.WTSUserName, out buffer, out strLen) && strLen > 1)
            {
                username = Marshal.PtrToStringAnsi(buffer); // don't need length as these are null terminated strings
                WTSFreeMemory(buffer);
                if (WTSQuerySessionInformation(IntPtr.Zero, cur_session, WTSInfoClass.WTSDomainName, out buffer, out strLen) && strLen > 1)
                {
                    username = Marshal.PtrToStringAnsi(buffer) + "\\" + username; // prepend domain name
                    WTSFreeMemory(buffer);
                }
            }

            return username;
        }


        public enum WTSInfoClass
        {
            WTSInitialProgram,
            WTSApplicationName,
            WTSWorkingDirectory,
            WTSOEMId,
            WTSSessionId,
            WTSUserName,
            WTSWinStationName,
            WTSDomainName,
            WTSConnectState,
            WTSClientBuildNumber,
            WTSClientName,
            WTSClientDirectory,
            WTSClientProductId,
            WTSClientHardwareId,
            WTSClientAddress,
            WTSClientDisplay,
            WTSClientProtocolType,
            WTSIdleTime,
            WTSLogonTime,
            WTSIncomingBytes,
            WTSOutgoingBytes,
            WTSIncomingFrames,
            WTSOutgoingFrames,
            WTSClientInfo,
            WTSSessionInfo
        }
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值