Using vbs script to set IE’s printing header and footers

Time:2021-7-2

Save the following content as a. VBS file, then double-click to execute, open the IE page, right-click in the page to see what’s more in the menu!:)  

    

Copy codeThe code is as follows:
option explicit 

    dim hkey_root,hkey_path,hkey_key,filepath 
    dim fs,fso,regwsh 

    hkey_root=”hkey_current_user” 
    hkey_path=”\software\microsoft\internet explorer” 

    // Create a file first  
    set fs=wscript.createobject(“scripting.filesystemobject”) 
    filepath=”c:\pagesetup_default.htm” 
    set fso=fs.createtextfile(filepath,true) 
    fso.write(“<script language=””vbscript””>”+vbcrlf _ 
            +”dim hkey_root,hkey_path,hkey_key,filepath,regwsh” +vbcrlf _ 
            +”hkey_root=””hkey_current_user””” +vbcrlf _ 
            +”hkey_path=””\software\microsoft\internet explorer””” +vbcrlf _ 
            +”filepath=””c:\pagesetup_null.htm””” +vbcrlf _ 
            +”// Set the header and footers of web page printing to the default value “+ vbcrlf”   _ 
            +”set regwsh = createobject(“”wscript.shell””)” +vbcrlf _ 
            +”hkey_key=””\pagesetup\header””” +vbcrlf _ 
            +” regwsh.regwrite   hkey_ root+hkey_ path+hkey_ Key, “& W & bpage: & P / & P”“  + vbcrlf  _ 
            +”hkey_key=””\pagesetup\footer””” +vbcrlf _ 
            +”regwsh.regwrite hkey_root+hkey_path+hkey_key,””&u&b&d””” +vbcrlf _ 
            +”// Set the display text on the right-click menu“  + vbcrlf  _ 
            +”// First delete the original item, and then set the new item “+ vbcrlf”   _ 
            +”on error resume next” +vbcrlf _ 
            +” hkey_ key=hkey_ root+hkey_ Path + “” restore header and footers on print \ ““  + vbcrlf  _ 
            +”regwsh.regdelete hkey_key” +vbcrlf _ 
            +” hkey_ key=hkey_ root+hkey_ Remove header and footers when printing“  + vbcrlf  _ 
            +”regwsh.regwrite hkey_key,filepath” +vbcrlf _ 
            +”// Close regwsh“  + vbcrlf  _ 
            +”set regwsh=nothing”+vbcrlf  _ 
        +”</script>”) 
    fso.close 

    filepath=”c:\pagesetup_null.htm” 
    set fso=fs.createtextfile(filepath,true) 
    fso.write(“<script language=””vbscript””>” +vbcrlf _ 
            +”dim hkey_root,hkey_path,hkey_key,filepath,regwsh” +vbcrlf _ 
            +”hkey_root=””hkey_current_user””” +vbcrlf _ 
            +”hkey_path=””\software\microsoft\internet explorer””” +vbcrlf _ 
            +”filepath=””c:\pagesetup_default.htm””” +vbcrlf _ 
            +”// Set the header and footers of web page printing to be empty“  + vbcrlf  _ 
            +”set regwsh =createobject(“”wscript.shell””)” +vbcrlf _ 
            +”hkey_key=””\pagesetup\header””” +vbcrlf _ 
            +”regwsh.regwrite hkey_root+hkey_path+hkey_key,””””” +vbcrlf _ 
            +”hkey_key=””\pagesetup\footer””” +vbcrlf _ 
            +”regwsh.regwrite hkey_root+hkey_path+hkey_key,””””” +vbcrlf _ 
            +”// Set the display text on the right-click menu“  + vbcrlf  _ 
            +”// First delete the original item, and then set a new one“  + vbcrlf  _ 
            +”on error resume next”+vbcrlf  _ 
            +” hkey_ key=hkey_ root+hkey_ Remove header and footers when printing“  + vbcrlf  _ 
            +”regwsh.regdelete hkey_key”+vbcrlf  _ 
            +” hkey_ key=hkey_ root+hkey_ Path + “” restore header and footers on print \ ““  + vbcrlf  _ 
            +”regwsh.regwrite hkey_key,filepath” +vbcrlf _ 
            +”// Close regwsh“  + vbcrlf  _ 
            +”set regwsh=nothing”+vbcrlf  _ 
        +”</script>”) 
    fso.close 

    set regwsh=wscript.createobject(“wscript.shell”) 
     hkey_ key=hkey_ root+hkey_ Path + “- remove header and footers when printing”  
    regwsh.regwrite hkey_key,”c:\pagesetup_null.htm” 

The above information is an integral part of the article. If you want to reprint this article, please keep the above information. Thank you!