Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone please help me! SYSTEMTIME

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to read the system time and run a batch file on a specific day and time. I wrote the following code using C++ help library.


SYSTEMTIME timeNow;
while(1)
{
Sleep(30000L); // check every 30 sec.
GetSystemTime(&timeNow);
// make sure its monday and its 10pm
if (timeNow.wDayOfWeek == 1 || timeNow.wHour == 22)
//need run bat file routine here
While(timeNow.WMinute == 0)
// dont run twice in the same hour
{
Sleep(60000L);
GetSystemTime(&timeNow);
}
}

I am not getting any result from this code can someone please help, Where am i going wrong.
 
if (timeNow.wDayOfWeek == 1 && timeNow.wHour == 22)
{
//need run bat file routine here
while (timeNow.wMinute != 0)
// dont run twice in the same hour
{
Sleep(60000L);
GetSystemTime(&timeNow);
}
}


I'm not sure what the problem is, the if condition should be true on Monday OR at 22:00. Probably you want && (and) in there. Note also the "!=". You maybe want to use GetLocalTime() rather than GetSystemTime() which returns the unadjusted GMT or whatever. Maybe that's why the routine doesn't run when you expect it to.
BTW, it would be better though to reduce your interval in the second while loop to below 60 secs, or you might miss the 0 minute and stay in the loop for another hour (possible, the system timer is not very accurate).

:) Hope that this helped! :)
 
When using the getsystemtime, you will get the Greewich time. That maybe is not your local time. If so, you cannot get the batch files to work as you expected. use GetLocalTime()instead,you will get it.
By the way, it is more logical if the code goes like this:

SYSTEMTIME timeNow;
while(1){
Sleep(30000L); // check every 30 sec.
GetLocalTime(&timeNow);
// make sure its monday and its 10pm
if (timeNow.wDayOfWeek == 1 && timeNow.wHour == 22){
//need run bat file routine here
Sleep(360000L);
}
}


 
Thanks friends,

Got it working, is there any chance for help on the two following questions.

1) Just like GetLocalTime, there is SetLocalTime, How would i use this SetlocalTime to set the time. ie 23:45?

2) I am using WIN 32 Application for my program, Is there a command that i can use to terminated the program ( DOS LIKE SCREEN) once it has perfomed its task.

help would be very grateful.
 
Thanks friends,

Got it working, is there any chance for help on the two following questions.

1) Just like GetLocalTime, there is SetLocalTime, How would i use this SetlocalTime to set the time. ie 23:45?

2) I am using WIN 32 Application for my program, Is there a command that i can use to terminated the program ( DOS LIKE SCREEN) once it has perfomed its task.

help would be very grateful.
 
SYSTEMTIME timeNow;
GetLocalTime(&timeNow);
timeNow.wHour = 23;
timeNow.wMinute = 45;
timeNow.wSecond = 0;
timeNow.wMilliseconds = 0;
SetLocaTime(&timeNow);


 
Thanks Mate it works, but it only sets the new time when the program terminate itself.
Is there a way of terminating this Dos-Like sceeen program after the setTime command.

I tried Exit(1) and abort(), but no luck.

again thanks for the help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top