Solved

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

Posted on 2008-10-17
7
999 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running Visio Macro from VBS File 3 58
Enable Intel-VT on a IBM Yoga 7 30
Can we place a tooltip on the actual vb6 form 5 35
DHCP server 6 49
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

21 Experts available now in Live!

Get 1:1 Help Now