任务计划程序管理at.exe任务 [英] task scheduler manage at.exe tasks

查看:129
本文介绍了任务计划程序管理at.exe任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用CreateProcess和at.exe命令创建新的计划任务时,我在名为at1.job,at2.job,at3.job等的计划任务文件夹中获取文件.

我想使用c ++编程删除其中的一些.
我想搜索所有的at文件,在其命令行中查找特定命令,然后删除包含此命令的at文件.

我该怎么做?

谢谢

When creating a new scheduled task, using CreateProcess with at.exe command, I get files in the scheduled tasks folder named at1.job, at2.job, at3.job, etc.

I want to delete some of them, using c++ programming.
I want to search all the at files, look for a specific command in their command line, and delete those at files contain this command.

How can I do it?

Thanks

推荐答案

要搜索文件,可以使用 FindNextFile [ ^ ] .当找到匹配项时,可以使用CFile.

这是一个很好的链接: http://msdn.microsoft.com /en-us/library/ey6xh9bk(v=VS.100).aspx [
To search the files you could use FindFirstFile[^] and FindNextFile[^]. When you found matches you could use CFile.

Here''s one good link: http://msdn.microsoft.com/en-us/library/ey6xh9bk(v=VS.100).aspx[^]


您是否尝试过:
Have you ever tried this:
C:\>cd WINDOWS
C:\WINDOWS>cd Tasks
C:\WINDOWS\Tasks>dir /a/s/b
C:\WINDOWS\Tasks\dfrag.job
C:\WINDOWS\Tasks\At1.job
C:\WINDOWS\Tasks\desktop.ini
C:\WINDOWS\Tasks\SA.DAT
C:\WINDOWS\Tasks\User_Task1.job


要删除此* .job文件,只需执行以下语句:


To delete this *.job files Just execute the following statement:

system("del /a /f C:\WINDOWS\Tasks\*.job");


注意:请指定您的操作系统目录.并非总是C:\ windows.


Note: Please specify you OS dir. It is not always C:\windows.


erez_l写道:

最大的问题是我不知道"由于文件位于控制面板\计划任务"文件夹中,因此不知道文件中文件的确切结构以及如何在文件中进行搜索.

The big prblem is that I don''t know exactly what is the structure of those at files and how to search inside them, because they are in the "control panel\scheduled tasks" folder.



您可以轻松地剖析这些文件,MSDN提供了有关文件格式的文档.
请参见
2.4.1 FIXDLEN_DATA [ 2.4.2可变长度数据部分 [



You can easily dissect these files, MSDN has documentation on the file format.
See 2.4.1 FIXDLEN_DATA[^] and 2.4.2 Variable-Length Data Section[^]

You can probably skip the section 2.4.1 because it is fixed length and doesn''t contain anything you are interested in.

What you might come up with is this.
It is the full code to a console application that will print the command line of every .job file.

#include <windows.h>
#include <stdio.h>
//Makes sure there is no padding added in by the compiler
#pragma pack(push)
#pragma pack(1)
//This struct is irrelevant for your task
typedef struct {
	WORD nProductVersion;
	WORD nFileVersion;
	WORD nUUID[9];
	WORD nAppNameLenOffset;
	WORD nTriggerOffset;
	WORD nErrorRetryCount;
	WORD nErrorRetryInterval;
	WORD nIdleDeadline;
	WORD nIdleWait;
	DWORD nPriority;
	DWORD nMaximumRunTime;
	DWORD nExitCode;
	DWORD nStatus;
	DWORD nFlags;
	WORD nYear;
	WORD nMonth;
	WORD nWeekday;
	WORD nDay;
	WORD nHour;
	WORD nMinute;
	WORD nSecond;
	WORD nMilliSeconds;
} FixedLenData;
typedef struct {
	WORD nLength;
	wchar_t szString[]; //0 sized array warning can be ignored
} UnicodeString;
typedef struct {
	FixedLenData *pHeader;
	union {
		struct {
			UnicodeString *pApplicationName; //The .exe name
			UnicodeString *pParameters; //The additional command line args
			UnicodeString *pRunningInstanceCount;
			UnicodeString *pWorkingDirectory;
			UnicodeString *pAuthor;
			UnicodeString *pComment;
			UnicodeString *pUserData;
			UnicodeString *pReservedData;
			UnicodeString *pTriggers;
			UnicodeString *pJobSignature;
		};
		UnicodeString *pStrings[10];
	};
} ATJobFile;
#pragma pack(pop)
ATJobFile *ReadJob(LPCSTR szFileName) {
	HANDLE hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile == INVALID_HANDLE_VALUE) {
		return NULL;
	}
	DWORD nFileSize = SetFilePointer(hFile, 0, NULL, FILE_END); //Get file size
	SetFilePointer(hFile, 0, NULL, FILE_BEGIN); //Reset file pointer
	BYTE *pData = new BYTE[nFileSize];
	ATJobFile *pJob = new ATJobFile();
	ReadFile(hFile, pData, nFileSize, &nFileSize, NULL);
	CloseHandle(hFile);
	pJob->pHeader = (FixedLenData *)pData; //This points to the start of the file
	pData += sizeof(FixedLenData);
	for (int nString = 0; nString < 10; ++nString) {
		pJob->pStrings[nString] = (UnicodeString *)pData;
		pData += pJob->pStrings[nString]->nLength * sizeof(wchar_t) + sizeof(WORD);
	}
	return pJob;
}
void DestroyJob(ATJobFile *pJob) {
	delete []pJob->pHeader;
	delete pJob;
}
int main() {
	WIN32_FIND_DATA fdSearch;
	char szWinDir[MAX_PATH];
	ExpandEnvironmentStrings("%WINDIR%\\Tasks", szWinDir, sizeof(szWinDir)); //Find the Windows directory
	SetCurrentDirectory(szWinDir); //This just saves us putting "C:\\Windows\\Tasks\\" infront of everything
	HANDLE hFind = FindFirstFile("*.job", &fdSearch);
	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			ATJobFile *pJob = ReadJob(fdSearch.cFileName);
			printf("Job %s\n", fdSearch.cFileName);
			if (pJob->pParameters->nLength == NULL) {
				wprintf(L"%s\n\n", pJob->pApplicationName->szString);
			} else {
				wprintf(L"%s %s\n\n", pJob->pApplicationName->szString, pJob->pParameters->szString);
			}
			DestroyJob(pJob);
		} while (FindNextFile(hFind, &fdSearch));
	}
	return 0;
}


这篇关于任务计划程序管理at.exe任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