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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing registry settings in VBS (hex) 1

Status
Not open for further replies.

MCubitt

Programmer
Mar 14, 2002
1,081
GB
I am trying to write vbs to write regigstry settings. Not sure on how to do this though, the hex looks odd!

What i want written:
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file]
@="Zetafax FAX image"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\open]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\open\command]
@=hex(2):22,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20, 00,46,00,69,00,6c,00,65,00,73,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00, 73,00,20,00,4e,00,54,00,5c,00,41,00,63,00,63,00,65,00,73,00,73,00,6f,00,72, 00,69,00,65,00,73,00,5c,00,49,00,6d,00,61,00,67,00,65,00,56,00,75,00,65,00, 5c,00,4b,00,6f,00,64,00,61,00,6b,00,49,00,6d,00,67,00,2e,00,65,00,78,00,65, 00,22,00,20,00,22,00,25,00,31,00,22,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\preview]
@="Pre&view"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\preview\command]
@=hex(2):22,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20, 00,46,00,69,00,6c,00,65,00,73,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00, 73,00,20,00,4e,00,54,00,5c,00,41,00,63,00,63,00,65,00,73,00,73,00,6f,00,72, 00,69,00,65,00,73,00,5c,00,49,00,6d,00,61,00,67,00,65,00,56,00,75,00,65,00, 5c,00,4b,00,6f,00,64,00,61,00,6b,00,50,00,72,00,76,00,2e,00,65,00,78,00,65, 00,22,00,20,00,22,00,25,00,31,00,22,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\print]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\print\command]
@=hex(2):22,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20, 00,46,00,69,00,6c,00,65,00,73,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00, 73,00,20,00,4e,00,54,00,5c,00,41,00,63,00,63,00,65,00,73,00,73,00,6f,00,72, 00,69,00,65,00,73,00,5c,00,49,00,6d,00,61,00,67,00,65,00,56,00,75,00,65,00, 5c,00,4b,00,6f,00,64,00,61,00,6b,00,49,00,6d,00,67,00,2e,00,65,00,78,00,65, 00,22,00,20,00,2f,00,70,00,20,00,22,00,25,00,31,00,22,00,00,00




What I have in VBS so far...
' Write registry entries
Dim WshShell
Set WshShell = CreateObject ("WScript.Shell")
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file", "Zetafax FAX image"
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell", ""
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\open", ""
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\open\command", "

and here I get stuck!

Any help, please?



There's no need for sarcastic replies, we've not all been this sad for that long!
 
This should get you over the hurdle...

Code:
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\G3F_auto_file\shell\open\command", "22,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\00,46,00,69,00,6c,00,65,00,73,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,\73,00,20,00,4e,00,54,00,5c,00,41,00,63,00,63,00,65,00,73,00,73,00,6f,00,72,\00,69,00,65,00,73,00,5c,00,49,00,6d,00,61,00,67,00,65,00,56,00,75,00,65,00,\5c,00,4b,00,6f,00,64,00,61,00,6b,00,49,00,6d,00,67,00,2e,00,65,00,78,00,65,\00,22,00,20,00,22,00,25,00,31,00,22,00,00,00", "REG_BINARY"

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hello MCubitt,

What I do not see very clearly is what environment variable does your system have in regard to any folder within the chain:
C:\Program Files\Windows NT\Accessories\...

Can you post back this info?

Otherwise, I can do with stright expanded command like this:
Code:
sroot="HKEY_CURRENT_USER\End-user_testing\"
skey="SOFTWARE\Classes\G3F_auto_file\"

cmdopen=chr(34) & "C:\Program Files\Windows NT\Accessories\Image Vue\KodakPrv.exe" & chr(34) & " " & chr(34) & "%1" & chr(34)
cmdpreview=chr(34) & "C:\Program Files\Windows NT\Accessories\Image Vue\KodakPrv.exe" & chr(34) & " " & chr(34) & "%1" & chr(34)
cmdprint=chr(34) & "C:\Program Files\Windows NT\Accessories\Image Vue\KodakPrv.exe" & chr(34) & " /p " & chr(34) & "%1" & chr(34)

set wshshell=createobject("wscript.shell")

wshshell.regwrite sroot & skey, "Zetafax FAX image", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\open\command\", cmdopen, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\preview\","Pre&view", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\preview\command\", cmdpreview, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\print\command\", cmdprint, "REG_EXPAND_SZ"

