Archive: Calling Regedit. Which method is better?


Calling Regedit. Which method is better?
In thread "convert .reg file" Kitchik, responding to aarnado, suggests calling Regedit.exe to merge a large number of registry entries into the registry on the target PC.

He suggests: (commenting is mine) (method 1)


GetTempFileName $R0
File /oname=$R0 myreg.reg ; copy myreg.reg to <uniquefilename> on target PC
ExecWait 'Regedit.exe /S "$R0"' ; merge the copied file into the registry (silently)
Delete $R0 ; delete the temporary file

And he also explains: (my paraphrasing, not a quote):
/S tells Regedit to work silently: it won't ask the user "are you sure ...", won't report success, but reports errors.

Thanks Kitchik for the tip about /s. It prompts the folowing questions:
1) Are there any other command line switches for Regedit?
2) Why, instead of the above code, can't we simply use (method 2):

ExecWait 'Regedit.exe /s "$EXEDIR\myreg.reg"' ; merge myreg.reg into target PC's registry

In other words, why not run the .reg file straight from the distribution media rather than first copy it to the target PC and later delete it.

3) What do you think about the following alternative (method 3):

ExecShell "" "$EXEDIR\myreg.reg"

Advantage: If Regedit.exe is not in the search path on the target PC (it might have been moved for security reasons), methods 1 and 2 will produce an error, but method 3 will still work provided the target PC has a file association set up for file-type .reg which correctly points to Regedit.exe.
Disadvantage: There does not seem to be a way of using the /s switch with method 3.

4) Is this correct, or is there some way of using /s with method 3 (shell-exec)?

5) Alternatively, can the /s switch be put into the .reg file itself?
(i.e. would Regedit recognise it as a command rather than a registry entry?) On reflection, I think not (but if anyone knows better, please say so). Experimentation on my Windows98.SE PC suggests that Regedit asks "are you sure…" before looking at the contents of myreg.reg. If myreg.reg is not of the expected format (e.g. if the header line "REGEDIT4" is missing or is in lower case), Regedit will still ask "are you sure…" and only then report an error. (On the other hand, it's worth noting that if you change the 4 to something else, it won't work, but Regedit falsely reports success!)

6) There is a syntax problem using method 3 (at least on my Windows98.SE PC).
Note that in the above example, no explicit action is specified; rather, an empty string ("") is used to specify the default action. I think that it is better to specify an explicit action for the ExecShell instruction, because specifying the default action relies on making assumptions about what the default action will be on the target PC. Since this is user-changeable, this is not a safe assumption. I have found that specifying "merge" as the action in this case doesn't work - despite the fact that there is a shell action called "merge" for Regedit, AND "merge" is the default action. Anyone know why?

Hint: If you edit the "merge" action in the Windows GUI using Explorer's "Edit File Type" facility, the action name is spelled "mer&ge", but in the main "Edit File Type" box, in the list of actions, it shows up as "merge". I don't know what the significance of this is - can anyone shed any light on it?

Also, I noticed that in HKEY_CLASSES_ROOT\regfile\shell, there is an "open" action, but this action does not show up anywhere in the GUI - not in the right-click context menu for .reg files, and not in the list of actions shown in the "Edit File Type" box for file type "Registration Entries" (.reg). Anyone know why? I tried using "open" as the action for ExecShell and it worked (i.e. it did what you would expect "merge" to do), but can we assume that this will be true on any target PC?

If it works, don't fix it :)


Using dselkirk's program is the best way. I will give you answers to all of the above question probably not later than tomorrow.


dselkirk's program???
What (and where) is dselkirks program?
(Sorry, it sounds like something you might assume we should know of, but I'm relatively new to this forum.)

Also, while you're at it, could you point me to some more detailed documentation (with sample code?) of how to use FindWindow, SendMessage and IsWindow. (BTW, I'm NOT familiar with Windows API calls.)


Re: dselkirk's program???

Originally posted by Mottel
What (and where) is dselkirks program?
If you read this thread you should be filled in better :)

dselkirk program doesn't work
Whoops -- just realised what you meant by dselkirk's program. (Ini2reg.zip) Sorry, but it doesn't work! See the attachment .zip file for an example:

MyReg.reg -------------- is the original Registry export file.
MyReg-BAD.nsi -------- is the output from Ini2reg
My-Reg-02.nsi ---------- is the cleaned up output (what Ini2reg SHOULD have produced.)

It falls over so badly in so many places, I wouldn't trust it further than I could vet it.
There are some cases where there is no alternative to using Regedit. I came across one when I was trying to write a large block of binary data (in hex). If it exceeds 2Kb, NSIS can't handle it.


Attachment
Sorry, looks like the attachment got lost.
Here it is again -- hope it shows up this time.


ini2reg was a very basic converter. it does not support anything fancy. it was a quick solution to someones problem. If you would like somethink better let me know and I'll see what I can do.


Here is an updated version which can do a little more. It now supports bin and dword import. Quotation and backslash problems fixed. It also creates the uninstall section as well. There's still somethings it can't do but should be good for basic usage.


ini2reg upgrade: comments
Well, this one's a vast improvement on version 1. Pretty good going for a couple of hours' work! :up:

Just one suggestion:

Where you have taken to using single quotes (I use the plural to denote that they come in pairs) to overcome the problem of consecutive delimiters, I would suggest that you switch to using the backward single quote (on the tilde key) instead.

This will eliminate problems like the one shown below. At the moment, version 2 still falls over on one line of the sample input (myreg.reg) that I uploaded earlier on this thread.

If you do that, then, instead of a line like this, which produces an error:


WriteRegStr HKCR "xxx.Audio\shell\ListBookmark" "" 'Add to Winamp's &Bookmark list'

you will get:

WriteRegStr HKCR "xxx.Audio\shell\ListBookmark" "" `Add to Winamp's &Bookmark list`

which is okay, since NSIS supports all three kinds of quotes.

Thank you. Here is the update you've requested.


Re: Calling Regedit. Which method is better?

1) Are there any other command line switches for Regedit?
http://support.microsoft.com/default...;EN-US;Q82821&
[quote]2) Why, instead of the above code, can't we simply use:
ExecWait 'Regedit.exe /s "$EXEDIR\myreg.reg"'

In other words, why not run the .reg file straight from the distribution media rather than first copy it to the target PC and later delete it.[/qoute]
You assume here that the installation media is a CD-ROM or something alike. Most users of NSIS use one installer that contains it all as far as I know.
4) Is this correct, or is there some way of using /s with method 3 (shell-exec)?
The command windows uses is regedit.exe too, it doesn't include the full path. Have a look at the registry (HCKR\regfile\shell\open\command).

5) Alternatively, can the /s switch be put into the .reg file itself?
You can't do that.

6) There is a syntax problem using method 3 (at least on my Windows98.SE PC).
Note that in the above example, no explicit action is specified; rather, an empty string ("") is used to specify the default action. I think that it is better to specify an explicit action for the ExecShell instruction, because specifying the default action relies on making assumptions about what the default action will be on the target PC. Since this is user-changeable, this is not a safe assumption. I have found that specifying "merge" as the action in this case doesn't work - despite the fact that there is a shell action called "merge" for Regedit, AND "merge" is the default action. Anyone know why?
The action name is open, the action display name is Mer&ge...

and Mer&ge looks like "Merge".
pushing g will click that command.
&& = "&"