欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
windows 下的自動(dòng)更新

windows 下的自動(dòng)更新

jackyhwei 發(fā)布于 2011-09-02 16:30 點(diǎn)擊:198次
Windows下實(shí)現自動(dòng)更新的實(shí)現代碼。

#include <stdio.h>
#include <assert.h>
#include <windows.h>

static int update_start(const char *path)
{
    HANDLE hProcess = NULL;
    STARTUPINFO startupInfo = {0};
    PROCESS_INFORMATION processInfo;

    char module[256];
    char cmdline[8192];
    startupInfo.cb = sizeof(startupInfo);
    hProcess = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId());
    size_t count = GetModuleFileName(NULL, module, sizeof(module));
    assert(count < sizeof(module));
    snprintf(cmdline, sizeof(cmdline),
            "update.exe %p -wait %s -delete %s -copy %s -final",
            hProcess, module, module, module);
    if (CreateProcess(path, cmdline, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
                NULL, NULL, &startupInfo, &processInfo) != TRUE) {
        printf("Create Process Fail: %d!\n", GetLastError());
        return -1;
    }
    CloseHandle(processInfo.hThread);
    CloseHandle(processInfo.hProcess);
    CloseHandle(hProcess);
    return 0;
}

static int update_wait(const char *handle)
{
    HANDLE hProcess = NULL;
    int count = sscanf(handle, "%p", &hProcess);
    assert(count == 1);
    WaitForSingleObject(hProcess, INFINITE);
    CloseHandle(hProcess);
    return 0;
}

static int update_final(const char *path)
{
    HANDLE hProcess = NULL;
    STARTUPINFO startupInfo = {0};
    PROCESS_INFORMATION processInfo;

    char module[256];
    char cmdline[8192];
    startupInfo.cb = sizeof(startupInfo);
    hProcess = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId());
    size_t count = GetModuleFileName(NULL, module, sizeof(module));
    assert(count < sizeof(module));
    snprintf(cmdline, sizeof(cmdline), "update.exe %p -wait %s -delete -1 -clear",
            hProcess, module, module);
    if (CreateProcess(path, cmdline, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
                NULL, NULL, &startupInfo, &processInfo) != TRUE) {
        CloseHandle(hProcess);
        return -1;
    }
    CloseHandle(processInfo.hThread);
    CloseHandle(processInfo.hProcess);
    CloseHandle(hProcess);
    return 0;
}

static int update_interpret(int argc, char *argv[])
{
    int i;
    char module[8192];
    size_t count = GetModuleFileName(NULL, module, sizeof(module));
    assert (count < sizeof(module));

    for (i=1; i<argc; i++) {
        if (!strcmp(argv[i], "-wait")) {
            if (update_wait(argv[i-1]) != 0)
                printf("update wait fail: %d\n", GetLastError());
        }else if (!strcmp(argv[i], "-copy")){
            if (CopyFile(module, argv[i-1], TRUE) != TRUE)
                printf("copy %s to %s fail\n", module, argv[i-1]);
        }else if (!strcmp(argv[i], "-delete")){
            if (DeleteFile(argv[i-1]) != TRUE)
                printf("delete %s fail\n", argv[i-1]);
        }else if (!strcmp(argv[i], "-final")){
            if (update_final(argv[i-1]) != 0)
                printf("update final fail: %d\n", GetLastError());
        }else if (!strcmp(argv[i], "-clear")){
            return atoi(argv[i-1]);
        }
    }
    return 0;
}

static int autorun_set(const char *regpath)
{
    HKEY hAutoRunKey = NULL;
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0,
               KEY_ALL_ACCESS, &hAutoRunKey) != ERROR_SUCCESS){
    printf("RegOpenKeyEx Fail\n");
    return -1;
    }
    char module[8192];
    size_t count = GetModuleFileName(NULL, module, sizeof(module));
    assert(count < sizeof(module));
    RegSetValueEx(hAutoRunKey, "rpcserver", 0, REG_SZ,
        (LPBYTE)module, strlen(module));
    RegCloseKey(hAutoRunKey);
    return 0;
}

int main(int argc, char *argv[])
{
    //FreeConsole();

    if (argc > 1 ) {
        if (!update_interpret(argc, argv))
            return 0;
    }else{
        if (!update_start("update.exe"))
            return 0;
    }

    autorun_set("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

    HANDLE hMutex = CreateMutex(NULL, FALSE, "rg4.net/rpcserver");
    if (GetLastError() == ERROR_ALREADY_EXISTS){
    CloseHandle(hMutex);
    return -1;
    }

    for (;;) {
        Sleep(1000);
        printf("Hello World!\n");
    }

    CloseHandle(hMutex);
    return 0;
}

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Windows下實(shí)現進(jìn)程保護
實(shí)戰 | 記一次Word文檔網(wǎng)絡(luò )釣魚(yú)以及繞過(guò)火絨,電腦管家和Windows Defender
Windows系統編程之進(jìn)程間通信_mypage
自刪除程序的研究及實(shí)現
遠程線(xiàn)程注入(二)線(xiàn)程注入
將可執行程序以資源形式添加到另外一可執行程序[轉貼]
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久