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

标签 powershell windows-7 runonce

我知道我可以在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/

相关文章:

windows - 在命令行上执行简单的powershell命令

windows - PowerShell 在屏幕外打开

powershell - Azure Powershell 获取暂存云服务的公共(public) IP

sql-server - 在PowerShell中使用Invoke-Sqlcmd时,在SQL查询中保留注释文本?

delphi - IDAPI、BdeAdmin 和 Windows 7

ruby - 在带有 Rails 3、Ruby 1.9.2 的 Windows 7 上运行自动测试时出错

c++ - EnumProcessModules 在 32 位 win7 上失败并出现错误 299

java - 创建一个只运行一次的java应用程序