打开regedit 注册表编辑器

找到 HKEY_CLASSES_ROOT 新建 如下目录

 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

"C:\Windows\System32\cmd.exe" "%1"

 最后在浏览器中输入

cmd://

即可打开cmd

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include "string"
#include <Windows.h>
#include <sstream>

using namespace std;

void prompt(LPWSTR szCmd);
wchar_t* charToWchar(const char* src);
void write(string content);
std::string decodeURIComponent(const std::string& in);

int main(int nArgc, char* argv[])
{

    string str = "";
    for (size_t i = 1; i < nArgc; i++)
    {
        str += " " + string(argv[i]);
    }

    str = decodeURIComponent(str.substr(7,str.length() - 8));

    str = "start cmd /k " + str;

    write(str);

    system(str.c_str());

    return 0;
}

//int main() {
//    string str = "test";
//    write(str);
//}

string decodeURIComponent(const string& in)
{
    int               readFlag = 0;
    int               code = 0;
    stringstream ssUri;
    for (const char& c : in) {
        if ((readFlag == 0) && (c == '%')) {
            readFlag = 1;
            continue;
        }
        else if (readFlag == 1) {
            if (isxdigit(c)) {
                if (isdigit(c))
                    code = c - '0';
                else if (c >= 'A' && c <= 'F')
                    code = (0x0a + (c - 'A'));
                else
                    return string();
                readFlag = 2;
                continue;
            }
            else {
                return string();
            }
        }
        else if (readFlag == 2) {
            if (isxdigit(c)) {
                code <<= 4;
                if (isdigit(c))
                    code |= (c - '0');
                else if (c >= 'A' && c <= 'F')
                    code |= (0x0a + (c - 'A'));
                else
                    return string();
                ssUri << (char)(code & 0xff);
                code = 0;
                readFlag = 0;
                continue;
            }
            else {
                return string();
            }
        }
        else {
            ssUri << c;
        }
    }
    return ssUri.str();
}

void write(string content) {
    ofstream ofs;
    ofs.open((char*)"C:\\Users\\djatm\\source\\repos\\urlProtocol\\logs.txt", ios::out);

    ofs << content << endl;

    ofs.close();
}

void prompt(LPWSTR szCmd) {
    TCHAR szModuleName[MAX_PATH];
    STARTUPINFO si = { 0 };
    PROCESS_INFORMATION pi = { 0 };

    GetModuleFileName(NULL, szModuleName, MAX_PATH);

    CreateProcess(NULL, szCmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);

    WaitForSingleObject(pi.hProcess, INFINITE);

    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
}

wchar_t* charToWchar(const char* src) {
    size_t size = strlen(src) + 1;
    wchar_t* dest = new wchar_t[size];
    size_t outSize;
    mbstowcs_s(&outSize, dest, size, src, size - 1);
    return dest;
}

ping 一下百度:

cmd://ping www.baidu.com

 

 posted on 2023-12-28 23:30  laremehpe  阅读(129)  评论(0编辑  收藏  举报