?
Solved

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

Posted on 2008-10-17
7
Medium Priority
?
1,005 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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