Solved

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

Posted on 2008-10-17
7
1,002 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I comeā€¦
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

726 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