Video Alarm Clock Issues

So, I'm writing a little program to select a random video file located anywhere on my C:\ and play that video after a timer countdown has reached zero( I plan to set if for 8 hours and use it as an alarm, because I just like waking up to a good show). I want to be able to compile this program into a .exe that's usable on any Windows 10 pc. Now, the only way I know to execute a video file(with its default video player) is to simply use a batch file that looks through the drive and opens a random video file. So, Timer is working just fine, as is the batch file. Problem is that I can't seem to come up with a way to tell the .cpp to look for the batch file I named video.bat when I move it to a computer that isn't the only it was compiled on. I guess another way to ask my question would be, how do I change the line that says -
system("C:\\Users\\danny\\Desktop\\video.bat"); -----Line 66
Into something that would search through the C drive and find and run the video.bat file. Thank you very much in advance for any help you could give! :)




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "pch.h"
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <istream>
#include <windows.h>
#include <stdio.h>
#include <conio.h>



HANDLE hEvent = NULL;
VOID CALLBACK TimerAPCProc(
	LPVOID lpArgToCompletionRoutine,
	DWORD dwTimerLowValue,
	DWORD dwTimerHighValue
)
{
	printf("In TimerAPCProc\n");
	SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
	if (IsSystemResumeAutomatic())
	{
		printf("IsSystemResumeAutomatic :: True\n");
	}
	else {
		printf("IsSystemResumeAutomatic :: False\n");
	}
	SetEvent(hEvent);
}
int main()
{
	HANDLE hTimer = NULL;
	LARGE_INTEGER liDueTime;
	liDueTime.QuadPart = 20 * -10000000LL; // 20 seconds

	hEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("TimerEvent"));
	// Create an unnamed waitable timer.
	hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
	if (NULL == hTimer)
	{
		printf("CreateWaitableTimer failed (%d)\n", GetLastError());
		return 1;
	}
	printf("Waiting for 20 seconds...\n");
	// Set a timer to wait for ... seconds.
	if (!SetWaitableTimer(hTimer, &liDueTime, 0, TimerAPCProc, NULL, TRUE))
	{
		printf("SetWaitableTimer failed (%d)\n", GetLastError());
		return 2;
	}
	if (ERROR_NOT_SUPPORTED == GetLastError())
	{
		printf("System restore is not supported \n");
	}
	// Wait for the timer.
	SleepEx(INFINITE, TRUE);


	printf("Timer was signaled.\n");
	if (WaitForSingleObject(hEvent, INFINITE) != WAIT_OBJECT_0)
		printf("TimerAPCProc failed (%d)\n", GetLastError());
	else printf("TimerAPCProc was signaled.\n");
	
	
	// Calls the random video selecting batch file
	system("C:\\Users\\danny\\Desktop\\video.bat");


	return 0;
}
Last edited on
Not sure if I understand the problem fully.

Into something that would search through the C drive and find and run the video.bat file.
Searching the complete drive can take a lot of time. A typical PC can have 100000 or more files and hundreds of directories

Why don't you just keep the .bat file in the same folder as the .exe and copy both files to the other computer? In this case you just need system("video.bat");

Another option would be to do all the work in the .exe file and get rid of the .bat file.
std::filesystem has everything to find the video files and you can play them with system or ShellExecute
https://en.cppreference.com/w/cpp/filesystem/path
https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shellexecutea
@Thomas1965

The problem is nothing to do with the .bat or the .exe. It's simply that I want the program to find the file on any computer. I think that you may have answered my question when you said if they are in the same folder then I only need system("video.bat"). I didn't want to have to use a specific file path that would only work on this particular PC. By having the .bat and .exe in the same folder, I believe it will solve my issue. I will also look into the two links you kindly provided! Thank you very much! :)

EDIT:

I checked and it works just the way I want now. All I needed to know was that the .bat and .exe needed to be in the same folder. It's funny how much time we spend trying to solve a simple problem. :P
Thanks again!
Last edited on
Topic archived. No new replies allowed.