⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sctask.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    if ((FAILED(hr)) && (hr != SCHED_E_NO_SECURITY_SERVICES))
    {
        // wprintf(L"Error: Failed to set credentials on task object %x\n",hr);
        pITask->Release();
        return hr;
    }

    // Set command name with ITask::SetApplicationName

    hr = pITask->SetApplicationName(lpwszAppName);
    if (FAILED(hr))
    {
        // wprintf(L"Error: Failed to set command name (with parms)\n"); 
        pITask->Release();
        return hr;
    }


    // Set task parameters with ITask::SetParameters

    hr = pITask->SetParameters(lpwszCommand);
    if (FAILED(hr))
    {
        // wprintf(L"Error: Failed to set parameters\n");
        pITask->Release();
        return hr;
    }
   
    // Set the comment, so we know how this job go there
    // Uses ITask::SetComment

    hr = pITask->SetComment(L"This job was added by PGP. You may edit it freely.");
    if (FAILED(hr))
    {
        // wprintf(L"Error: Task comment could not be set\n");
        pITask->Release();
        return hr;
    }

    // Set the flags on the task object
    // Use ITask::SetFlags

    dwTaskFlags = TASK_FLAG_DELETE_WHEN_DONE;
    hr = pITask->SetFlags(dwTaskFlags);
    if (FAILED(hr))
    {
        // wprintf(L"Error: Could not set task flags\n");
        pITask->Release();
        return hr;
    }

    // Now, create a trigger to run the task at our specified time.
    // Uses ITask::CreateTrigger()

    hr = pITask->CreateTrigger(&wTrigNumber, &pITaskTrig);
    if (FAILED(hr))
    {
        // wprintf(L"Error: Could not create a new trigger\n");
        pITask->Release();
        return hr;
    }

    // Now, fill in the trigger as necessary.
    dwTrigFlags = 0;

    TaskTrig.cbTriggerSize = sizeof(TASK_TRIGGER);
    TaskTrig.Reserved1 = 0;
    TaskTrig.wBeginYear = lptTime->wYear;
    TaskTrig.wBeginMonth = lptTime->wMonth;
    TaskTrig.wBeginDay = lptTime->wDay;
    TaskTrig.wEndYear = 0;
    TaskTrig.wEndMonth = 0;
    TaskTrig.wEndDay = 0;
    TaskTrig.wStartHour = lptTime->wHour;
    TaskTrig.wStartMinute = lptTime->wMinute;
    TaskTrig.MinutesDuration = 0;
    TaskTrig.MinutesInterval = 0;
    TaskTrig.rgFlags = dwTrigFlags;
    TaskTrig.TriggerType = TASK_TIME_TRIGGER_DAILY;
	TaskTrig.Type.Daily.DaysInterval=1;
    TaskTrig.wRandomMinutesInterval = 0;
    TaskTrig.Reserved2 = 0;

    // Add this trigger to the task using ITaskTrigger::SetTrigger

    hr = pITaskTrig->SetTrigger(&TaskTrig);
    if (FAILED(hr))
    {
        // wprintf(L"Error: Failed to set trigger to desired values\n");
        pITaskTrig->Release();
        pITask->Release();
        return hr;
    }

    // Make the changes permanent
    // Requires using IPersistFile::Save()

    hr = pITask->QueryInterface(IID_IPersistFile, (void **) &pIPF); 
    if (FAILED(hr))
    {
        // wprintf(L"Error: Could not get IPersistFile on task\n");
        pITaskTrig->Release();
        pITask->Release();
        return hr;
    }

    hr = pIPF->Save(NULL, FALSE);
    if (FAILED(hr))
    {
        // wprintf(L"Error: Could not save object\n");
        pITaskTrig->Release();
        pITask->Release();
        pIPF->Release();
        return hr;
    }

    // We no longer need ITask
    
	EditTaskSettings(hwnd,pITask);

    pITask->Release();
    pITask = NULL;

    // Done with ITaskTrigger pointer
    
    pITaskTrig->Release();
    pITaskTrig = NULL;

    // Done with IPersistFile
    
    pIPF->Release();
    pIPF = NULL;

    return hr;
} 

extern "C" HRESULT SchedulePGPwipe(HWND hwnd,PGPContextRef context,
								   char *Drive,int Passes)
{
	HRESULT hRes;
	ITaskScheduler *pITaskScheduler;
	WCHAR wszJobName[255];
	WCHAR wszAppName[255];
	WCHAR wszCommand[255];
	UINT uCodePage;
	SYSTEMTIME SysTime;
	int result;
	char szJobName[255];
	char szAppName[255];
	char szCommand[255];

	strcpy(szJobName,"PGPwipeVolume");
	szJobName[strlen(szJobName)+1]=0;
	szJobName[strlen(szJobName)]=Drive[0];
	strcat(szJobName,".job");

	PGPclGetPath (kPGPclInstallFolder, szAppName, sizeof(szAppName));
	strcat(szAppName, "PGPmail.exe");

	sprintf(szCommand,"/w %d %s",Passes,Drive);

	memset(wszJobName,0x00,255*sizeof(WCHAR));
	memset(wszAppName,0x00,255*sizeof(WCHAR));
	memset(wszCommand,0x00,255*sizeof(WCHAR));

	uCodePage = _getmbcp();
	result=MultiByteToWideChar(uCodePage, 0, 
		szJobName,
		strlen(szJobName),
		wszJobName,255);

	result=MultiByteToWideChar(uCodePage, 0, 
		szAppName,
		strlen(szAppName),
		wszAppName,255);

	result=MultiByteToWideChar(uCodePage, 0, 
		szCommand,
		strlen(szCommand),
		wszCommand,255);

	hRes=Init(&pITaskScheduler);

	if(hRes!=S_OK)
	{
		PGPscMessageBox (hwnd,IDS_PGPERROR,IDS_NOTASKSCHL,
			MB_OK|MB_ICONSTOP);
	}
	else
	{
		if(PGPscMessageBox (hwnd,IDS_SCHLTITLE,IDS_SCHLINFO,
			MB_OKCANCEL|MB_ICONQUESTION)==IDCANCEL)
		{
			hRes=S_FALSE;
		}
		else
		{
			hRes=DeleteJob(pITaskScheduler,wszJobName);

			GetLocalTime(&SysTime);

			hRes=AddJob(hwnd,
				context,
				pITaskScheduler,
				wszJobName, 
				&SysTime,
				wszAppName,
				wszCommand);

			if(hRes!=S_OK)
			{
				PGPscMessageBox (hwnd,IDS_PGPERROR,IDS_NOADDJOB,
					MB_OK|MB_ICONSTOP);
			}
			else
			{
				PGPscMessageBox (hwnd,IDS_SCHLTITLE,IDS_SCHLOK,
					MB_OK|MB_ICONINFORMATION);
			}
		}
		Cleanup(pITaskScheduler);
	}

	return hRes;
}

