Powershell 如何在Windows 7上为特定用户执行RunOnce?

Powershell 如何在Windows 7上为特定用户执行RunOnce?,powershell,windows-7,runonce,Powershell,Windows 7,Runonce,我知道我可以在Win7注册表中全局设置runonce项,无论下次哪个用户登录,都将使用此注册表项执行该项: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce 我只需要为特定用户进行初始化,因此我想知道是否有办法通过编程(使用Powershell)设置runonce条目,该条目仅在一个特定用户登录时执行,并且该用户不是管理员 你知道怎么做吗?谢谢。我想这个问题和另一个问题(http://stackoverflow.com/questio

我知道我可以在Win7注册表中全局设置runonce项,无论下次哪个用户登录,都将使用此注册表项执行该项:

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

我只需要为特定用户进行初始化,因此我想知道是否有办法通过编程(使用Powershell)设置runonce条目,该条目仅在一个特定用户登录时执行,并且该用户不是管理员


你知道怎么做吗?谢谢。

我想这个问题和另一个问题(http://stackoverflow.com/questions/10908727/how-can-i-programatically-find-a-users-hkey-users-registry-key-using-powershell)它们是相关的:

无论如何,这里是你如何做到的:

$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"