Hi, I don't know if that is the right forum... I was searching a forum for WSH (Windows Scripting Hosting)..
I have the following problem: I use a WSH in order to read the value of a registry (showed by start-run-"regedit"). When the registry doesn't exist at all, I get a dialog window message (a kind of error reporting " the registry... doesn't exist.. ect...). I want absolutely avoid to get this dialog window message. An idea could be to use a WSH script in order to verify, before the reading, if a registry exists, but which is the WSH script in order to do that?
Thank You In Advance
Fausto
What do you mean the registry does not exist? The registry always exists, windows can't run without it...
I'm sorry, I wasn't clear... as you know you can add (or delete or modify) an item ofthe registry by regedit. Try to think that you create a new item and then you try to read it by a WSH script (command "RegRead"). If the item exist... no problem, you will get the value of the item.
Then try to delete by regedit the item you created and try to read again it by a WSH script (always command "RegRead"). Because the item doesn't exist anymore, you will get a dialog window message with an error reporting " the registry... doesn't exist.. ect..." .
I need to avoid that, when the my application try to read a precise item of the registry, and that precise item doesn't exist (for various reasons), I DON'T get any dialog window message with the error " the registry... doesn't exist.. ect..."; I need that no messages are sent to the screen.
Thank You in Advance
Fausto
Hmm.. Hard to say. In VB you might do something like:
set Shell = WScript.CreateObject("WScript.Shell")
on error resume next ' Turn on error checking.
Shell.RegDelete("....")
errnum = err.number ' Get # and name of error.
errname = err.description
on error goto 0 ' Turn off error checking. This also does 'err.clear'.
However, I am not sure if this will work, or if you are using a different language, if there is a similar feature in those. Not sure how or if others provide this, though I expect Python would, but that isn't part of WSH. lol In any case, the above, assuming it works, should trap any errors caused by trying to find/delete a key that doesn't exist. That should also prevent the dialog, but I can't be 100% certain that I am right, it may generate a dialog anyway. :( I just don't know what the result will be, but for some things it does work, so...
Hi again,
first of all thanks for your help...
second, I have to say that I'm not expert at all, then sorry if my questions could be a little bit ingenuos.
I used the VSH scripts only why I needed the simple operation to read an item of the registry: I simply installed the application "Scripten.exe" and then I used a simple script that I found out on internet... without knowing the language...
Therefore I don't know wich is exactly the difference between WSH and VBscript; I thought simply that WSH commands were a subset of Vbscript commands...
By the way... I tried the your code, with some modifications:
"
set Shell = WScript.CreateObject("WScript.Shell");
on error resume next;
Shell.RegRead("....");
var errnum = err.number;
var errname = err.description;
on error goto 0;
"
but I get some errors: I suppose that the words "error, resume, next" are not recognised.
At this point I should think that I could use directly the VBscript instead of the WSH, so your code could work properly... but What I have to do?
Do I have to install a different application from "Scripten.exe"? Or may be I was simply wrong in something in the code?
Thank You in Advance
Fausto
If you have ; in there, then you are using Javascript, not VBScript. It unfortunately has no built in way to trap these errors that I know of. I am afraid someone else will have to try to help you. :p
Hi again,
I solved the problem... I used a VBscript instead a JSscript (I discovered that the WSH could be write in both the languages... and I used Js); then I used the your code and it works...
Thank You again and bye
Fausto