News, tips, advice, support for Windows, Office, PCs & more. Tech help. No bull. We're community supported by donations from our Plus Members, and proud of it
Home icon Home icon Home icon Email icon RSS icon
  • Add Preview handlers for script files

    Posted on Rick Corbett Comment on the AskWoody Lounge

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

    Tagged: ,

    This topic contains 2 replies, has 3 voices, and was last updated by  Oldun 4 months, 1 week ago.

    • Author
      Posts
    • #400716 Reply

      Rick Corbett
      AskWoody_MVP

      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…

      Attachments:
      1 user thanked author for this post.
    • #420669 Reply

      Paul T
      AskWoody MVP

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

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

      cheers, Paul

    • #472250 Reply

      Oldun
      AskWoody Lounger

      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

    Please follow the -Lounge Rules- no personal attacks, no swearing, and politics/religion are relegated to the Rants forum.

    Reply To: Add Preview handlers for script files

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