• Add Preview handlers for script files

    Home » Forums » Developers, developers, developers » DevOps Lounge » Add Preview handlers for script files

    • This topic has 2 replies, 3 voices, and was last updated 6 years ago.
    Author
    Topic
    #400716

    If you’re not careful about naming your scripts then it’s often helpful to be able to ‘preview’ them from within (File) Explorer rather than have to open them in an editor.

    Here’s a QAD (Quick and Dirty) method of adding a Preview handler for different script types:

    1. Open the Registry Editor (using Run as administrator).

    2. Navigate (for example) to HKEY_CLASSES_ROOT\.ps1 and select it in the left-hand navigation pane.

    3. In the right-hand pane, right-click and choose the option New > String value.

    4. Rename the New Value #1 entry to PerceivedType.

    5. Modify the entry’s Data value to text.

    preview_handler01

    That’s it.

    To test, navigate within (File) Explorer and select a PowerShell .ps1 file. Use ALT+p to turn on the Preview pane.

    preview_handler02

    I’ve added preview handlers for .PS1, .AHK and .VBS files in both Win 10 and Win 7 so far (as these are all that I normally use).

    Note: I found that I couldn’t just import a REG file with the settings, either by double-clicking on a REG file or even running REGEDIT as Administrator and importing the REG file. I saw all the ‘normal’ prompts and messages that the import was successful… but nothing changed in the registry. The manual method is so quick that I haven’t (yet) looked into whether I can script the addition of the required entry.

    Hope this helps…

    1 user thanked author for this post.
    Viewing 1 reply thread
    Author
    Replies
    • #420669

      Or right click on the file and Select “Open in Notepad++”.

      What do you mean you don’t have Notepad++ installed?

      cheers, Paul

    • #472250

      You can add to the registry in an elevated PoweShell window (or in a script), like this:

      $reg = @{
      Path         = 'Registry::HKCR\.ps1'
      Name         = 'PerceivedType'
      PropertyType = 'String'
      Value        = 'text'
      Force        = $true
      }
      New-ItemProperty @reg
      

      Oldun

    Viewing 1 reply thread
    Reply To: Add Preview handlers for script files

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: