View Full Version : need help with WScript.Shell in a .hta file

08-23-2004, 01:15 PM
hi peeps! :thumbsup:

i need to read the registry to see if content adviser is enabled..

the problem is that i get an error if there is nothing in that key :(

alert (WshShell.RegRead("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\policies\\Ratings"));

if that key has a value thats ok - but if not i get an error saying it cant be read... i just need to set a variable to yes/no depending on whether its blank or not... it seems stupid to me. surely if its blank then just return an empty string?!?!?! HELP plz :confused:

08-23-2004, 04:05 PM
Haven't worked with registry keys but have you tried...

if (regkey){alert(regkey)}

08-23-2004, 05:33 PM
nope :(

the problem is if you try and read a key that has no value you get the error... its stupid logic really...

i get a similar thing when trying to delete registry entries... if there isnt a value it wont let you delete them (i.e. ignore them if not there and delete if they are!) so i have to create a blank entry then delete it... arghhh @ micro$lop :rolleyes:

08-23-2004, 06:05 PM
arghhh @ micro$lop

hey, don't dis the mighty microsoft coders ... see how helpful they are these days, working extra hours to give us yet another free update to their software. how many other companies do you know that release new versions of their software every so often.

sloppy indeed, just dilligent, i say. ;)

08-23-2004, 06:07 PM
fair point... although they arent technically giving more as fixing really.... :)

although look at ahead etc for upgrading the likes of nero etc..

08-23-2004, 11:13 PM
fair point... although they arent technically giving more as fixing really

i was actually being sarcastic.

of course, their code is sloppy. SP2 is witness to that. no sooner has it been released, but there are already a fresh batch of security issues discovered.

the problem with Windows, however, is not necessarily the people that work on it, but the man at the healm. it's essentially Bill Gates' greed which stops them from building a new OS from scratch, not just building on the same mistakes as before. i should know, i work a firm which has done the same thing. when will they ever learn??

anyway, we digress ... :p

08-24-2004, 07:19 AM
alert (WshShell.RegRead("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\policies\\Ratings"));

Try putting it inside the try-catch block.

var rating = "";
try {
rating = WshShell.RegRead("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\policies\\Ratings");
//ignore error, rating is already initialized to empty
if (contentAdv!=""){
alert("Content Advisor has a rating of: " + contentAdv);
else {
alert("No rating.");

08-24-2004, 11:11 AM
arghhhhhhhh... i was just going to poast that i fixed it... why didnt i get an email from this system? :(

try { //checks to see if content advisor has already been removed - if not you need to restart IE to take affect
var key = WshShell.RegRead("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\policies\\Ratings\\.Default\\Enabled");

catch (e) {
if (e != 0) {
alert("Error: " + e + " Entry doesn't exists");

if (key=="1") {
alert("When this is fixed you will need to restart ALL instances of Internet Explorer for changes to take affect");

thanks tho m8e... i cant believe how easy this was in the end... it took me about 5 hours of solid exploration till i found this simple solution

thanks tho m8! :thumbsup: :thumbsup: :thumbsup: