View Full Version : stopping a program
kurtgamer
03-14-2006, 08:50 AM
Hello
Sorry for my English
I have a code to launch a program at a specifiec time thats OK
But i want to stop that program on a other time.
code on a page "Show"
sTime = System.GetTime(TIME_FMT_MIL)
Label.SetText("Label11", sTime)
Page.StartTimer(1000)
code on a page "Timer"
sTime = System.GetTime(TIME_FMT_MIL)
Label.SetText("Label11", sTime)
if sTime == "15:35:00" then
result = File.Run(_ProgramFilesFolder.."\\program\\program.exe", "", "", SW_SHOWNORMAL, false);
end
Is that possibel.
Thanxs kurtgamer
TJ_Tigger
03-14-2006, 08:58 AM
That should work. I would recommend that if you are going to compare seconds that you lessen the timer to have it run more frequently. Even though you have it set to one second, I have seen it skip a second in a display due to a system being short on memory.
Page.StartTimer(500)
Tigg
If you need to 'stop' a program at a specific time, you could use
-- define variable H
Window.Close(H, CLOSEWND_TERMINATE);
Where 'H' is a variable holding the WndHandle of the window you want to terminate.
If you don't know the WndHandle of the window that needs to be closed, you could use
Windows_Open = Window.EnumerateTitles(false);
kurtgamer
03-14-2006, 09:47 AM
That should work. I would recommend that if you are going to compare seconds that you lessen the timer to have it run more frequently. Even though you have it set to one second, I have seen it skip a second in a display due to a system being short on memory.
Page.StartTimer(500)
Tigg
No good Tigg
Because the program starts 2 times in the same second.
kurtgamer
03-14-2006, 09:56 AM
If you need to 'stop' a program at a specific time, you could use
-- define variable H
Window.Close(H, CLOSEWND_TERMINATE);
Where 'H' is a variable holding the WndHandle of the window you want to terminate.
If you don't know the WndHandle of the window that needs to be closed, you could use
Windows_Open = Window.EnumerateTitles(false);
Mina i test what You give to me but it dont work wright now.
I take the code from the help
-- Get the titles and window handles of all open windows.
windows = Window.EnumerateTitles();
-- A variable containing text in the title you want to search for.
window_name = "Notepad";
-- Loop through the table of windows.
for handle, title in windows do
-- Check if the window title has the target text.
result = String.Find(title, window_name, 1, false);
-- if the string was found in the title, send the window a close message.
if (result ~= -1) then
Window.Close(handle, CLOSEWND_SENDMESSAGE);
end
end
with a Notepad its OK
But with my application NOT OK
I wil try now to get al of the "titles and window handles of all open windows"
in a table to check of my app.'s name
kurtgamer
No good Tigg
Because the program starts 2 times in the same second.
Yup, because 500 milliseconds is half a second and the program is set to start in 1 second :)
To get over this, something like this might help:
-- ((On timer))
sTime = System.GetTime(TIME_FMT_MIL)
Label.SetText("Label11", sTime)
if sTime == "15:35:00" and Launched then
Launched = false
else
result = File.Run(_ProgramFilesFolder.."\\program\\program.exe", "", "", SW_SHOWNORMAL, false);
launched = true
end
Mina i test what You give to me but it dont work wright now.
I take the code from the help
-- Get the titles and window handles of all open windows.
windows = Window.EnumerateTitles();
-- A variable containing text in the title you want to search for.
window_name = "Notepad";
-- Loop through the table of windows.
for handle, title in windows do
-- Check if the window title has the target text.
result = String.Find(title, window_name, 1, false);
-- if the string was found in the title, send the window a close message.
if (result ~= -1) then
Window.Close(handle, CLOSEWND_SENDMESSAGE);
end
end
with a Notepad its OK
But with my application NOT OK
I wil try now to get al of the "titles and window handles of all open windows"
in a table to check of my app.'s name
kurtgamer
Replace "Notepad" with "the title of your window" in
window_name = "Notepad";
For example, to close this window (indigorose forums), i used the following code and it worked:
windows = Window.EnumerateTitles();
window_name = "stopping a program - Indigo Rose Software Forums - Mozilla Firefox";
for handle, title in windows do
result = String.Find(title, window_name, 1, false);
if (result ~= -1) then
Window.Close(handle, CLOSEWND_SENDMESSAGE);
end
end
If you are using firefox, it should work perfectly with you :yes
kurtgamer
03-14-2006, 10:12 AM
Yup, because 500 milliseconds is half a second and the program is set to start in 1 second :)
To get over this, something like this might help:
-- ((On timer))
sTime = System.GetTime(TIME_FMT_MIL)
Label.SetText("Label11", sTime)
if sTime == "15:35:00" and Launched then
Launched = false
else
result = File.Run(_ProgramFilesFolder.."\\program\\program.exe", "", "", SW_SHOWNORMAL, false);
launched = true
end
No Mina no good the application starts 2 times/sec and counting
kurtgamer
03-14-2006, 10:15 AM
thanxs mina
now i get it
its the title of the window
My bad englisch i tought it was the name of the program
sorry I was not thinking straight
kurtgamer
Perfect for stopping my application thanxs
No Mina no good the application starts 2 times/sec and counting
Sorry, but i haven't made a project that did such actions before..
Try it this way
sTime = System.GetTime(TIME_FMT_MIL)
Label.SetText("Label11", sTime)
Last_Run = Registry.GetValue(HKEY_CURRENT_USER, "My-Application", "Last_Run", false);
if Last_Run ~= "15:35:00" and sTime == "15:35:00" then
result = File.Run(_ProgramFilesFolder.."\\program\\program.exe", "", "", SW_SHOWNORMAL, false);
Registry.SetValue(HKEY_CURRENT_USER, "My-Application", "Last_Run", "15:35:00", REG_SZ);
elseif Last_Run == "15:35:00" and sTime == "15:35:00" then
Registry.SetValue(HKEY_CURRENT_USER, "My-Application", "Last_Run", sTime, REG_SZ);
end
TJ_Tigger
03-14-2006, 10:55 AM
No good Tigg
Because the program starts 2 times in the same second.
Yes it will. Thanks Mina for responding, I would do what Mina did and put a variable that is set when you first launch the application then when your timer fires again then you can check to see if it is launched based on that variable. You could also stop the timer after you launch the program. I don't know it that will be appropriate or not, but it is a thought.
Along the lines of checking the time multiple times within a second, you could have a counter that will reset after so many seconds as well. Something like this. Change the number in Red below to make it wait a number of timer iterations equal to the specified number.
--Launch code for the Timer
Page.StartTimer(500);
g_Timer_ctr = 0
Launched = false;
-- (On timer)
sTime = System.GetTime(TIME_FMT_MIL)
Label.SetText("Label11", sTime)
if Launched and g_Timer_ctr < 4 then
g_Timer_ctr = g_Timer_ctr +1;
if g_Timer_ctr == 4 then
Launched = false
g_Timer_ctr = 0
end
elseif sTime == "10:54:00" and not Launched then
result = File.Run(_SystemFolder.."\\notepad.exe", "", "", SW_SHOWNORMAL, false);
Launched = true
g_Timer_ctr = g_Timer_ctr +1;
end
Tigg
kurtgamer
03-14-2006, 11:08 AM
Hallo mina
I have learnd many things from your reply's
my code is now the same you give me but i have taken the time ("17.53.00") to a string
it's faster for changing.
Now i will looking into the code from TJ-Tigger.
--Launch code for the Timer
Page.StartTimer(500);
g_Timer_ctr = 0
Launched = false;
-- (On timer)
sTime = System.GetTime(TIME_FMT_MIL)
Label.SetText("Label11", sTime)
if Launched and g_Timer_ctr < 4 then
g_Timer_ctr = g_Timer_ctr +1;
if g_Timer_ctr == 4 then
Launched = false
g_Timer_ctr = 0
end
elseif sTime == "10:54:00" and not Launched then
result = File.Run(_SystemFolder.."\\notepad.exe", "", "", SW_SHOWNORMAL, false);
Launched = true
g_Timer_ctr = g_Timer_ctr +1;
end
Tigg
Uh, yeah i could've said that.. :lol
osamazaied
05-01-2006, 01:22 PM
Hallo TJ_Tigger
I set a button to open a rtf file (assum afile name 2300.rtf) ,I need the code required to close it when I press anthor button
with my regards
Wonderboy
05-01-2006, 02:04 PM
this will close an rtf file called 2300 that is opend , put this on a click action of your button.
-- Get the titles and window handles of all open windows.
windows = Window.EnumerateTitles();
-- A variable containing text in the title you want to search for.
window_name = "2300";
-- Loop through the table of windows.
for handle, title in windows do
-- Check if the window title has the target text.
result = String.Find(title, window_name, 1, false);
-- if the string was found in the title, send the window a close message.
if (result ~= -1) then
Window.Close(handle, CLOSEWND_SENDMESSAGE);
end
end
osamazaied
05-01-2006, 02:14 PM
Dear Wonderboy
THK a lot it works
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.