Hi, i am trying to create some small program but i want to add someting
well, i dont know how to check is computer restarted, for example when program first time executed it will show you that you must restart PC before use.
ok i can create that but when i start second time program runs winout restarting.
How to create something that you must restart PC before you can run program?
i never see example for that, of to someone discus about that. :U
what about creating a registry key? When your program starts, check to see what walue has that registry key.
If it doesn't exist, create it and set it to a vlaue(Eg ID_First_Run), then ask to restart the machine.
If that key exists and it is set to ID_First_Run, then change it to ID_Normal_Run.
But this doesn't work if the user restarts the app without restarting the machine ... :(
Another quick ideea. Make a small app and place it under RunOnce. It should do something like changing your exe to let it run.
Nick
yeah thats sucks, if user start target again program will run and dont need for restart system :'(
i like drivers, then you must restart comp to windows accept driver, but i dont like to mess with driver, i olmoust olways get Bsod :P
so i need some easy method winout drivers, i dont knoe, maybe something with mutex check or something other
any advice is welcome :U
No, really, the second method may work. You need 2 or 3 app ...
First one: Your application, but with it's header set to FFh
Second one: a small exe that has right header for first app in data section and some procs to copy that header to main app. This should be placed under RunOnce key.You can write code in main app to delete this exe if it find it.
Third one: a Install.exe that has both apps in .DATA section and will put second one under RunOnce key and copy both of them to proper location.
??
Nick
QuoteSecond one: a small exe that has right header for first app in data section and some procs to copy that header to main app. This should be placed under RunOnce key.You can write code in main app to delete this exe if it find it.
Third one: a Install.exe that has both apps in .DATA section and will put second one under RunOnce key and copy both of them to proper location.
yeah but then i will probably get olways same result, and program will dont know is win restarted or not
i dont know, i have some small idea in mind
for example we need also 3 aps
1. just simple message box that tell us that we need to restart computer and then use, this will also create startup key in regedit for secont app.
2. second app will be automatic activated when windows start, and when is run it will move or copy 3 ap (our program)
so 2 app will copy and replace original app with first message box that tould us that we need to restart computer ;)
i think that this will work winout problem?
btw i hope you understand my bad english.
Quote from: trodon on December 14, 2006, 05:37:28 PM
yeah but then i will probably get olways same result, and program will dont know is win restarted or not
No, no, no. :) Here is the algo:
The Install.exe is fiered.
- ask for a folder to install this application
- create two files in that directory: MainApp.exe and Dummy.exe
- copy from .CONST section the content of those two files
- create a subkey in registry under RunOnce, and pass as value the path and name for Dummy.exe
- issue a message: "In order to use MainApp, you need to restart Windows. Restart now? Y/N"
- if Yes - restart
- exit
At this moment, if user double click the MainApp.exe, it won't work, because his header is all 0FFh 's.
When Wndows will restart, Dummy.exe will be executed:
- GetCommandLine to find it's path
- replace Dummy.exe with MainApp.exe and you have the path and name
- open the file and copy from .CONST section the real header for MainApp.exe
- ShellExecute to run MainApp.exe
- exit
When MainApp.exe runs:
- GetCommandLine to find it's path
- replace MainApp.exe with Dummy.exe
- test to see if Dummy.exe exists
- if it's there - delete it
- run happy
So, what you say?
Nick
PS What, my english is better??? :)
GetLastRebootTime proc uses ebx ecx edx esi ; returns number of seconds elapsed between start of the year and last-reboot
local stime:SYSTEMTIME
invoke GetTickCount
xor edx,edx
mov ecx,1000
div ecx
push eax
invoke GetSystemTime,addr stime
movzx eax,stime.wSecond
movzx ebx,stime.wMinute
movzx ecx,stime.wHour
movzx edx,stime.wDay
movzx esi,stime.wMonth
imul ebx,60
imul ecx,60*60
imul edx,60*60*24
imul esi,60*60*24*31 ; let's not be precise about months.. it's useless
add eax,ebx
add ecx,edx
add eax,ecx
add eax,esi
pop ebx
sub eax,ebx
ret
GetLastRebootTime endp
HasComputerBeenRebooted proc InitialBootTime ; eax=0 if not, otherwise yes
; InitialBootTime is loaded from the registry or a local file
invoke GetLastRebootTime
sub eax,InitialBootTime
jge @F
neg eax
@@:
shr eax,3 ; let errors of +/- 7 seconds not be wrongly reported as reboots
; I've noticed errors of +/- 1 second
ret
HasComputerBeenRebooted endp
During installation of your app, call GetLastRebootTime(), and save the 32-bit result in the registry of some file.
Every time your app is started, it should load this 32-bit number, and call HasComputerBeenRebooted()
P.S: the "wMonths" can actually become nasty, so use GetSystemTimeAsFileTime(), and some 64-bit arithmetic.
Hello, Ultrano!
Well, it took me a while :) but it makes sense. It's much better than my method.
Regards,
Nick
Toyed with 64-bit, so finally this must work perfectly always:
GetLastRebootTime proc uses ecx edx ; returns number of seconds elapsed between (some fixed point in time) and last-reboot
local stime:QWORD
local result
.data
glrt_1div10000000 real8 0.0000001
.code
invoke GetSystemTimeAsFileTime,addr stime
sub dword ptr stime[0],8E7F8780h ; these two hard-coded values are a fixed time around today. (14.Dec.2006)
sbb dword ptr stime[4],01C71FB6h
fild stime
fmul glrt_1div10000000
fistp result
invoke GetTickCount
xor edx,edx
mov ecx,1000
div ecx
sub eax,result
neg eax
ret
GetLastRebootTime endp
hi thank you both for comments, i will try something like that
i like your method Ultrano :U
mine and TNick method is more how to say.... use some nessesary methods if compare with your method ;)
btw @Tnick, yes your english is 99% bether then mine :lol
Fantastic site Ultrano, you're something of true inspiration :U
Thanks :red - it's just that I have set some high goals (that I actually stumble really hard at attaining (http://www.ultranos.com/i/animesweat.gif) )
For future reference:
Quote from: http://msdn2.microsoft.com/en-us/library/ms724844.aspx
REG_OPTION_VOLATILE
All keys created by the function are volatile. The information is stored in memory and is not preserved when the corresponding registry hive is unloaded. For HKEY_LOCAL_MACHINE, this occurs when the system is shut down. For registry keys loaded by the RegLoadKey function, this occurs when the corresponding RegUnLoadKey is performed. The RegSaveKey function does not save volatile keys. This flag is ignored for keys that already exist.
The downside is it is only for Win2K and above.
Hope this helps, Ehtyar.
[Dumb look]
If I understood correctly...(having a blonde day)
erm... how about assign a Global Atom in u're proggy on first exit -
erm... if Global Atom still assigned on second start of proggy - pc has'nt been rebooted.
should be about 5 lines of code.
[Dumb look]
Draakie
Of course there is also the "proper" way to do it, which is to create an MSI to install your application. It isn't difficult to do, and there are free tools like WiX to build them with. By using an MSI you also get a proper uninstall ability as well.
I forgot to mentionate that this was a contest: Most stupid way to see if machine was restarted after install.
I won this contest, by the way.
:red
Nick