Monday, June 1, 2009

Working with Registry in Powershell

Microsoft has made registry accessing very simple using powershell. You can access the system registry just like any other drive in powershell.

For example, you can easily list all the registry entries in HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run registry key with Get-ItemProperty cmdlet


PS C:\> cd HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
PS HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run> Get-ItemProperty .

RTHDCPL : RTHDCPL.EXE
Alcmtr : ALCMTR.EXE
IgfxTray : C:\WINDOWS\system32\igfxtray.exe
HotKeysCmds : C:\WINDOWS\system32\hkcmd.exe
Persistence : C:\WINDOWS\system32\igfxpers.exe

PS HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run>

You can add a new entry to registry key using New-ItemProperty cmdlet

I have just added a entry to HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run to autostart notepad.exe on the windows boot-up


PS C:\> New-ItemProperty -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run -name "Notepad" -value "C:\WINDOWS\NOTEPAD.EXE" -type string

Notepad
-------
C:\WINDOWS\NOTEPAD.EXE

PS C:\> Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

RTHDCPL : RTHDCPL.EXE
Alcmtr : ALCMTR.EXE
IgfxTray : C:\WINDOWS\system32\igfxtray.exe
HotKeysCmds : C:\WINDOWS\system32\hkcmd.exe
Persistence : C:\WINDOWS\system32\igfxpers.exe
Notepad : C:\WINDOWS\NOTEPAD.EXE

As you might have noticed in the above code window, i have used PropertyType as 'String'. Below is the list of PropertyType Values available for Registry Entries

PropertyType ValueMeaning
BinaryBinary data
DWordA number that is a valid UInt32
ExpandStringA string that can contain environment variables that are dynamically expanded
MultiStringA multiline string
StringAny string value
QWord8 bytes of binary data

A registry entry can be removed from a registry key with the help of Remove-ItemProperty cmdlet


PS C:\> Remove-ItemProperty -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run -name "Notepad"
PS C:\> Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

RTHDCPL : RTHDCPL.EXE
Alcmtr : ALCMTR.EXE
IgfxTray : C:\WINDOWS\system32\igfxtray.exe
HotKeysCmds : C:\WINDOWS\system32\hkcmd.exe
Persistence : C:\WINDOWS\system32\igfxpers.exe

5 comments:

  1. As you mentioned above that powershell has simplified many things like registry accessing just like any other drive in powershell. and we can easily add a new entry to registry key using New-ItemProperty command.It really sounds good

    ReplyDelete
  2. Betting Casino Games is unlimited.
    Gclub Slot Is a online game site to cheer online through the online betting games that can be played without interruption. Win online with quality online gambling games to win every game without downloading. Have fun and gambling at the same time because you can gamble through the site. Online gambling games in the new era has been uninterrupted. And there are a number of players who turn to betting on online gambling games to facilitate. Instead of the original way to use the service in real gambling. Because online games have been broadcast and have given you the chance to win. Withdrawal - in 15 minutes, and also allows players to gamble directly through the site without the hassle of downloading. And to win online lucrative online games, we also have the option to play a variety of games. That is to meet the needs of people in this age. Play online gambling games that improve the agility of the users. You can also opt for the online slot machine games you want. We bring you the most popular online games to play a variety of games to you to enjoy every moment. Holiday Palace

    ReplyDelete
  3. Online Casinos The channel you will not be disappointed.
    บาคาร่าออนไลน์ Online casino sites are famous for their entertainment. Full casino support. No matter where you are in the world. It can be accessed quickly. The online casino also has a staff to help and advise new players or interested to play 24 hours a day. Come on continuously. The game is easy to play to accommodate the player in every way has updated the way to play all the time. There are also various types of play. The player to play with fun. The game is transmitted through our online casino site, sharp images without interruption through the Internet. To keep the player uninterrupted. In addition, the online games bets on our online casino site. We dare to guarantee that real players pay real money without taking advantage of any player. You just want to try playing gambling games rather than playing time kill games. Can be contacted directly through our website. In addition to the speed and accuracy that can be verified. Our casino site is also one of the top casinos. The country with the most shifting players each day. Please join us at the website. รูบี้888

    ReplyDelete
  4. จีคลับ Online gambling sites that can be played every day. Just like or want to gamble yourself all the time. Anyone who likes to gamble can play professionally. Have a play that anyone play. Can play in a friendly. Every day bets are fun and realistic bets.

    In addition, it is interesting to occasionally eat smoothies. It does not always benefit the body. If you do not like the way you drink it down. Green fruit juice. Full of benefits The smell of green and bitter taste, the drink will make your body can not absorb the benefits of the juice. If you do not want to lose fruits and vegetables, you should gradually drink it with a drink time of about 5-20 minutes, gradually sip gradually the body absorbs minerals and vitamins in the drink better.

    It is interesting to have a gambling game that will play every day. Gambling is like a good return every time. To play all. You can earn as you choose. It is a bet that will enjoy the things that people choose. Can play well with betting games to make more money. บาคาร่า

    ReplyDelete
  5. Thank you for sharing valuable informationNice post,I enjoyed reading this post.

    หนังตลก

    ReplyDelete