Check whether system requires restart or not: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|aman_ansari}}
|<small>Author: [[{{ns:2}}:aman_ansari|aman_ansari]] ([[{{ns:3}}:aman_ansari|talk]], [[{{ns:-1}}:Contributions/aman_ansari|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
Using this function you can determine whether your system requires a restart or not. This can be useful when you are running external setup applications or want to check whether previously installers applications require a restart.
Using this function you can determine whether your system requires a restart or not. This can be useful when you are running external setup applications or want to check whether previously installers applications require a restart.
Line 38: Line 36:
ExitFunc:
ExitFunc:
Pop $R3
Pop $R2
Pop $R2
Pop $R3
Exch $R1
Exch $R1
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
[[Category:System Related Functions]]

Latest revision as of 19:51, 7 December 2009

Author: aman_ansari (talk, contrib)


Description

Using this function you can determine whether your system requires a restart or not. This can be useful when you are running external setup applications or want to check whether previously installers applications require a restart.

To check whether your own installer requires a restart (when using /REBOOTOK parameters), use IfRebootFlag (see documentation).

Usage

Push $R1
Call RestartRequired
Exch $R1
StrCmp $R1 "1" RestartRequired RestartNotRequired

The Function

Function RestartRequired
	Exch $R1         ;Original Variable
	Push $R2
	Push $R3         ;Counter Variable
 
	StrCpy $R1 "0" 1     ;initialize variable with 0
	StrCpy $R3 "0" 0    ;Counter Variable
 
	;First Check Current User RunOnce Key
	EnumRegValue $R2 HKCU "Software\Microsoft\Windows\CurrentVersion\RunOnce" $R3
	StrCmp $R2 "" 0 FoundRestart
 
	;Next Check Local Machine Key
	EnumRegValue $R2 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" $R3
	StrCmp $R2 "" ExitFunc 0
 
	FoundRestart:
		StrCpy $R1 "1" 1
 
	ExitFunc:
		Pop $R3
		Pop $R2
		Exch $R1
FunctionEnd