• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Playing video at certain time

Hey experts!

I'm looking to make a install that will install a video and set it to play at a certain time.  I'm not sure if I should either write a program to play a video, or somehow set the scheduler for windows to play it.  In either case, I'm not sure where to begin.  So my question is: Do you experts have any ideas on how to do this?  thanks!

  • 6
  • 3
1 Solution
It depends what you mean by 'install' the video.  I think you mean just copy it to the hard drive, since you do not normaly use a program like installShield to accomplish this.

You could do this using C I am fairly sure since it is just parameter passing.  As for the windows scheduler then that again depends on your definition of install.

Let us know the exact purposes of what you need.
DiscomonkeyAuthor Commented:
Here's exactly what I want to do:
I have a movie clip (movie.avi or movie.mpg)

I want to make a .exe that when executed will:

1) copy movie.avi to a directory on the hard drive
2) set movie.avi to play at a particular time (say 11:00 pm)

now I know you can set task scheduler (win 98 has it, don't know about other os) to add a task that would accomplish this.  How can I access task scheduler via my program (my thoughts are that it is impossible)

so the only other option would be to just rely on the program.  I have no idea how to accomplish this.
It is not easy or even doable if the movie has to be *packaged* with the .exe, and I think that is what you want: am I correct ?  That will inevitably result in one hell of a big executable file.

I cannot see why you would want to do this anyway; if the executable is to be run on machine X, then this implies the movie must reside on machine X; hence it would be infinitely easier to copy the movie *beforehand* to machine X and the rely on your program purely to execute it.  

Of course you could write a batch file that would copy it from, say a CD, without anyone knowing and then set this to be run at a certain time via the your program; the program could then sit idle (and invisible) in memory waiting to run the movie itself.

You also need to be more specific about the program intended to play the movie (eg realplayer, windows media) although if you use a batch file this is not a problem, but the problem with batch files is the dos window the appears.

This is certainly an interesting problem, and it would be interesting to hear what the purpose of it is :D

-- A prank on someone maybe ?

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

DiscomonkeyAuthor Commented:
well its actually a small file like maybe 5 megs or so, but the purpose of the program is a prank, it's such an awesome idea, I guess I'll write it, hopefully no one comes by and steals this idea because its too good.  Basically me and a friend want to make a virus like program (not harmful, just when you run it it'll pop something up to distract the person) and what it REALLY does is install the video from the movie The Ring where its that random jibberish that's all freaky and have it play in the middle of hte night on a friends's computer, and splice in their name, and since we know exactly when it goes off, we're gonna call that person exactly when the movie ends.  MAN I'm freaked out just thinkin about it.
If you've never seen the movie, its really damn good, but pretty freaky at parts (since the whole movie is about a movie that kills people 7 days after they see it)

So basically its an elaborate prank, Windows media player would be the prefered player to use, and the computer is left on over night so there's no problems there.  any ideas?  the program that sits in memory is a good idea (hey that's virus)  not sure how to go about any of this htough
Yeah this is more than doable.  I would do it in C.  

It is even easier if you have VC++ as it provides an easy way to make an app window invisible but still doing something in the background if you get me.

As regards the time then you could hard code it into the program or pass it via the command line.  Of course this makes it more difficult as you need to parse the time to make sure it is in the correct format, but it is all doable.

As regards distracting the user with something else; this is not really necessary as the program when run will appear to be a placebo anyway.  Unless they run some sort of process viewer they will not know it is there.

So basically since you cannot easily package the video into the mpeg, you need two files:

1. The movie (never)
2. The exe that, when run, will first copy the movie to a specified directory and then sit dormant waiting for the time to come when the movie is to be played.

Sound ok ?

I will have a crack at this later my time (currently 9:20GMT).
#include <stdio.h>
#include <time.h>
#include <Windows.h>
#include <process.h>

#define DUMMY_STRING  __TEXT("I am already running")

int main(int argc, char** argv)
          HANDLE hMapping;
          // Test to ensure that we are not running more than one copy of the program.
          // Place a string in a certain memory area, and later test for its existence
          hMapping = CreateFileMapping( (HANDLE)0XFFFFFFFF, NULL, PAGE_READWRITE, 0, 256, DUMMY_STRING);
          if (hMapping != NULL) {
               if (GetLastError() == ERROR_ALREADY_EXISTS) {
                    exit(1);     // String already exists; no need for more than one copy running hence exit
               } else {          // This is the only program instance running
          } else {
               exit(1);          // Other problem

          system("@echo Please Wait....");
          system("@echo off");
          system("cp <filename> <dirname>");     // eg system("cp myMovie.avi C:\");  Copy the movie to play to the hard drive of your buddy's machine

          // get current time.
          time_t currentTime;
          struct tm tm_current;
          // localtime returns a pointer (struct tm*) so we want the dereferenced struct tm !
          tm_current = *(localtime(&currentTime));

          struct tm runTime;    
          runTime = *(localtime(&currentTime));

          // With the values as given, the task would execute at 14:33 on 1st April 2003
          runTime.tm_mday = 1;          // Day of month
          runTime.tm_hour = 14;     // Hour (24hr format)
          runTime.tm_min = 33;     // Minutes past hour
          runTime.tm_sec = 0;          // Seconds past minute
          time_t timeToRun = mktime(&runTime);

          double diff = difftime(timeToRun, currentTime);
          printf("Sleeping for %.2lf ", diff);
          system("@echo off");
          system(" <full path to file> ");     // eg system("C:\myMovie.avi");  
     return 0;

You need to bind and link this with the following paramters (in MSCV++) :

Project->Settings->Link Tab ->Project Options box


/subsystem:windows (this replaces /subsystem:console)

If you have not got MSVC++, or have other probs then get back to me and I will figure out another way to get the app to run invisibly.

Test this locally before you let it loose on your friend.
whoops the command to copy the file in the system() call should be




Damn Unix commands still stuck in my head from University...
DiscomonkeyAuthor Commented:
AWESOME.  I haven't tested it yet, tonight i will, school has turned up the heat on me.  This looks good though I'm gonna play with it.  I'll get back to you asap.

Did you ever try this code and did it work ?

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now