set wshshell=nothing
With the above the task would be completed. Just a slight sacrifice on generality of using the environment variable if you have one custom-made.

regards - tsuji

ps Hello markdmac, if you don't mind, I have to point out (once again because I think I did it once at least) that regwrite would fail for reg_binary longer than double words (4 bytes long)---limited by design to-date. You've to use stdregprov or simple import .reg for long binary.
 
Correction:

The sroot meant to be a testing environment I'm prepared to test out. Hence, for your use, change it to the hive you specified.
Code:
'sroot="HKEY_CURRENT_USER\End-user_testing\"  '[red]replaced[/red]
sroot="HKEY_LOCAL_MACHINE\"
- tsuji
 
Hello again - sorry for the delay, I could not find this box, had to scroll a mile right!

Anyway, tsuji thank you very much for your code which worked (ish). Had to tweak a little but is now ok:

sroot="HKEY_LOCAL_MACHINE\"
skey="SOFTWARE\Classes\.G3F\"

cmdopen=chr(34) & "C:\Program Files\Windows NT\Accessories\ImageVue\KodakPrv.exe" & chr(34) & " " & chr(34) & "%1" & chr(34)
cmdpreview=chr(34) & "C:\Program Files\Windows NT\Accessories\ImageVue\KodakPrv.exe" & chr(34) & " " & chr(34) & "%1" & chr(34)
cmdprint=chr(34) & "C:\Program Files\Windows NT\Accessories\ImageVue\KodakPrv.exe" & chr(34) & " /p " & chr(34) & "%1" & chr(34)

set wshshell=createobject("wscript.shell")

wshshell.regwrite sroot & skey, "Zetafax FAX image", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\open\command\", cmdopen, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\preview\","Pre&view", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\preview\command\", cmdpreview, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\print\command\", cmdprint, "REG_EXPAND_SZ"

set wshshell=nothing

msg=msgbox("Zetafax Preview installed successfully",0,"Zetafax Preview Installer")


Now, very quickly, how would I go about checking if an association already existed? I.e. Check, if there, skip.

Would retrieving "SOFTWARE\Classes\.G3F\" suffice? Ie if present = exists.

Many thanks




There's no need for sarcastic replies, we've not all been this sad for that long!
 
Having problems reading the registry. I tried this:
.
.
.
chk=wshshell.regread(sroot & skey)

select case(chk)
case "Zetafax FAX image"
msg=msgbox("Zetafax preview is already installed.",0,"Zetafax Preview Installer")
case ""
wshshell.regwrite sroot & skey, "Zetafax FAX image", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\open\command\", cmdopen, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\preview\","Pre&view", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\preview\command\", cmdpreview, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\print\command\", cmdprint, "REG_EXPAND_SZ"
msg=msgbox("Zetafax preview successfully installed.",0,"Zetafax Preview Installer")
case else
msg=msgbox("G3F file extension already associated as" & chk,0,"Zetafax Preview Installer")
end select

But the read fails,
Unable to open registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.G3F\"

It does exist, since in Regedit, if I were to export the branch I see:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.G3F

I am signed on as Admin so not permissions.

Any ideas, please?



There's no need for sarcastic replies, we've not all been this sad for that long!
 
MCubitt,

[1] Verify if association existing
I think it is good in principle to read all the vital keys to draw conclusion that the intended associations do exist. But, you practically need to read all the keys to .regwrite to assure this fact. Hence, the simplest if to write it all disregards whether there exist associations and that the associations are exactly what we like to set. Hence, I do not think it is a top priority. (We can come back to it later.)

[2] The associations
What I'm worrying about is the "tweak" you come up with. The association is established by this structure.
[HKLM\Software\Classes\.G3F]
@="G3F_auto_file"
Then, from this info, you look into this.
[HKLM\Software\Classes\G3F_auto_file] <<the key info from above .G3F default setting
@="ZetaFax_...etc"
[...\G3F_auto_file\shell\open] << open is one of the action...etc
[...\G3F_auto_file\shell\open\command]
@="..." <<this is the command line reg_expand_sz
etc
Your latest postings do not seem to be right?

What do you say?

- tsuji
 
Hi again,

The original script did not create .G3F and hence there was no association at all. The script does work.

I agree with what you say about the reading of the keys, but I cannot even read 1 yes and yes, it does exist.




There's no need for sarcastic replies, we've not all been this sad for that long!
 
MCubitt,

