Solved

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

Posted on 2008-10-17
7
997 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now