| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- #pragma once
- #include "stdafx.h"
- #include <tlhelp32.h>
- #include "global.h"
- #define MAX_PATH_LENGTH MAX_PATH
- CRITICAL_SECTION g_csWrDataBase; //写日志和告警数据库操作
- //程序退出事件
- HANDLE g_hRunObject = NULL;
- //客户端数据
- INT g_nClientNum = 0;
- char g_strDirectory[256]={0};
- //DOG
- INT g_nUseTimeLimit = 0; //是否超过使用期限
- //WatchServer
- CHAR g_strWatchServerIP[MAX_EQUIP_IP + 1] = {0};
- CHAR g_strWatchServerPort[MAX_PORT + 1] = {0};
- //Database
- CHAR g_strConnectString[MAX_PATH + 1] = ""; // 数据连接字符串
- CHAR g_strDBType[MAX_SERVER_LENGTH + 1] = ""; // 数据库连接类型(如: SQL SERVER 、Access )
- CHAR g_strAccessFile[MAX_PATH_LENGTH + 1] = ""; // 如果是用Access数据库:Access文件名称
- // 如用其它数据库:为空
- CHAR g_strServerName[MAX_SERVER_LENGTH + 1] = ""; // 数据库服务器名称或IP
- CHAR g_strDataBaseName[MAX_DATABASE_LENGTH + 1] = ""; // 数据库名称
- CHAR g_strUserName[MAX_USER_LENGTH + 1] = ""; // 数据库用户名
- CHAR g_strPassword[MAX_PASSWORD_LENGTH + 1] = ""; // 数据库密码
- //用户信息
- CHAR g_strLoginUserID[MAX_USER_LENGTH + 1] = ""; // 当前使用该软件的用户名
- CHAR g_strLoginPwd[MAX_PASSWORD_LENGTH + 1] = ""; // 当前使用该软件的密码
- CHAR g_strDefaultUserID[MAX_USER_LENGTH + 1] = {0};
- CHAR g_strDefaultUserPwd[MAX_PASSWORD_LENGTH + 1] = {0};
- //系统设置
- BOOL g_bEnableTimeLimited = FALSE; // TRUE:时间限制 FALSE:正式版
- INT g_iAutoRunSystem = 0; // 是否开机自启动该系统
- CHAR g_strLanguage[MAX_LANG_LENGTH + 1]={0}; // 默认语言
- //日志
- //CHAR g_strDirectory[MAX_PATH_LENGTH + 1]; // 软件所在路径
- CHAR g_strAppName[MAX_PATH_LENGTH + 1] = {0}; // 软件名称
- CHAR g_strSummaryLogPath[MAX_PATH_LENGTH + 1] = {0}; // 日志存放目录
- //环境参数配置
- CHAR g_strSNCode[MAX_PATH];
- INT g_nLevelWav = 0; // 语音通知级别
- INT g_nLevelSms = 0; // 发送短信级别
- INT g_nLevelEmail = 0; // 发送Email级别
- INT g_nLevelDevInterrupt = 0; // 通讯中断级别
- INT g_nLevelDlg = 0; // 本地报警提示框级别
- INT g_nLevelLocalWav = 0; // 本地声音提示级别
- INT g_nDBRecordDate = 0; // 数据库记录时间
- //Sms
- INT g_nSendSms = 0; // 是否启动短信报警功能
- CHAR g_strSmsComPort[MAX_TEL_LENGTH + 1] = {0}; // 短信猫端口
- INT g_nSmsRate = 0; // 串口波特率
- INT g_nSmsDataBit = 8; // 数据位
- INT g_nSmsStopBit = 1; // 停止位
- INT g_nSmsParity = 0; // 检验位
- INT g_nSmsInterval = 100; // 间隔时间
- INT g_nSmsLanguageTrans = 0; // 是否需要繁简转换
- INT g_nSmsMaxChar = 70; // 短信猫支持最大字符个数
- INT g_nSmsMakeCall = 0; // 发送短信后,是否拔打电话提醒 本来是1,chn modify
- CHAR g_strSmsSMSC[MAX_TEL_LENGTH + 1] = {0}; // smsc号码
- INT g_nSmsTimOut = 0; // 短信发送超时
- INT g_nSmsCallTimes = 0;
- //Email
- INT g_nSendEmail = 0; // 是否启动Email报警功能
- CHAR g_strEmailSMTPSrv[MAX_MAILSERVER_LENGTH]={0}; // SMTPServer地址
- INT g_nEmailSMTPPort = 0; // SMTP端口
- INT g_nEmailIsNeed = 0; // 是否需要身份验证
- CHAR g_strEmailUserAcc[MAX_USER_LENGTH]={0}; // 用户名
- CHAR g_strEmailUserPwd[MAX_PASSWORD_LENGTH]={0}; // 密码
- INT g_nEmailTimeOut = 0; // 发送邮件超时
- CHAR g_strEmailFromAddr[MAX_MAILTO_LENGTH]={0}; // 发信人Email地址
- CHAR g_strEmailSubject[MAX_EMAIL_LENGTH]={0}; // Email标题
- INT g_nEmailCallTimes = 0;
- //语音通知
- INT g_nSendNotice = 0; // 是否启动语音通知功能
- INT g_nNoticeCardType = 1; // 板卡类型
- CHAR g_strNoticeTelPre[MAX_TEL_LENGTH + 1] = {0}; // 外线前缀
- INT g_nNoticeCallDelay = 0; // 两次呼叫间隔时间
- INT g_nNoticeCallTimes = 0; // 最大的呼叫次数
- //TTS参数配置
- INT g_nTTSType = 5; // TTS格式类型
- // 报警参数设置
- INT g_nAlarmModeIsDlg = 0; // 是否弹出报警提示框
- INT g_nAlarmModeShowDlgTimes = 0; // 提示框显示次数
- INT g_nAlarmModeIsSound = 0; // 是否本地播放报警提示音
- INT g_nAlarmModeSoundNum = 0; // 声音播放次数,0:代表无限播放,直到报警被确认
- //定时发送短信和电话参数配置
- INT g_nTimingEnable = 0;
- INT g_nTimingWeeks = 0;
- INT g_nTimingHours = 0;
- INT g_nTimingMinutes = 0;
- //是否启用Snmp参数配置
- INT g_nSnmpEnable = 0;
- CHAR g_strSnmpObjOid[MAX_OBJ_OID + 1] = {0};
- CHAR g_strSnmpIP[MAX_EQUIP_IP + 1] = {0};
- CHAR g_strSnmpField[MAX_EQUIP_DESC + 1] = {0};
- WORD AsciiToBYTE(BYTE btSrc);
- char ByteToAscii(BYTE btSrc);
- /*字符全转为大写*/
- void ByteToUpper(char *szMsg)
- {
- for (int i=0; i< strlen(szMsg); i++)
- {
- if ((szMsg[i]>='a') && (szMsg[i]<='z'))
- {
- szMsg[i] = szMsg[i] - 32;
- }
- else
- {
- szMsg[i] = szMsg[i];
- }
- }
- }
- WORD AsciiToBYTE(BYTE btSrc)
- {
- WORD chDest = (WORD)btSrc;
- if ((btSrc >= 'A')&&(btSrc <= 'F'))
- {
- chDest = chDest - 'A' + 10;
- }
- else if ((btSrc >= 'a')&&(btSrc <= 'f'))
- {
- chDest = chDest - 'a' + 10;
- }
- else if ((btSrc >= '0')&&(btSrc <= '9'))
- {
- chDest -= '0';
- }
- return chDest;
- }
- char lowercase2uppercase(BYTE btSrc)
- {
- if( btSrc >= 'a' && btSrc <= 'z' )
- {
- return btSrc - 'a' + 'A';
- }
- return btSrc;
- }
- char ByteToAscii(BYTE btSrc)
- {
- char chDest;
- if( btSrc < 10 )
- {
- chDest = (char)(btSrc % 10 + '0');
- chDest = lowercase2uppercase(chDest);
- return chDest;
- }
- else
- {
- chDest = ByteToAscii( btSrc / 10 ) + (char)( btSrc % 10 + '0' );
- chDest = lowercase2uppercase(chDest);
- return chDest;
- }
- }
- int DigitToBinary(WORD wdSource, char* pDes, int iBit)
- {
- char pTmpBuf[17] = {0};
- char chBuffer[17] = {0};
- //wdSource =htonl(wdSource);
- itoa(wdSource, pTmpBuf, 2);
- int iLen = strlen(pTmpBuf) - 1;
- char chValue[17] = {0};
- strcpy(chValue, pTmpBuf);
- for (int i =0; i<=iLen; i++)
- {
- pTmpBuf[i] = chValue[iLen - i];
- }
- for (int k = 0; k<iBit; k++)
- {
-
- if ( 0x00 == pTmpBuf[iBit - k - 1])
- chBuffer[k] = 0x30;
- else
- chBuffer[k] = pTmpBuf[iBit - k - 1];
- }
- memcpy(pDes, chBuffer, iBit);
- return 0;
- }
- int StrUpper(char *pSource, char *pDest)
- {
- int length, i;
- length = strlen(pSource);
- for (i = 0; i < length; i++) {
- if ((pSource[i] >= 'a') && (pSource[i] <= 'z')){
- pDest[i] = _toupper(pSource[i]);
- }
- else
- pDest[i] = pSource[i];
- }
- return 0;
- }
- int StrLower(char *pSource, char *pDest)
- {
- int length, i;
- length = strlen(pSource);
- for (i = 0; i < length; i++) {
- if ((pSource[i] >= 'A') && (pSource[i] <= 'Z')){
- pDest[i] = _tolower(pSource[i]);
- }
- else
- pDest[i] = pSource[i];
- }
- return 0;
- }
- char Hex16(char WillChangeNum[]) //该函数把四位二进制转换成十六进制数
- {
- int i;
- i = (WillChangeNum[3]) + (WillChangeNum[2] * 10) +
- (WillChangeNum[1] * 100) + (WillChangeNum[0] * 1000);
- switch(i)
- {
- case 0:
- return 0;
- case 1:
- return 1;
- case 10:
- return 2;
- case 11:
- return 3;
- case 100:
- return 4;
- case 101:
- return 5;
- case 110:
- return 6;
- case 111:
- return 7;
- case 1000:
- return 8;
- case 1001:
- return 9;
- case 1010:
- return 0x0A;
- case 1011:
- return 0x0B;
- case 1100:
- return 0x0C;
- case 1101:
- return 0x0D;
- case 1110:
- return 0x0E;
- case 1111:
- return 0x0F;
- }
- return -1;
- }
- BYTE TwoByteToByte(BYTE b1, BYTE b2)//两个字符转换为一个字符
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- BYTE b = 0;
- if(b1 >= 'A' && b1 <= 'F')
- b += (b1 - 'A' + 10)*16;
- else if(b1 >= 'a' && b1 <= 'f')
- b += (b1 - 'a' + 10)*16;
- else
- b += (b1 - '0')*16;
- if(b2 >= 'A' && b2 <= 'F')
- b += b2 - 'A' + 10;
- else if(b2 >= 'a' && b2 <= 'f')
- b += b2 - 'a' + 10;
- else
- b += b2 - '0';
- return b;
- }
- void ByteToTwoByte(BYTE b, BYTE b2[])//一个字符转换为两个字符
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- char szBuf[3];
- int nData = b;
- sprintf(szBuf, "%02X", nData);
- memcpy(b2, szBuf, 2);
- }
- int GetSysData()
- {
- CHAR strFile[MAX_FILE_LENGTH + 1] = "";
- CHAR strValue[MAX_VALUE_LENGTH + 1] = "";
- int iPosFile = 0;
- int iLenghtFile = 0;
- ////////////////////////////////////////////////////////////////////////////
- //获取应用名
- //GetModuleFileName(AfxGetApp()->m_hInstance, g_strDirectory, MAX_PATH);
- GetModuleFileName(NULL, g_strDirectory, MAX_PATH);
- iLenghtFile = (int)strlen(g_strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (g_strDirectory[iPosFile] == '\\')
- {
- memset(g_strAppName, 0, sizeof(g_strAppName));
- memcpy(g_strAppName, g_strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
- break;
- }
- }
- iLenghtFile = strlen(g_strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (g_strDirectory[iPosFile] == '\\')
- {
- g_strDirectory[iPosFile] = '\0';
- break;
- }
- }
- wsprintf(strFile, "%s\\set.ini", g_strDirectory);
- //是否自动启动系统
- GetPrivateProfileString("Other", "AutoRunSystem", "", strValue, sizeof(strValue), strFile);
- if (strcmp(strValue, ""))
- g_iAutoRunSystem = atoi(strValue);
- else
- g_iAutoRunSystem = 0;
- if (g_iAutoRunSystem <= 0)
- g_iAutoRunSystem = 0;
- else
- g_iAutoRunSystem = 1;
- //语言
- GetPrivateProfileString("Other", "Language", "", g_strLanguage, sizeof(g_strLanguage), strFile);
- //Database
- GetPrivateProfileString("Database", "DBType", "", g_strDBType, sizeof(g_strDBType), strFile);
- GetPrivateProfileString("Database", "AccessFile", "", g_strAccessFile, sizeof(g_strAccessFile), strFile);
- GetPrivateProfileString("Database", "ServerName", "", g_strServerName, sizeof(g_strServerName), strFile);
- GetPrivateProfileString("Database", "DataBaseName", "", g_strDataBaseName, sizeof(g_strDataBaseName), strFile);
- GetPrivateProfileString("Database", "UserName", "", g_strUserName, sizeof(g_strUserName), strFile);
- GetPrivateProfileString("Database", "Password", "", g_strPassword, sizeof(g_strPassword), strFile);
- //数据库连接串
- if (!_stricmp(g_strDBType, "SQL SERVER"))
- sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s; ",
- g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
- else if (!_stricmp(g_strDBType, "ACCESS97"))
- sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=%s", g_strAccessFile);
- else if (!_stricmp(g_strDBType, "ACCESS2000"))
- sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s", g_strAccessFile);
- else if(!_stricmp(g_strDBType, "PGSQL"))
- sprintf(g_strConnectString, "DRIVER={PostgreSQL ODBC Driver(UNICODE)}; SERVER=%s; port=5432; DATABASE=%s; UID=%s; PWD=%s;",
- g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
- else
- sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s; ",
- g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
- //Common
- g_nLevelWav = GetPrivateProfileInt("Common", "LevelWav", 3, strFile);
- g_nLevelSms = GetPrivateProfileInt("Common", "LevelSms", 3, strFile);
- g_nLevelEmail = GetPrivateProfileInt("Common", "LevelEmail", 3, strFile);
- g_nLevelDevInterrupt = GetPrivateProfileInt("Common", "LevelDevInterrupt", 8, strFile);
- g_nLevelDlg = GetPrivateProfileInt("Common", "LevelDlg", 1, strFile);
- g_nLevelLocalWav = GetPrivateProfileInt("Common", "LevelLocalWav", 1, strFile);
- g_nDBRecordDate = GetPrivateProfileInt("Common", "DbRecordDate", 365, strFile);
- //Email
- g_nSendEmail = GetPrivateProfileInt("Email", "SendEmail", 0, strFile);
- GetPrivateProfileString("Email", "SMTPServer", "", g_strEmailSMTPSrv, sizeof(g_strEmailSMTPSrv), strFile);
- g_nEmailSMTPPort = GetPrivateProfileInt("Email", "SMTPPort", 25, strFile);
- g_nEmailIsNeed = GetPrivateProfileInt("Email", "IsNeed", 1, strFile);
- GetPrivateProfileString("Email", "UserAcc", "", g_strEmailUserAcc, sizeof(g_strEmailUserAcc), strFile);
- GetPrivateProfileString("Email", "UserPwd", "", g_strEmailUserPwd, sizeof(g_strEmailUserPwd), strFile);
- GetPrivateProfileString("Email", "MailFrom", "", g_strEmailFromAddr, sizeof(g_strEmailFromAddr), strFile);
- g_nEmailTimeOut = GetPrivateProfileInt("Email", "TimeOut", 60, strFile);
- GetPrivateProfileString("Email", "Subject", "", g_strEmailSubject, sizeof(g_strEmailSubject), strFile);
- g_nEmailCallTimes = GetPrivateProfileInt("Email", "ReCallTimes", 2, strFile);
- //Sms
- g_nSendSms = GetPrivateProfileInt("Sms", "SendSms", 0, strFile);
- GetPrivateProfileString("Sms", "Port", "", g_strSmsComPort, sizeof(g_strSmsComPort), strFile);
- g_nSmsRate = GetPrivateProfileInt("Sms", "Rate", 115200, strFile);
- g_nSmsDataBit = GetPrivateProfileInt("Sms", "DataBit", 8, strFile);
- g_nSmsStopBit = GetPrivateProfileInt("Sms", "StopBit", 1, strFile);
- g_nSmsParity = GetPrivateProfileInt("Sms", "Parity", 0, strFile);
- g_nSmsInterval = GetPrivateProfileInt("Sms", "Interval", 0, strFile);
- g_nSmsLanguageTrans = GetPrivateProfileInt("Sms", "LanguageTrans", 0, strFile);
- g_nSmsMaxChar = GetPrivateProfileInt("Sms", "MaxChar", 0, strFile);
- g_nSmsMakeCall = GetPrivateProfileInt("Sms", "MakeCall", 0, strFile);
- GetPrivateProfileString("Sms", "SMSC", "", g_strSmsSMSC, sizeof(g_strSmsSMSC), strFile);
- g_nSmsTimOut = GetPrivateProfileInt("Sms", "TimeOut", 60, strFile);
- g_nSmsCallTimes = GetPrivateProfileInt("Sms", "ReCallTimes", 2, strFile);
- //Voice
- g_nSendNotice = GetPrivateProfileInt("Voice", "SendNotice", 0, strFile);
- g_nNoticeCardType = GetPrivateProfileInt("Voice", "CardType", 0, strFile);
- GetPrivateProfileString("Voice", "PreTel", "", g_strNoticeTelPre, sizeof(g_strNoticeTelPre), strFile);
- g_nNoticeCallDelay = GetPrivateProfileInt("Voice", "CallRelay", 60, strFile);
- g_nNoticeCallTimes = GetPrivateProfileInt("Voice", "ReCallTimes", 2, strFile);
- //TTS
- //AlarmMode
- g_nAlarmModeIsDlg = GetPrivateProfileInt("AlarmMode", "Dlg", 0, strFile);
- g_nAlarmModeShowDlgTimes = GetPrivateProfileInt("AlarmMode", "ShowTime", 1, strFile);
- g_nAlarmModeIsSound = GetPrivateProfileInt("AlarmMode", "Sound", 0, strFile);
- g_nAlarmModeSoundNum = GetPrivateProfileInt("AlarmMode", "PlayNum", 1, strFile);
- GetPrivateProfileString("Other", "SummaryLog", "", g_strSummaryLogPath, sizeof(g_strSummaryLogPath), strFile);
- //定时发送短信和电话参数配置
- g_nTimingEnable = GetPrivateProfileInt("Timing", "Enable", 0, strFile);
- g_nTimingWeeks = GetPrivateProfileInt("Timing", "Weeks", 0, strFile);
- g_nTimingHours = GetPrivateProfileInt("Timing", "Hours", 0, strFile);
- g_nTimingMinutes = GetPrivateProfileInt("Timing", "Minutes", 0, strFile);
- g_nSnmpEnable = GetPrivateProfileInt("Snmp", "Enable", 0, strFile);
- GetPrivateProfileString("Snmp", "ObjOid", "", g_strSnmpObjOid, sizeof(g_strSnmpObjOid), strFile);
- GetPrivateProfileString("Snmp", "IP", "", g_strSnmpIP, sizeof(g_strSnmpIP), strFile);
- GetPrivateProfileString("Snmp", "Field", "", g_strSnmpField, sizeof(g_strSnmpField), strFile);
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- //增加自动启动注册表项
- #if 0
- wsprintf(strFile, "%s\\%s", g_strDirectory, g_strAppName);
- AddAutoSysRun(strFile, g_iAutoRunSystem);
- #endif
- return 0;
- }
- //软件时间限制代码
- INT ProgramEncrypt(HWND hWnd)
- {
- SYSTEMTIME systemtime;
- HKEY hKey = NULL;
- CHAR strKeyName[50] = "";
- CHAR strFirstDate[20] = "";
- CHAR strMaxDate[20] = "";
- CHAR strMinDate[20] = "";
- CHAR strNowDate[20] = "";
- DWORD dwErrorCode = 0;
- INT iNumberOfDays = 0;
- DWORD dwType = 0;
- DWORD dwSize = 0;
- if (g_bEnableTimeLimited == FALSE)
- return 1;
- //创建注册表,有该键则读取,无则创建
- strcpy(strKeyName, "Software\\stoneu");
- dwErrorCode = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
- strKeyName,
- 0,
- NULL,
- REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS,
- NULL, //Security
- &hKey,
- NULL);
- if (dwErrorCode == ERROR_SUCCESS)
- {
- dwType = REG_BINARY;
- dwSize = sizeof(strFirstDate);
- dwErrorCode = RegQueryValueEx(hKey,
- "Date",
- NULL,
- &dwType,
- (BYTE*)strFirstDate,
- &dwSize
- );
- if (dwErrorCode == ERROR_SUCCESS && strcmp(strFirstDate, ""))
- {
- ::GetLocalTime(&systemtime);
- CTime NowDate(systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond);
- CTime MaxDate(systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond);
- CTime MinDate(systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond);
- iNumberOfDays = 90;
- MaxDate = MaxDate + CTimeSpan(iNumberOfDays, 0, 0, 0);
- MinDate = MinDate - CTimeSpan(iNumberOfDays, 0, 0, 0);
- sprintf(strMaxDate, "%04d%02d%02d", MaxDate.GetYear(), MaxDate.GetMonth(), MaxDate.GetDay());
- sprintf(strMinDate, "%04d%02d%02d", MinDate.GetYear(), MinDate.GetMonth(), MinDate.GetDay());
- if (atoi(strMaxDate) >= atoi(strFirstDate) && atoi(strMinDate) <= atoi(strFirstDate))
- {
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 1;
- }
- else
- {
- LOG4C((LOG_NOTICE, "软件试用天数已经到期!"));
- //MessageBox(hWnd, "软件试用天数已经到期!", "提示", MB_OK+MB_ICONINFORMATION);
- ////超过x天,则禁止运行
- //::InvalidateRect(hWnd, NULL, TRUE);
- //::UpdateWindow(hWnd);
- }
- }
- else
- {
- if (NULL == hWnd)
- {
- ::GetLocalTime(&systemtime);
- sprintf(strFirstDate, "%04d%02d%02d", systemtime.wYear, systemtime.wMonth, systemtime.wDay);
- dwErrorCode = RegSetValueEx(hKey,
- "Date",
- NULL,
- REG_BINARY,
- (BYTE*)strFirstDate,
- sizeof(strFirstDate)
- );
- if (dwErrorCode == ERROR_SUCCESS)
- {
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 1;
- }
- }
- }
- }
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 0;
- }
- VOID TerminateLastProcess()
- {
- HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hSnapShot != NULL)
- {
- PROCESSENTRY32 ProcessInfo = {0};//声明进程信息变量
- ProcessInfo.dwSize = sizeof(ProcessInfo);//设置ProcessInfo的大小
- //返回系统中第一个进程的信息
- BOOL bStatus = Process32First(hSnapShot, &ProcessInfo);
- while (bStatus)
- {
- if (!_stricmp(g_strAppName, ProcessInfo.szExeFile))//映像名称
- {
- HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessInfo.th32ProcessID);
- ::TerminateProcess(hProcess, 1);
- hProcess = NULL;
- Sleep(1000);
- break;
- }
- else
- //获取下一个进程的信息
- bStatus = Process32Next(hSnapShot, &ProcessInfo);
- }
- }
- }
- //增加自动启动注册表项
- INT AddAutoSysRun(CHAR *strExeFile, INT iAutoRunSystem)
- {
- HKEY hKey = NULL;
- DWORD dwErrorCode = 0;
- //创建注册表,有该键则读取,无则创建
- dwErrorCode = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
- 0,
- NULL,
- REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS,
- NULL, //Security
- &hKey,
- NULL);
- if (dwErrorCode == ERROR_SUCCESS)
- {
- if (iAutoRunSystem)
- dwErrorCode = RegSetValueEx(hKey, "SToneU-isP-CMS", NULL, REG_SZ, (BYTE*)strExeFile, (DWORD)strlen(strExeFile));
- else
- dwErrorCode = RegDeleteKey(hKey, "SToneU-isP-CMS");
- }
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 0;
- }
|