if(GetSystemDirectory(SysPath, sizeof(SysPath)) == 0) 内容来自www.paper51.com { http://www.paper51.com // AfxMessageBox("GetSystem32 Path Failed"); copyright paper51.com } http://www.paper51.com // 获取本程序当前路径和名字 内容来自论文无忧网 www.paper51.com if(GetModuleFileName(NULL, FilePathAndName, sizeof(FilePathAndName)) == 0) http://www.paper51.com { 内容来自论文无忧网 www.paper51.com // AfxMessageBox("GetCurrent File Path And Name Failed"); paper51.com } http://www.paper51.com // 拷贝本程序到System32 copyright paper51.com LPSTR lpFileNewPathAndName; http://www.paper51.com
lpFileNewPathAndName= lstrcat(SysPath, "\\"); copyright paper51.com
lpFileNewPathAndName= lstrcat(lpFileNewPathAndName, lpFileName); paper51.com // 判断System32下是否存在本文件 内容来自论文无忧网 www.paper51.com if(PathFileExists(lpFileNewPathAndName) == FALSE) 内容来自www.paper51.com
{ 内容来自www.paper51.com //如果不存在就拷贝 http://www.paper51.com if(CopyFile(FilePathAndName, lpFileNewPathAndName, FALSE) == 0) http://www.paper51.com { paper51.com
// AfxMessageBox("CopyFile To System32 Failed"); copyright paper51.com } paper51.com } copyright paper51.com // 写开机自启动的注册表键值 内容来自论文无忧网 www.paper51.com LPCTSTR lpRegSubPath= "Software\\Microsoft\\Windows\\CurrentVersion\\Run" ; copyright paper51.com HKEY hKey; 内容来自论文无忧网 www.paper51.com LONG lRet =RegOpenKeyEx( HKEY_LOCAL_MACHINE,lpRegSubPath, 0, http://www.paper51.com KEY_WRITE, &hKey); copyright paper51.com if(lRet ==ERROR_SUCCESS) http://www.paper51.com { 内容来自www.paper51.com DWORDdwRet = strlen(lpFileNewPathAndName); 内容来自论文无忧网 www.paper51.com lRet= RegSetValueEx( hKey,lpRegKeyName, 0, REG_SZ, paper51.com (BYTE *)lpFileNewPathAndName,dwRet); paper51.com RegCloseKey(hKey); paper51.com if(lRet!= ERROR_SUCCESS) 内容来自www.paper51.com
{ 内容来自论文无忧网 www.paper51.com // AfxMessageBox("AutorunFailed"); http://www.paper51.com } 内容来自www.paper51.com } 内容来自论文无忧网 www.paper51.com …………………(省略) http://www.paper51.com
----------------------------------------------------------------------------------------------------------------- 内容来自论文无忧网 www.paper51.com 二、初始化本机IP地址等网络参数。首先,随机产生网络参数信息。然后获取网卡的信息以填充特定结构体,以便配置网络参数。接着,在填充好了相关结构体后,通过写注册表的方式,把新的网络参数写入注册表,最后再调用未公布的API用以通告网络参数的更改,以使新配置的网络参数立即生效。本部分的主要代码如下: copyright paper51.com ----------------------------------------------------------------------------------------------------------------- http://www.paper51.com
…………………(省略) 内容来自www.paper51.com if (GetAdaptInfo()) // 获取网卡信息填充m_pAdapterInfo指向的结构体 内容来自www.paper51.com { 内容来自论文无忧网 www.paper51.com if(SetIP(clientip,clientmask,clientgate)) paper51.com { 内容来自www.paper51.com
returnTRUE; // 设置IP成功则返回TRUE paper51.com
} copyright paper51.com } paper51.com …………………(省略) 内容来自www.paper51.com if (!SetIPToReg(pAdapterName,pIPAddress, pSubnetMask, pDefaultGateway)) 内容来自论文无忧网 www.paper51.com
{ copyright paper51.com
returnFALSE; http://www.paper51.com } 内容来自www.paper51.com if (!NotifyIPChange(nIndex,pAdapterName, pIPAddress, pSubnetMask)) copyright paper51.com { 内容来自论文无忧网 www.paper51.com returnFALSE; 内容来自www.paper51.com
} http://www.paper51.com …………………(省略) copyright paper51.com ----------------------------------------------------------------------------------------------------------------- 内容来自论文无忧网 www.paper51.com
|