2012-06-06 23 views
2

我知道我可以設置在全球範圍內的Win7註冊表的RunOnce鍵,這將是無論執行其下一次用戶登錄,使用此註冊表項:如何在Windows 7上爲特定用戶執行RunOnce?

HKLM:\ SOFTWARE \微軟\的Windows \ CurrentVersion \ RunOnce

我只需要爲特定用戶進行初始化,所以我想知道是否有編程方式(使用Powershell)設置一個runonce-entry,只有當一個特定用戶登錄時纔會執行,如果此用戶不是管理員。

你知道一種方法嗎?謝謝。

回答

3

我覺得這個問題和其他問題(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" 
相關問題