运行界面如图
QQLogin.cs 文件代码为
代码打包下载:
http://files.cnblogs.com/9who/QQ自动登录器.rar
namespace QQLogin
{
public partial class QQLogin : Form
{
/// <summary>
/// QQ帐号信息
/// </summary>
public List<QQAccount> QQAccountList = new List<QQAccount>();
/// <summary>
/// QQ信息存储文件的路径
/// </summary>
private string qqInfoPath = Environment.SystemDirectory + Constants.STR_QQ_DATE_FILE_NAME;
public QQLogin()
{
InitializeComponent();
}
/// <summary>
/// 加载窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void QQLogin_Load(object sender, EventArgs e)
{
QQAccountList.Clear();
initQQAccountList();
initListView();
}
/// <summary>
/// 关闭程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void QQLogin_FormClosing(object sender, FormClosingEventArgs e)
{
//保存当前listView中的QQ信息
QQFileAccess.Set(qqInfoPath, QQAccountList);
}
/// <summary>
/// 读取QQ信息,初始化QQAccountList
/// </summary>
private void initQQAccountList()
{
if (!File.Exists(qqInfoPath))
{
//从指定路径创建QQ信息
File.Create(qqInfoPath).Close();
XmlTextWriter xmlWriter = new XmlTextWriter(qqInfoPath, Encoding.UTF8);
xmlWriter.WriteStartDocument();
xmlWriter.Close();
QQAccountList = new List<QQAccount>();
}
else
{
//从指定路径读取QQ信息
QQAccountList = QQFileAccess.Get(qqInfoPath);
}
}
/// <summary>
/// 初始化ListView显示
/// </summary>
private void initListView()
{
QQInfoListView.Items.Clear();
if (null == QQAccountList)
{
QQAccountList = new List<QQAccount>();
return;
}
//循环添加所有QQ信息
foreach (QQAccount qqAcnt in QQAccountList)
{
string name = qqAcnt.Name;
//有昵称时显示昵称,否则显示QQ号码
if (name == null || name.Length == 0)
{
name = qqAcnt.Number;
}
ListViewItem qqItem = new ListViewItem(name);
qqItem.SubItems.Add(qqAcnt.LastLoginDate);
qqItem.Checked = qqAcnt.IsChecked;
//根据是否隐身,显示不同的图标
if (qqAcnt.IsStealth)
{
qqItem.ImageIndex = 0;
}
else
{
qqItem.ImageIndex = 1;
}
QQInfoListView.Items.Add(qqItem);
}
}
/// <summary>
/// 启动选定帐号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStrtAcnt_Click(object sender, EventArgs e)
{
if (QQInfoListView.Items.Count == 0)
{
return;
}
//从注册表获取QQ主程序的路径
string qqPath = QQLoginRegistry.GetQQRegistryValue(Constants.STR_QQ_REG_KEY_PRGRM_PATH);
//未设置QQ路径错误提示
if (string.IsNullOrEmpty(qqPath))
{
MessageBox.Show(Constants.STR_QQ_WARN_PRGRM_PATH_NULL);
return;
}
//路径设置选择程序不是QQ,提示错误
if (!qqPath.ToLower().EndsWith("qq.exe"))
{
MessageBox.Show(Constants.STR_QQ_WARN_PRGRM_PATH_ERR);
return;
}
//循环登录所有选择的QQ帐号
foreach (ListViewItem qqItem in QQInfoListView.Items)
{
QQAccount qqAcnt = QQAccountList[qqItem.Index];
if (qqItem.Checked)
{
qqAcnt.IsChecked = true;
string strAcntNum = qqAcnt.Number;
string strPsw = qqAcnt.Psword;
bool blAcntSts = qqAcnt.IsStealth;
qqAcnt.LastLoginDate = DateTime.Now.ToLongDateString() + DateTime.Now.ToShortTimeString();
//通过指定参数启动QQ
Process.Start(qqPath, "/START QQUIN:" + strAcntNum + " PWDHASH:" + strPsw + " /STAT:" + (blAcntSts ? "40" : "41"));
}
else
{
qqAcnt.IsChecked = false;
}
}
}
/// <summary>
/// 创建快捷登录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCreateLnk_Click(object sender, EventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
//从注册表获取QQ主程序的路径
string qqPath = QQLoginRegistry.GetQQRegistryValue(Constants.STR_QQ_REG_KEY_PRGRM_PATH);
//获取当前选择的帐号信息
QQAccount acnt = this.QQAccountList[this.QQInfoListView.FocusedItem.Index];
//创建快捷登录脚本
StreamWriter sw = new StreamWriter("C:\\CreateLink.vbs", false, System.Text.Encoding.GetEncoding("GB2312"));
sw.WriteLine("Set C = CreateObject(\"WScript.Shell\")");
sw.WriteLine("DesktopPath = C.SpecialFolders(\"Desktop\")");
//创建桌面快捷方式,快捷方式以QQ昵称或QQ号码命名
sw.WriteLine("Set link = C.CreateShortcut(DesktopPath & \"\\" + (string.IsNullOrEmpty(acnt.Name) ? acnt.Number : acnt.Name) + ".lnk\")");
sw.WriteLine("link.IconLocation = \"" + qqPath + ",0\"");
//QQ启动参数
string temp = "/START QQUIN:" + acnt.Number + " PWDHASH:" + acnt.Psword + " /STAT:" + (acnt.IsStealth ? "40" : "41");
sw.WriteLine("link.Arguments =\"" + temp + "\"");
sw.WriteLine("link.Description = \"QQ自动登录器 - Aspx1\"");
sw.WriteLine("link.TargetPath = \"" + qqPath + "\"");
sw.WriteLine("link.WindowStyle =0");
sw.WriteLine("link.Save");
sw.WriteLine("Dim oFS");
sw.WriteLine("Set oFS = CreateObject(\"Scripting.FileSystemObject\")");
//删除脚本
sw.WriteLine("oFS.DeleteFile \"c:\\CreateLink.vbs\"");
sw.WriteLine("Set OFS = Nothing");
sw.Close();
//启动进程隐藏执行脚本文件
ProcessStartInfo psi = new ProcessStartInfo("c:\\CreateLink.vbs");
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
MessageBox.Show("成功创建快捷方式.");
}
/// <summary>
/// 启动QQ
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStrtQQ_Click(object sender, EventArgs e)
{
//从注册表获取QQ主程序的路径
string qqPath = QQLoginRegistry.GetQQRegistryValue(Constants.STR_QQ_REG_KEY_PRGRM_PATH);
//未设置QQ路径错误提示
if (string.IsNullOrEmpty(qqPath))
{
MessageBox.Show(Constants.STR_QQ_WARN_PRGRM_PATH_NULL);
return;
}
//路径设置选择程序不是QQ,提示错误
if (!qqPath.ToLower().EndsWith("qq.exe"))
{
MessageBox.Show(Constants.STR_QQ_WARN_PRGRM_PATH_ERR);
return;
}
//启动QQ程序
Process.Start(qqPath);
}
/// <summary>
/// 添加帐号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddAcnt_Click(object sender, EventArgs e)
{
AddAccount addAccount = new AddAccount();
if (addAccount.ShowDialog() == DialogResult.OK)
{
QQAccount acnt = addAccount.GetAddQQInfo();
for (int i = 0; i < QQInfoListView.Items.Count; i++)
{
if (acnt.Number == QQInfoListView.Items[i].Text)
{
MessageBox.Show("号码已存在");
return;
}
}
this.QQAccountList.Add(acnt);
initListView();
//保存QQ信息
QQFileAccess.Set(qqInfoPath, QQAccountList);
}
}
/// <summary>
/// 设置QQ程序路径
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSetting_Click(object sender, EventArgs e)
{
SetPath setQQPath = new SetPath();
setQQPath.ShowDialog();
}
/// <summary>
/// 显示关于窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAbout_Click(object sender, EventArgs e)
{
About a = new About();
a.ShowDialog();
}
/// <summary>
/// 退出程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnExt_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// 修改QQ信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ltvQQInfo_DoubleClick(object sender, EventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
//获取要修改的QQ号码
string qqAcntNum = QQAccountList[this.QQInfoListView.FocusedItem.Index].Number;
//获取要修改的QQ昵称
string qqName = QQAccountList[this.QQInfoListView.FocusedItem.Index].Name;
AddAccount chgQQAcntInfo = new AddAccount();
chgQQAcntInfo.initChangeStatus(qqName,qqAcntNum);
if (chgQQAcntInfo.ShowDialog() == DialogResult.OK)
{
QQAccount acnt = this.QQAccountList[this.QQInfoListView.FocusedItem.Index];
//删除原有的QQ帐号信息
this.QQAccountList.Remove(acnt);
//添加修改后的信息
this.QQAccountList.Add(chgQQAcntInfo.GetAddQQInfo());
initListView();
//保存QQ信息
QQFileAccess.Set(qqInfoPath, QQAccountList);
}
}
/// <summary>
/// 菜单删除事件,删除选定的QQ信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuDelItem_Click(object sender, EventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
QQAccountList.RemoveAt(QQInfoListView.FocusedItem.Index);
initListView();
}
/// <summary>
/// 菜单隐身事件,设置QQ隐身或上线
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuShowItem_Click(object sender, EventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
int intSelectItem = this.QQInfoListView.FocusedItem.Index;
this.QQAccountList[intSelectItem].IsStealth = !this.QQAccountList[intSelectItem].IsStealth;
initListView();
}
/// <summary>
/// 选中行事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ltvQQInfo_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
int intSelectItem = this.QQInfoListView.FocusedItem.Index;
this.QQAccountList[intSelectItem].IsChecked = !this.QQAccountList[intSelectItem].IsChecked;
initListView();
//设置选中行的样式
this.QQInfoListView.Items[intSelectItem].Focused = true;
this.QQInfoListView.Items[intSelectItem].BackColor = Color.Blue;
this.QQInfoListView.Items[intSelectItem].ForeColor = Color.White;
}
}