Download Pelles C here: http://www.pellesc.se
Quote from: MrBcx on December 10, 2025, 04:21:11 PMI have attached my four Bcx Basic Task Scheduler source codes, so that peopleBCX seems to be powerful
can examine the codes without needing to sign up on the Bcx forum.
The BCX Translator is needed, if you want to examine the resulting C/C++ codes.
I successfully tested each using Pelles C, MSVC, Mingw64, and Clang.

ComCpp2C2.exe EnumTasks2.cpp > EnumTasks2.cit just convert from cpppTaskCollection->Release();to C pTaskCollection->lpVtbl->Release(pTaskCollection);/********************************************************************
This sample enumerates through all running tasks on the local computer and
displays their name and state.
********************************************************************/
#define WIN32_LEAN_AND_MEAN
#define _WIN32_DCOM
#include <windows.h>
#include <stdio.h>
//#include <comdef.h>
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
//#pragma comment(lib, "comsupp.lib")
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")
int __cdecl wmain()
{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}
// Set general COM security levels.
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);
if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( &CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
&IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
CoUninitialize();
return 1;
}
// Connect to the task service.
VARIANT v1;
VariantInit(&v1);
hr = pService->lpVtbl->Connect(pService, v1, v1, v1, v1);
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->lpVtbl->Release(pService);
CoUninitialize();
return 1;
}
// Get the running tasks.
IRunningTaskCollection* pRunningTasks = NULL;
hr = pService->lpVtbl->GetRunningTasks(pService,TASK_ENUM_HIDDEN, &pRunningTasks);
pService->lpVtbl->Release(pService);
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
CoUninitialize();
return 1;
}
LONG numTasks = 0;
hr = pRunningTasks->lpVtbl->get_Count(pRunningTasks,&numTasks);
if( numTasks == 0 )
{
printf("\nNo Tasks are currently running" );
pRunningTasks->lpVtbl->Release(pRunningTasks);
CoUninitialize();
return 1;
}
printf("\nNumber of running tasks : %d", numTasks );
TASK_STATE taskState;
v1.vt = VT_I4;
for(LONG i=1; i <= numTasks; i++)
{
v1.lVal = i;
IRunningTask* pRunningTask = NULL;
hr = pRunningTasks->lpVtbl->get_Item(pRunningTasks, v1, &pRunningTask );
if( SUCCEEDED(hr) )
{
BSTR taskName = NULL;
hr = pRunningTask->lpVtbl->get_Name(pRunningTask,&taskName);
if( SUCCEEDED(hr) )
{
printf("\nTask Name: %ls", taskName);
SysFreeString(taskName);
hr = pRunningTask->lpVtbl->get_State(pRunningTask,&taskState);
if (SUCCEEDED (hr) )
printf("\n\tState: %d", taskState);
else
printf("\n\tCannot get the registered task state: %x", hr);
}
else
{
printf("\nCannot get the registered task name: %x", hr);
}
pRunningTask->lpVtbl->Release(pRunningTask);
}
else
{
printf("\nCannot get the registered task item at index=%d: %x", i+1, hr);
}
}
pRunningTasks->lpVtbl->Release(pRunningTasks);
CoUninitialize();
return 0;
}
// Connect to the task service.
//hr = pService->Connect(_variant_t(), _variant_t(), _variant_t(), _variant_t());
hr = pService->lpVtbl->Connect(pService, v1, v2, v3, v4);
those variants are optional, but C compiler don't allow NULL for them.typedef struct names{
char AppPath[MAX_PATH];
char VBSTime[50];
char VBETime[50];
char TaskName[50];
char UserSTime[50];
char Message[50];
}names;
names name;
/****************************************************************************
* *
* Function: Create_Script_PS1 *
* *
* Purpose : create runnable Powershell script for task *
* *
* History : Date Reason *
* 01/31/25 Created John Z *
* *
* Globals :SYSTEMTIME dpst, SYSTEMTIME dpet; *
****************************************************************************/
void Create_Script_PS1(void)
{ int RetVal;
char FileName [MAX_PATH*2]={0};
FILE *p_file;
char buf2[4000]={0};
char *p_buf2;
p_buf2 = buf2; //wide char
strcpy(FileName,name.AppPath);
strcat(FileName,"scr1.ps1");
p_file = fopen(FileName,"wb+"); //For Binary Access Write
if (p_file == NULL)
{
snprintf(buf2,MAX_PATH*2,"Unable to open file.\r\nFilename: %s",FileName);
MessageBoxA( NULL, buf2, "File Access Error",
MB_OK | MB_ICONERROR | MB_TOPMOST);
return;
}
snprintf(p_buf2, 3999,"%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A",
"$TriggerTypeTime = 1",
"$ActionTypeExec = 0",
"$service = New-Object -ComObject Schedule.Service",
"$service.Connect()"
);
RetVal = fwrite(p_buf2, sizeof(char), strlen(p_buf2), p_file);
snprintf(p_buf2, 3999,"%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A",
"$rootFolder = $service.GetFolder(\"\\\")",
"$taskDefinition = $service.NewTask(0)",
"$taskDefinition.RegistrationInfo.Description = \"Start Alert at a certain time\""
);
RetVal = fwrite(p_buf2, sizeof(char), strlen(p_buf2), p_file);
fflush(p_file);
snprintf(p_buf2, 3999,"%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A",
"$taskDefinition.RegistrationInfo.Author = \"CalendarZ\"",
"$taskDefinition.Principal.LogonType = 3",
"$taskDefinition.Settings.Enabled = $true",
"$taskDefinition.Settings.StartWhenAvailable = $true"
);
RetVal = fwrite(p_buf2, sizeof(char), strlen(p_buf2), p_file);
snprintf(p_buf2, 3999,"%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A",
"$taskDefinition.Settings.Hidden = $false",
"$taskDefinition.Settings.DeleteExpiredTaskAfter = \"PT10M\"",
"$triggers = $taskDefinition.Triggers",
"$trigger = $triggers.Create($TriggerTypeTime)"
);
RetVal = fwrite(p_buf2, sizeof(char), strlen(p_buf2), p_file);
fflush(p_file);
snprintf(p_buf2, 3999,"%s'%s'\x0D\x0A%s'%s'\x0D\x0A%s\x0D\x0A%s\x0D\x0A",
"$startTime = ",name.VBSTime,
"$endTime = ",name.VBETime,
"$trigger.StartBoundary = $startTime",
"$trigger.EndBoundary = $endTime"
);
RetVal = fwrite(p_buf2, sizeof(char), strlen(p_buf2), p_file);
fflush(p_file);
snprintf(p_buf2, 3999,"%s\x0D\x0A%s\x0D\x0A%s\"%s%s\"\x0D\x0A",
"$actions = $taskDefinition.Actions",
"$action = $actions.Create($ActionTypeExec)",
"$action.Path = ",
name.AppPath,
"Alert.exe"
);
RetVal = fwrite(p_buf2, sizeof(char), strlen(p_buf2), p_file);
snprintf(p_buf2, 3999,"%s%s -%s\"\x0D\x0A",
"$Action.Arguments = \"-",
name.UserSTime,
name.Message
);
RetVal = fwrite(p_buf2, sizeof(char), strlen(p_buf2), p_file);
snprintf(p_buf2, 3999,"%s\x0D\x0A%s,\x0D\x0A%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A%s\x0D\x0A)",
"$rootFolder.RegisterTaskDefinition(",
name.TaskName,
" $taskDefinition,",
" 6, # Task creation flag (6 = CREATE_OR_UPDATE)",
" $null, # User",
" $null, # Password",
" $null, # Logon type",
" $null # SDDL"
);
RetVal = fwrite(p_buf2, sizeof(char), strlen(p_buf2), p_file);
fflush(p_file);
fclose(p_file);
//MessageBox(NULL,"Completed!","Create Alert",MB_OK);
}/* end create_script_ps1 */
Quote from: Vortex on December 09, 2025, 11:26:23 AMAdditionaly, MrBcx created some useful applications too :
https://bcxbasiccoders.com/smf/index.php?topic=1443.0
Page created in 0.064 seconds with 15 queries.