Conveniently Starting New Scripts..VBS Help?

by Sep 3, 2012

I am a DOS power user.  I now have a need(don't have the desire) to become a PowerShell power user.  I am hoping to not only get help from this site, but provide help in the future.

I purchased WINDOWS SCRIPTING SECRETS by Weltner, and am trying to run the script on page 6, but I get this error message:


From the script posted below,

here is line 16: WSHShell.RegWrite "HKCR" & prg & "", prgname

Here are the lines for setting  prg:  prg = ReadReg("HKCR" & filetype & "")

                               and  prgname:  prgname = ReadReg("HKCR" & prg & "")


Grateful for any help to get me past the first script here.  Not sure where I went wrong. 

Weltner book makes it difficult to check your typing by not providing line numbers in his scripts(although he recommends use of an editor with line number labeling), and he doesn't provide any checksums either like total # of words, or # of characters to double check my typing.  I also bought this book with the impression it would be a powershell book.  But now I am confused by the Visual Basic Shell references.


Page 6 Script

' 1-1.VBS

' this is the file extension the new command
' should generate:
filetype = ".vbs"
' connect to WScript.Shell for registry access:

set WSHShell = CreateObject("WScript.Shell")
' read in the name of the vbs-section:
prg = ReadReg("HKCR" & filetype & "")
' read in the official name for vbs-files:
prgname = ReadReg("HKCR" & prg & "")

' ask for a new name
ask = "What should be the name for new VBScript scripts?"
title = "New menu entry"
prgname = InputBox(ask, title, prgname)
' save the new program description:

'Line 16 Next

WSHShell.RegWrite "HKCR" & prg & "", prgname
' add a New menu entry asking for an empty new file:
WSHShell.RegWrite "HKCR" & filetype & "ShellNewNullFile", ""
' reads a registry key
' should the key be invalid, complain and stop:

function ReadReg(key)
on error resume next
ReadReg = WSHShell.RegRead(key)
if err.Number>0 then
' key could not be read: complain!

error = "Error: Registry-Key """ & key _
& """ could not be found!"
MsgBox error, vbCritical
end if
end function