What I am sure is that it is not accepted structure. Even if it works it will put you in a very difficulty when it comes to maintain.

I suggest you test this out.
[1] Use the original posting's registry structure.
[2] Add this line to it at the top.
skey2="SOFTWARE\Classes\.G3F\"
wshshell.regwrite sroot & skey2,"G3F_auto_file","REG_SZ"

I relist my proposed code:
Code:
sroot="HKEY_LOCAL_MACHINE\"
skey="SOFTWARE\Classes\G3F_auto_file\"
skey2="SOFTWARE\Classes\.G3F\"

cmdopen=chr(34) & "C:\Program Files\Windows NT\Accessories\Image Vue\KodakPrv.exe" & chr(34) & " " & chr(34) & "%1" & chr(34)
cmdpreview=chr(34) & "C:\Program Files\Windows NT\Accessories\Image Vue\KodakPrv.exe" & chr(34) & " " & chr(34) & "%1" & chr(34)
cmdprint=chr(34) & "C:\Program Files\Windows NT\Accessories\Image Vue\KodakPrv.exe" & chr(34) & " /p " & chr(34) & "%1" & chr(34)

set wshshell=createobject("wscript.shell")

wshshell.regwrite sroot & skey2, "G3F_auto_file", "REG_SZ"
wshshell.regwrite sroot & skey, "Zetafax FAX image", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\open\command\", cmdopen, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\preview\","Pre&view", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\preview\command\", cmdpreview, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\print\command\", cmdprint, "REG_EXPAND_SZ"

set wshshell=nothing
-tsuji

ps. If you have read issue can you open a new thread. I get so tire scrolling around!
 
Interestingly enough, it worked (the read) on another PC which had been used to create the association using the script. The difference between it and my PC, for the exported registry is as follows:

One that works:
[HKEY_LOCAL_MACHINE\SOFTWARE\\Classes\.G3F]

My one:
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.G3F]

Not sure if that is a red herring because when you CLICK on the registry key (left pane) both shows with single \ throughout.




There's no need for sarcastic replies, we've not all been this sad for that long!
 
MCubitt,

I think you should not imagine thing (or else I may have a lesson to take from your observation) just because something for the moment is not working. [...\\Classes\...] is definitely out of the line except you've the author explain its intention.

- tsuji
 
Ok, sorry I did not entirely understand the question.

Anyway, the script will only be used by about 10 people and is a one off, because I don't want them to have to do it manually (wish I had, now!)

The final script (not perfect, not fool proof) is:

sroot="HKEY_LOCAL_MACHINE\"
skey="SOFTWARE\Classes\G3F_auto_file\"
skey2="SOFTWARE\Classes\.G3F\"


cmdopen=chr(34) & "C:\Program Files\Windows NT\Accessories\ImageVue\KodakPrv.exe" & chr(34) & " " & chr(34) & "%1" & chr(34)
cmdpreview=chr(34) & "C:\Program Files\Windows NT\Accessories\ImageVue\KodakPrv.exe" & chr(34) & " " & chr(34) & "%1" & chr(34)
cmdprint=chr(34) & "C:\Program Files\Windows NT\Accessories\ImageVue\KodakPrv.exe" & chr(34) & " /p " & chr(34) & "%1" & chr(34)

set wshshell=createobject("wscript.shell")
chk=wshshell.regread(sroot & skey2 & "shell\open\command\")
chkkodak=-1
if chk <> "" then chkkodak = instr(ucase(chk), "KODAKPRV.EXE")
select case(chkkodak)
case 0
msg=msgbox("G3F file extension already associated with " & chk,0,"Zetafax Preview Installer")
case -1
wshshell.regwrite sroot & skey2, "G3F_auto_file", "REG_SZ"
wshshell.regwrite sroot & skey, "Zetafax FAX image", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\open\command\", cmdopen, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\preview\","Pre&view", "REG_SZ"
wshshell.regwrite sroot & skey & "shell\preview\command\", cmdpreview, "REG_EXPAND_SZ"
wshshell.regwrite sroot & skey & "shell\print\command\", cmdprint, "REG_EXPAND_SZ"
msg=msgbox("Zetafax preview successfully installed.",0,"Zetafax Preview Installer")
case else
msg=msgbox("Zetafax preview is already installed.",0,"Zetafax Preview Installer")
end select

set wshshell=nothing


Thanks for your help, indeed.


There's no need for sarcastic replies, we've not all been this sad for that long!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top