THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Rob Farley

- Owner/Principal with LobsterPot Solutions (a MS Gold Partner consulting firm), Microsoft Certified Master, Microsoft MVP (SQL Server), APS/PDW trainer and leader of the SQL User Group in Adelaide, Australia. Rob is a former director of PASS, and provides consulting and training courses around the world in SQL Server and BI topics.

PowerShell - grabbing values out of the registry and running them

So I closed an application that runs when Windows starts up, but it doesn’t have a Start Menu entry, and I was trying to find it.

Ok, I could’ve run regedit.exe, navigated through the tree and found the list of things that run when Windows starts up, but I thought I’d use PowerShell instead.

PowerShell presents the registry as if it’s a volume on a disk, and you can navigate around it using commands like cd and dir.

It wasn’t hard to find the folder I knew I was after – tab completion (starting the word and then hitting the Tab key) was a friend here. But unfortunately dir doesn’t list values, only subkeys (which look like folders).

PS C:\Windows\system32> dir HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
PS C:\Windows\system32>

Instead, I needed to use Get-Item to fetch the ‘Run’ key, and use its Property property. This listed the values in there for me, as an array of strings (I could work this out using Get-Member).

PS C:\Windows\system32> (Get-Item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run).Property
Zune Launcher
PS C:\Windows\system32>

Ok, so the thing I wanted wasn’t in there (an app called PureText, whicih lets me Paste As Text using Windows+V). That’s ok – a simple change to use HKCU instead of HKLM (Current User instead of Local Machine), and I found it.

Now to fetch the details of the application itself, using the RegistryKey method GetValue

PS C:\Windows\system32> (Get-Item HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run).GetValue('PureText')
PS C:\Windows\system32>

And finally, surrounding it in a bit of code to execute that command. That needs an ampersand and the Invoke-Expression cmdlet.

PS C:\Windows\system32> '& ' + (Get-Item HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run).GetValue('PureText') | Invoke-Expression

A simple bit of exploring PowerShell which will makes for a much easier way of finding and running those apps which start with Windows.

Published Tuesday, June 12, 2012 8:08 PM by Rob Farley
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



Phil Carter said:

Nice Rob.

Also good to see someone else lives with PureText :)

June 12, 2012 7:04 AM

Robert Sterbal said:

Autoruns is a nice app that can also be used

June 17, 2012 10:02 PM

Tyler Harnach said:

Thanks Rob! This kind of registry manipulation with powershell is just what I was looking for!

April 1, 2013 2:41 PM

Rob Farley said:

Hi Milla,

It depends very much on what your definition of 'quote' is. You can certainly refer to my articles, but I would rather you didn't just copy the whole thing word-for-word.


December 11, 2014 9:13 PM

Leave a Comment


This Blog



News? Haven't you read my blog?

My Company

Can't find something?

Contact Me

Twitter: @rob_farley
Skype: rob_farley

MVP (SQL Server)


Adelaide SQL UG

Privacy Statement