// find if iPstr2 is in iPstr1
// case doesn't matter
// return is same as strstr 
char *mystrstri(char *iPstr1, char *iPstr2)
{            
	int i;
	int Len    = strlen(iPstr2);
	int MaxLen = strlen(iPstr1)-Len;
  
	for(i=0; i<=MaxLen; i++)
	{
		if(!strnicmp(iPstr1+i, iPstr2, Len)) 
			break;
	}

	if(i>MaxLen) 
		return NULL;

	return (iPstr1+i);
}

extern "C" HRESULT SchedulePGPdirwipe(HWND hwnd,PGPContextRef context,
									  char *Directory,int Passes)
{
	HRESULT hRes;
	ITaskScheduler *pITaskScheduler;
	WCHAR wszJobName[255];
	WCHAR wszAppName[255];
	WCHAR wszCommand[255];
	UINT uCodePage;
	SYSTEMTIME SysTime;
	int result;
	char szJobName[255];
	char szAppName[255];
	char szCommand[255];
	char *name;

	if((mystrstri(Directory,"\\windows")!=NULL)||
		(mystrstri(Directory,"\\winnt")!=NULL)||
		(mystrstri(Directory,"\\Program Files")!=NULL)||
		(mystrstri(Directory,"\\Documents and Settings")!=NULL)||
		(strlen(Directory)<=3)) // Probably c:\ etc.
	{
		if(IDCANCEL==MessageBox (hwnd,
			"The directory you are scheduling to wipe and delete may be\n"
			"within a system folder or other important directory.\n\n"
			"Press OK if you are sure you want to continue.",
			Directory,
			MB_OKCANCEL|MB_ICONSTOP))
			return S_FALSE;
	}

	name=strrchr(Directory,'\\');

	if(name==NULL)
		name=Directory;
	else
		name++;

	strcpy(szJobName,"PGPwipe");
	strcat(szJobName,name);
	strcat(szJobName,".job");

	PGPclGetPath (kPGPclInstallFolder, szAppName, sizeof(szAppName));
	strcat(szAppName, "PGPmail.exe");

	sprintf(szCommand,"/d %d %s",Passes,Directory);

	memset(wszJobName,0x00,255*sizeof(WCHAR));
	memset(wszAppName,0x00,255*sizeof(WCHAR));
	memset(wszCommand,0x00,255*sizeof(WCHAR));

	uCodePage = _getmbcp();
	result=MultiByteToWideChar(uCodePage, 0, 
		szJobName,
		strlen(szJobName),
		wszJobName,255);

	result=MultiByteToWideChar(uCodePage, 0, 
		szAppName,
		strlen(szAppName),
		wszAppName,255);

	result=MultiByteToWideChar(uCodePage, 0, 
		szCommand,
		strlen(szCommand),
		wszCommand,255);

	hRes=Init(&pITaskScheduler);

	if(hRes!=S_OK)
	{
		PGPscMessageBox (hwnd,IDS_PGPERROR,IDS_NOTASKSCHL,
			MB_OK|MB_ICONSTOP);
	}
	else
	{
		if(MessageBox (hwnd,
			"Completing this operation will cause a directory wipe to be\n"
			"scheduled for the currently selected directory using the task\n"
			"scheduler.\n\n"
			"Note: If you are using Windows NT, you will need to enter\n"
			"your NT login password to allow the job to run.\n\n"
			"Do you wish to continue?",
			Directory,
			MB_OKCANCEL|MB_ICONQUESTION)==IDCANCEL)
		{
			hRes=S_FALSE;
		}
		else
		{
			hRes=DeleteJob(pITaskScheduler,wszJobName);

			GetLocalTime(&SysTime);

			hRes=AddJob(hwnd,
				context,
				pITaskScheduler,
				wszJobName, 
				&SysTime,
				wszAppName,
				wszCommand);

			if(hRes!=S_OK)
			{
				PGPscMessageBox (hwnd,IDS_PGPERROR,IDS_NOADDJOB,
					MB_OK|MB_ICONSTOP);
			}
			else
			{
				PGPscMessageBox (hwnd,IDS_DSCHLTITLE,IDS_DSCHLOK,
					MB_OK|MB_ICONINFORMATION);
			}
		}
		Cleanup(pITaskScheduler);
	}

	return hRes;
}

/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -