我知道我可以在Win7注册表中全局设置一个runonce键,无论下次哪个用户登录都会执行这个键,使用这个注册表键:
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
我只需要为特定用户进行初始化,所以我想知道是否有一种方法可以以编程方式(使用Powershell)设置一个运行一次条目,该条目仅在一个特定用户登录时执行,即使该用户是不是管理员。
你知道有什么方法可以做到这一点吗?谢谢。
最佳答案
我认为这个问题和其他问题(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"
关于powershell - 如何在Windows 7上为特定用户执行RunOnce?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10908514/