Question Trying to remove IE Header & Footer but i'm getting a NullReferenceException.. help?

SpykeYs

New member
Joined
Feb 16, 2009
Messages
1
Programming Experience
Beginner
Trying to remove IE Header & Footer but i'm getting a NullReferenceException.. help?

Hey Guys,

I am trying to get rid of the IE added header and footer such as Page Title, Page 1 of 1, Url, Etc..

I am using the following code. My goal is when a user click on the PRINT button within my application, I would call SetIEON, print the page and SetIEOff.

However, when my code gets to SetIEOn at

Dim oKey As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable)
oKey.SetValue(strName, oValue)

it crashes with a NullReferenceException. Any idea why ? I'm using VS 2008 .NET 2.0

See code below.

'Removing the header and footer in the Windows Registry

Public Sub SetIEOn()
Dim strKey As String = "Software\Microsoft\Internet Explorer\PageSetup"
Dim bolWritable As Boolean = True
Dim strName As String = "footer"
Dim oValue As Object = ""
Dim oKey As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable)
oKey.SetValue(strName, oValue)
strName = "header"
oValue = ""
oKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable)
oKey.SetValue(strName, oValue)
oKey.Close()
End Sub

'Adding the header and footer in the Windows Registry
Public Sub SetIEOff()
Dim strKey As String = "Software\Microsoft\Internet Explorer\PageSetup"
Dim bolWritable As Boolean = True
Dim strName As String = "footer"
Dim oValue As Object = "&u&b&d"
Dim oKey As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable)
oKey.SetValue(strName, oValue)
strName = "header"
oValue = "&w&bPage &p of &P"
oKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable)
oKey.SetValue(strName, oValue)
oKey.Close()
End Sub

Thanks so much!!!!
Peter
 
I'm pretty sure that this won't actually work (the latest version of IE doesn't use these settings and I'm not sure you can change them on the fly anyway) but the code runs absolutely fine on my machine. Are you running on an admin account with UAC turned off?
 

Latest posts

Back
Top