2

I know that I can set a runonce key in the Win7 registry globally, which will be executed no matter which user logs on the next time, using this registry key:

HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

I need to do an initialization only for a specific user, so I wonder if there is a way to programatically (using Powershell) set a runonce-entry that is only executed if one specific user logs on, also if this user is not an Administrator.

Do you know of a way to do this? Thanks.

Erik
  • 2,316
  • 9
  • 36
  • 58

1 Answers1

3

I think this question and the other (http://stackoverflow.com/questions/10908727/how-can-i-programatically-find-a-users-hkey-users-registry-key-using-powershell) are related:

Anyways, here is how you do it:

$User = New-Object System.Security.Principal.NTAccount($env:UserName)
$sid = $User.Translate([System.Security.Principal.SecurityIdentifier]).value

New-PSDrive HKU Registry HKEY_USERS
Get-Item "HKU:\${sid}"

Set-ItemProperty -Path "HKU:\${sid}\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name Command -Value "notepad.exe"
ravikanth
  • 24,922
  • 4
  • 60
  • 60