获取登录过的全部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
}
}
}