Solved

!!!!VERY VERY EASY!!!!!!

Posted on 2003-12-01
6
302 Views
Last Modified: 2010-04-01
Who can write for me a program, which reads a file(each line containing a date and something else(an action)), ececutes the action at the given time (I will write the actionpart)<br>
So the program reads the lines selects next date and time and calls a function at the given time.<br>Thanks
0
Comment
Question by:Centauri
6 Comments
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 175 total points
ID: 9851842
I can, but I wouldn't... because Windows and Linux both have the 'at' command.
0
 
LVL 69

Expert Comment

by:Callandor
ID: 9853209
Sounds like a job scheduler to me, so why would you want to reinvent the wheel?
0
 
LVL 1

Author Comment

by:Centauri
ID: 9856507
I need this because I would like to send information to an URL at that moment and I don't think, that it can be done without this program
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 175 total points
ID: 9857172
How about calling wget or curl (Linux) or lynx.exe (Windows) at the required time using at to schedule the batch file / script? The parameter can be picked up from a batch file /script.

e.g. In Windows XP you could maintain a file called value.txt with the URL-encoded value you wanted to send to http://xxx?This=value at 14:00 on Thursday.

   at 14:00 /next:THU "c:\MyStuff\DoIt.bat"

   DoIt.bat
   --------8<--------
   @echo off
   setlocal
   set /p that= < value.txt
   lynx -source "http://xxx?This=%that%" > c:\nul
   --------8<--------

...this sort of thing is easier in Linux.
0
 
LVL 69

Expert Comment

by:Callandor
ID: 9857969
Have you tried Control Panel->Scheduled Tasks->Add Scheduled Task and filling out the command to run on the Task tab and the time to run on the Schedule tab?  The command can be a perl script, DOS batch file, or exe file.  Why does this not work for you?
0
 
LVL 3

Accepted Solution

by:
RJSoft earned 125 total points
ID: 9858592
Semi-Pseudo code

struct SS
{
int date;
int time;
char DoIt[200];
};

// could do this as link list for larger instruction sets
// but this may be adaquate for you, I dont know

// space to read in 1000 instructions
struct SS Instruct[1000];

// load instructions and times into memory
FILE *fptr=NULL;
fptr=fopen("Input.txt","rb");
if(fptr==NULL)
{
MessageBox error....
return;
}//endif
int x=0;
while(1)
{
fread(&Instruct[x],sizeof(SS),1,fptr);
x++;
if(x==1000)break;
}//endwhile
fclose(fptr);

In InitDialog activate a timer

SetTimer(id,val,NULL);
Id can be any number dont matter,
val can be 1000 for fire every one second


Then use message member function OnTimer
from message WM_TIMER

void YourDialog::OnTimer(UINT Id)
{
//dont worry about id

//if date and time match do it...
if(Instruct[WhichInstruct].date==YourRequestedDate &&
   Instruct[WhichInstruct].time==YourRequestedTime )DoSomething();


}//endfunc


WhichInstruct could be a global variable to keep track of a count of which instruction got done last. So it could be a value of 0 to 999. You may only need 31 max, depending on what you want to do.

Once the DoSomething function runs you could increment the counter WhichInstruct++ for the next day. Going back to 0 for the begining of the month.

As far as creating the file simply load the struct with the values you like. You can use something more explicit than ints for date and time. up to you. Just after you load the struct use fwrite or whatever way you want to write the file.

fptr=fopen("file.txt","wb");
int x=0;
while(1)
{
prompt ("enter time");
Instruct[x].time=xxxxx;
prompt("enter date");
Instruct[x].date=yyyyy;
prompt("enter instruction"); //cin >> Str
strcpy(Instruct[x].DoIt,Str);   ex..."open first.htm"
fwrite(&Instruct,sizeof(SS),1,fptr);
x++;
if(prompt ...) break;
}//endwhile


void MyDialog::DoSomething()
{
// to open an html page
ShellExecute(Instruct[WhichInstruct],0,.....);
}//endfunc

One good thing about ShellExecute is that it does the instruction with the default program that is assigned to the specific file (in this case htm will start your browser)

Bad thing is that when the other app runs there is no real good way to shut the other app (browser in this case) down.

You can use EnumWindows to get the handle of your browser window and then close it, but thing is there is no standard amoung window titles and class names. (EnumWindows can get the title or class name for you but there are not much similarities enough to close unkown conditions)

Unless you know the classname and or window title specifically in each condition you will end up with other apps running uncontrolled. If this is acceptable then no need to worry hey...

You can also run another app and have your app wait for the processing of the other app to quit or terminate. You can do this with ShellExecute also but that may not really help in your case if your using an application like this for scripting purposes. This is because what good does it do you to run another application that does not close (like a browser) and have your scripting app just hang waiting for the other to close.....

If on the other hand your apps close after processing then this would be perfect.

RJ
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now