Solved

Getting errors when trying to build a VB Script to remove IE Headers and Footers

Posted on 2008-10-17
7
1,000 Views
Last Modified: 2008-11-07
I have built a VB Script for removing IE headers and footer for printing but it is not working and I can't see why. I have pasted below what the script is. I know it is saying the registry key is not there but it is. I have also pasted below the exported reg key so you can see what I want to remove.

If someone can either show me the change, write the script down or amend it for me would be great thanks

Option Explicit
 
Dim oShell
 
Private Function KeyExists (keyName)
        Dim bKey
               
        On Error Resume Next
 
        bKey = oShell.RegRead(keyName)
 
        If TypeName (bKey) = "Empty" Then
                KeyExists = False
        Else
                KeyExists = True
        End If
End Function
 
 
 
Set oShell = CreateObject("Wscript.Shell")
 
If keyExists("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\header") Then
   oshell.RegWrite " HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\header",  , "REG_SZ"
Else
   wscript.echo "Key exists"
End If

Set oShell = CreateObject("Wscript.Shell")

If keyExists("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\footer") Then
   oshell.RegWrite " HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\footer", , "REG_SZ"
Else
   wscript.echo "Key empty"
End If

Set oShell = Nothing


Ok this is the exported reg file with what needs to be amended

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup]
"header"="I want to clear this"
"footer"="I want to clear this"
"margin_bottom"="0.750000"
"margin_left"="0.750000"
"margin_right"="0.750000"
"margin_top"="0.750000"


Hope you can help thanks.

P.s Here is the error message from VBscript below

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

\\Setanta\NETLOGON\Resources\IEHeaderFooters\removeITheader.vbs(24, 4) WshShell.RegWrite: Invalid root in registry key " HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\header".


***** script completed *****



0
Comment
Question by:Stevenpj
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Hubasan
ID: 22740005
I believe the problem is an assignment of your root registry keys.

Place this on top of your script:

Const HKEY_CLASSES_ROOT = &h80000000
Const HKEY_CURRENT_USER = &h80000001
Const HKEY_LOCAL_MACHINE = &h80000002
Const HKEY_USERS = &h80000003
Const HKEY_CURRENT_CONFIG = &h8000000

These constants will define your root registry keys with their corresponding HEX values.
0
 
LVL 7

Expert Comment

by:Hubasan
ID: 22740028
You just need the constant for HKEY_CURRENT_USER, but It's a good practice to put them all since you might want to manipulate other reg keys in the same script in the future.
Also make sure that spelling of the root reg key is exactly the same as in the constant.
0
 
LVL 7

Accepted Solution

by:
Hubasan earned 500 total points
ID: 22740742
Small correction to the last Root key in the above post, for HKEY_CURRENT_CONFIG.

Const HKEY_CURRENT_CONFIG = &h80000005
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:Stevenpj
ID: 22784608
sorry been away.. that is great thanks. I will get back to you on this asap
0
 

Author Comment

by:Stevenpj
ID: 22784904
is this correct

Const HKEY_CLASSES_ROOT = &h80000000
Const HKEY_CURRENT_USER = &h80000001
Const HKEY_LOCAL_MACHINE = &h80000002
Const HKEY_USERS = &h80000003
Const HKEY_CURRENT_CONFIG = &h80000005


Option Explicit
 
Dim oShell
 
Private Function KeyExists (keyName)
        Dim bKey
               
        On Error Resume Next
 
        bKey = oShell.RegRead(keyName)
 
        If TypeName (bKey) = "Empty" Then
                KeyExists = False
        Else
                KeyExists = True
        End If
End Function
 
 
 
Set oShell = CreateObject("Wscript.Shell")
 
If keyExists("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\header") Then
   oshell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\header", "" , "REG_SZ"
Else
   wscript.echo "Key exists"
End If

Set oShell = CreateObject("Wscript.Shell")

If keyExists("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\footer") Then
   oshell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\footer", "" , "REG_SZ"
Else
   wscript.echo "Key empty"
End If

Set oShell = Nothing
0
 

Author Comment

by:Stevenpj
ID: 22784965
ok need your help here explaining this please

Also make sure that spelling of the root reg key is exactly the same as in the constant.
0
 
LVL 7

Expert Comment

by:Hubasan
ID: 22904116
Hi Stevenpi,

Sorry i didn't see your posts from earlier, which is interesting since I always get a notification email, especially when monitoring the question?!?
Thank you for your points, and please let me know if you still need help with this...
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Learn about cloud computing and its benefits for small business owners.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question