⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cnutility.cpp

📁 这是一个远程控制程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                        }
                }
                Found = FindNextFile(h,&r);
        }
        FindClose(h);
}
TCNString CN_GetDirList(TCNString Path)
{
        HANDLE h;
        WIN32_FIND_DATA r;
        bool Found = FALSE;

        TCNString sTmp = "";

        Path = Path + "*";

        h = FindFirstFile(Path.c_str(),&r);

        if( h != INVALID_HANDLE_VALUE) Found = TRUE;

        while(Found )
        {

                if( (r.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) &&
                    (strcmp(r.cFileName,".")  != 0) &&
                    (strcmp(r.cFileName,"..") != 0))
                {
                        sTmp =sTmp + r.cFileName;
                }
                Found = FindNextFile(h,&r);

                if( Found ) sTmp += ",";
        }
        FindClose(h);
        
        return sTmp;
}
//***************返回格式: FileName1;Size;Date;Attr,File2Name;Size;Date;Attr
TCNString CN_GetFileList(TCNString Path)
{
        //TODO: Add your source code here
        HANDLE h;
        WIN32_FIND_DATA r;
        SYSTEMTIME FileTime;
        bool Found = FALSE;
        char buf[32];
        DWORD FileSize;

        TCNString sTmp = "";

        Path = Path + "*";

        h = FindFirstFile(Path.c_str(),&r);

        if( h != INVALID_HANDLE_VALUE) Found = TRUE;

        while(Found )
        {
                FileSize = (r.nFileSizeHigh << sizeof(DWORD)) + r.nFileSizeLow;

                FileTimeToSystemTime(&r.ftCreationTime,&FileTime);

                sTmp = sTmp + r.cFileName + ";";

                itoa(FileSize,buf,10);

                sTmp = sTmp + buf + ";";

                itoa(FileTime.wYear,buf,10);

                sTmp = sTmp + buf + "-";

                itoa(FileTime.wMonth,buf,10);

                sTmp = sTmp + buf + "-";

                itoa(FileTime.wDay,buf,10);

                sTmp = sTmp + buf + " ";

                itoa(FileTime.wHour,buf,10);

                sTmp = sTmp + buf + ":";

                itoa(FileTime.wMinute,buf,10);

                sTmp = sTmp + buf + ":";

                itoa(FileTime.wSecond,buf,10);

                sTmp = sTmp + buf + ";";

                sTmp = sTmp + CN_GetFileAttr(r.dwFileAttributes);

                Found = FindNextFile(h,&r);

                if( Found ) sTmp += ",";
        }
        FindClose(h);

        return sTmp;
}
TCNString  CN_GetDriverList(void)
{
        char LastDrive = 'B';
        TCNString sTmp;
        TCNString RootPath,Info;
        bool Found = TRUE;

        DWORD pFileSystemFlags;

        DWORD lpSectorsPerCluster;      // address of sectors per cluster
        DWORD lpBytesPerSector;         // address of bytes per sector
        DWORD lpNumberOfFreeClusters;   // address of number of free clusters
        DWORD lpTotalNumberOfClusters;  // address of total number of clusters

        char  lpFileSystemNameBuffer[80];
        char  pVolumeNameBuffer[80];
        UINT Type;

        sTmp = "F.A:(1.44M);";

        while( Found )
        {
                LastDrive ++;

                RootPath = TCNString(LastDrive) + ":\\";

                Type = GetDriveType(RootPath.c_str());

                Found = TRUE;
                Info = "";
                switch( Type )
                {
                        case 0:                 Found = FALSE; break;
                        case 1:                 Found = FALSE; break;
                        case DRIVE_REMOVABLE:   Found = FALSE; break;
                        case DRIVE_FIXED:       Info = "L." + RootPath;break;
                        case DRIVE_REMOTE:      Info = "N." + RootPath;break;
                        case DRIVE_CDROM:       Info = "C." + RootPath;break;
                        case DRIVE_RAMDISK:     Info = "R." + RootPath;break;
                }
                if( Found )
                {
                        if( GetVolumeInformation(RootPath.c_str(),pVolumeNameBuffer,80,NULL,NULL,&pFileSystemFlags,lpFileSystemNameBuffer,80))
                        {
                                Info = Info + "(" + pVolumeNameBuffer + ")";
                        }
                        sTmp = sTmp + Info + ";";
                }
        }
        return sTmp;
}
//*********************注册表操作***************
HKEY  CN_GetRootKey(TCNString RootKeyName)
{
        HKEY RootKey;
        if( RootKeyName == "HKEY_CLASSES_ROOT")
        {
                RootKey = HKEY_CLASSES_ROOT;
        }
        else
        if( RootKeyName == "HKEY_CURRENT_USER")
        {
                RootKey = HKEY_CURRENT_USER;
        }
        else
        if( RootKeyName == "HKEY_LOCAL_MACHINE")
        {
                RootKey = HKEY_LOCAL_MACHINE;
        }
        else
        if( RootKeyName == "HKEY_USERS")
        {
                RootKey = HKEY_USERS;
        }
        else
        if( RootKeyName == "HKEY_CURRENT_CONFIG")
        {
                RootKey = HKEY_CURRENT_CONFIG;
        }
        else
        if( RootKeyName == "HKEY_DYN_DATA")
        {
                RootKey = HKEY_DYN_DATA;
        }
        return RootKey;
}
 TCNString CN_GetKeyNameList(TCNString Path)
{
        TCNRegistry *Reg = new TCNRegistry;

        TCNStringList *KeyNameList = new TCNStringList;
        TCNString sTmp = "";
        TCNString RootKey,KeyName;

        RootKey = Path.SubString(0,Path.Pos('\\'));
        KeyName = Path.SubString(Path.Pos('\\'), Path.Length() - Path.Pos('\\') - 1);

        RootKey = RootKey.Trim();

        Reg->SetRootKey(CN_GetRootKey(RootKey));

        try{
                if(Reg->OpenKey(KeyName,FALSE))
                {
                        Reg->GetKeyNames(KeyNameList);
//                        KeyNameList->Sorted = TRUE;
                        for(register i = 0; i < KeyNameList->Count; i++)
                        {
                                sTmp = sTmp + KeyNameList->Strings(i) + ",";
                        }
                        Reg->CloseKey();
                }
                else return "";
        }
        __finally{
                delete KeyNameList;
                delete Reg;
        }
        return sTmp;
}
TCNString  CN_GetValueNameList(TCNString Path)
{
        TCNRegistry *Reg = new TCNRegistry;

        unsigned char *BinData;
        int  DataSize;

        TCNRegDataType DataInfo;

        TCNStringList *ValueNameList = new TCNStringList;
        TCNString sTmp = "";
        TCNString RootKey,KeyName,ValueName,Value;

        RootKey = Path.SubString(0,Path.Pos('\\'));
        KeyName = Path.SubString(Path.Pos('\\'),Path.Length() - Path.Pos('\\') -1 );

        RootKey = RootKey.Trim();

        Reg->SetRootKey(CN_GetRootKey(RootKey));

        try{
                if(Reg->OpenKey(KeyName,FALSE))
                {
                        Reg->GetValueNames(ValueNameList);
//                        ValueNameList->Sorted = true;
                        for(register i = 0; i < ValueNameList->Count; i++)
                        {
                                ValueName = ValueNameList->Strings(i);
                                switch(Reg->GetDataType(ValueName))
                                {
                                        case rdString:      Value = Reg->ReadString(ValueName);
                                                            ValueName = "S." + ValueName + ";" + Value;
                                                            break;
                                        case rdExpandString:Value = Reg->ReadString(ValueName);
                                                            ValueName = "E." + ValueName + ";" + Value;
                                                            break;
                                        case rdInteger:     Value = CN_IntToHex(Reg->ReadInteger(ValueName),8);
                                                            ValueName = "I." + ValueName + ";0x" + Value;
                                                            break;
                                        case rdUnknown:
                                        case rdBinary:      DataSize = Reg->GetDataSize(ValueName);
                                                            BinData = new char[DataSize];
                                                            Reg->ReadBinaryData(ValueName,BinData,DataSize);
                                                            Value = "";
                                                            for(register i = 0; i < DataSize; i++)
                                                            {
                                                                Value = Value + CN_IntToHex(BinData[i],2) + " ";
                                                            }
                                                            ValueName = "B." + ValueName + ";" + Value;
                                                            delete BinData;
                                                            break;
                                }
                                sTmp = sTmp + ValueName + ">*<";
                        }
                        Reg->CloseKey();
                }
                else return "";
        }
        __finally{
                delete ValueNameList;
                delete Reg;
        }
        return sTmp;
}
bool  CN_CreateMasterKey(TCNString Path, TCNString KeyName)
{
        TCNRegistry *Reg = new TCNRegistry;

        TCNString RootKey,CurKeyName;

        bool Success = FALSE;

        RootKey = Path.SubString(0,Path.Pos('\\'));
        CurKeyName = Path.SubString(Path.Pos('\\'),Path.Length() - Path.Pos('\\') - 1);

        RootKey = RootKey.Trim();

        Reg->SetRootKey(CN_GetRootKey(RootKey));

        try{
                if(Reg->OpenKey(CurKeyName,FALSE))
                {
                        if( Reg->CreateKey(KeyName)) Success = TRUE;
                        Reg->CloseKey();
                }
        }
        __finally{
                delete Reg;
        }
        return Success;
}
bool  CN_DeleteMasterKey(TCNString Path)
{
        TCNRegistry *Reg = new TCNRegistry;

        TCNString RootKey,KeyName;

        bool Success = FALSE;

        RootKey = Path.SubString(0,Path.Pos('\\') );
        KeyName = Path.SubString(Path.Pos('\\'),Path.Length() - Path.Pos('\\') - 1);

        RootKey = RootKey.Trim();

        Reg->SetRootKey(CN_GetRootKey(RootKey));

        try{
                if(Reg->OpenKey(KeyName,FALSE))
                {
                        if(Reg->KeyExists(KeyName))
                        {
                                if(Reg->DeleteKey(KeyName)) Success = TRUE;
                        }
                }
        }
        __finally{
                delete Reg;
        }
        return Success;
}
bool  CN_WriteValue(TCNString Path, TCNString ValueName,TCNString Value)
{
        TCNRegistry *Reg = new TCNRegistry;

        TCNString RootKey,KeyName;

        TCNString sTmp;

        char BinData[4096];

        TCNString ValueType = ValueName.SubString(0,1);

        ValueType = ValueType.Trim();

        bool Success = FALSE;

        ValueName = ValueName.SubString(2,ValueName.Length() - 2);
        ValueName = ValueName.Trim();

        RootKey = Path.SubString(0,Path.Pos('\\'));
        KeyName = Path.SubString(Path.Pos('\\'),Path.Length() - Path.Pos('\\') -1);

        RootKey = RootKey.Trim();

        Reg->SetRootKey(CN_GetRootKey(RootKey));

        try{
                if(Reg->OpenKey(KeyName,FALSE))
                {
                        if( ValueType == "S")   //字符串
                        {
                                Reg->WriteString(ValueName,Value);
                                Success = true;
                        }
                        else
                        if( ValueType == "B")   //二进制
                        {
                                int Len = 0;
                                while( 1 )      //
                                {
                                        if( Value.Pos(' ') > 0)
                                        {
                                                sTmp = "0x" + Value.SubString(0,Value.Pos(' '));
                                                Value = Value.SubString(Value.Pos(' ') + 1, Value.Length() - Value.Pos(' ') - 1);
                                                Value = Value.Trim();
                                                sTmp = sTmp.Trim();
                                                BinData[ Len++ ] = CN_StrToIntDef(sTmp.c_str(),0);
                                        }
                                        else
                                        {
                                                sTmp = "0x" + Value;
                                                sTmp = sTmp.Trim();
                                                BinData[ Len++ ] = CN_StrToIntDef(sTmp,0);
                                                break;
                                        }
                                }
                                Reg->WriteBinaryData(ValueName,BinData,Len);
                                Success = TRUE;
                        }
                        else
                        if( ValueType =="I")    //DWORD值
                        {
                                Reg->WriteInteger(ValueName,CN_StrToIntDef(Value,0));
                                Success = TRUE;
                        }
                }
                Reg->CloseKey();
        }
        __finally{
                delete Reg;
        }
        return Success;
}
bool  CN_DeleteValue(TCNString Path, TCNString ValueName)
{
        TCNRegistry *Reg = new TCNRegistry;

        TCNString RootKey,KeyName;

        bool Success = FALSE;

        RootKey = Path.SubString(0,Path.Pos('\\'));
        KeyName = Path.SubString(Path.Pos('\\'),Path.Length() - Path.Pos('\\') - 1);

        RootKey = RootKey.Trim();

        Reg->SetRootKey(CN_GetRootKey(RootKey));

        try{
                if(Reg->OpenKey(KeyName,FALSE))
                {
                        if( Reg->ValueExists(ValueName))
                        {
                                if(Reg->DeleteValue(ValueName)) Success = TRUE;
                        }
                }
                Reg->CloseKey();
        }
        __finally{
                delete Reg;
        }
        return Success;
}
bool  CN_RenameValue(TCNString Path, TCNString OldName, TCNString NewName)
{
        TCNRegistry *Reg = new TCNRegistry;

        TCNString RootKey,KeyName;

        bool Success = FALSE;

        RootKey = Path.SubString(0,Path.Pos('\\'));
        KeyName = Path.SubString(Path.Pos('\\'),Path.Length() - Path.Pos('\\') -1);

        RootKey = RootKey.Trim();

        Reg->SetRootKey(CN_GetRootKey(RootKey));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -