我想写一个写入所有用户在本地计算机上指定的键的应用程序(如:我想设置的位置IE收藏夹的所有用户在同一个文件夹中)打开另一个用户的注册表设置
PS 有人用过这些功能吗? LoadUserProfile RegOpenCurrentUser CreateProcessAsUser
我想写一个写入所有用户在本地计算机上指定的键的应用程序(如:我想设置的位置IE收藏夹的所有用户在同一个文件夹中)打开另一个用户的注册表设置
PS 有人用过这些功能吗? LoadUserProfile RegOpenCurrentUser CreateProcessAsUser
我已经做了很多次。这个想法是更新当前登录用户的HKCU(这很简单)。然后你必须枚举系统上的每个配置文件并找到他们的ntuser.dat文件(这也很简单)。
随着发现Ntuser.dat文件,将其加载到在HKLM蜂巢临时密钥(我一般用“HKLM \ TempHive”。然后编辑程。
如果有超过1个用户登录,他们的个人资料将HKEY_USERS下被加载,通过他们的SID。简单地更新该位置。
修改设置为所有新用户,只需修改HKEY_USERS.DEFAULT下相应的键,或使用Delphi代码下面将做这通过加载默认用户的HKCU注册表配置单元(存储在ntuser.dat中)。
UPDATE:我发现我的Delphi代码演示了如何更新未登录到系统的用户的HKCU配置单元。
这需要Russell Libby的'Privilege'组件,which is available here。
//NOTE: sPathToUserHive is the full path to the users "ntuser.dat" file.
//
procedure LoadUserHive(sPathToUserHive: string);
var
MyReg: TRegistry;
UserPriv: TUserPrivileges;
begin
UserPriv := TUserPrivileges.Create;
try
with UserPriv do
begin
if HoldsPrivilege(SE_BACKUP_NAME) and HoldsPrivilege(SE_RESTORE_NAME) then
begin
PrivilegeByName(SE_BACKUP_NAME).Enabled := True;
PrivilegeByName(SE_RESTORE_NAME).Enabled := True;
MyReg := TRegistry.Create;
try
MyReg.RootKey := HKEY_LOCAL_MACHINE;
MyReg.UnLoadKey('TEMP_HIVE'); //unload hive to ensure one is not already loaded
if MyReg.LoadKey('TEMP_HIVE', sPathToUserHive) then
begin
//ShowMessage('Loaded');
MyReg.OpenKey('TEMP_HIVE', False);
if MyReg.OpenKey('TEMP_HIVE\Environment', True) then
begin
// --- Make changes *here* ---
//
MyReg.WriteString('KEY_TO_WRITE', 'VALUE_TO_WRITE');
//
//
end;
//Alright, close it up
MyReg.CloseKey;
MyReg.UnLoadKey('TEMP_HIVE');
//let's unload the hive since we are done with it
end
else
begin
WriteLn('Error Loading: ' + sPathToUserHive);
end;
finally
FreeAndNil(MyReg);
end;
end;
WriteLn('Required privilege not held');
end;
finally
FreeAndNil(UserPriv);
end;
end;
我还写了一个前段时间完成此任务的VBScript。我用它来修改某些Internet Explorer设置,但您可以根据需要对其进行自定义。它也演示了一般过程:
Option Explicit
Dim fso
Dim WshShell
Dim objShell
Dim RegRoot
Dim strRegPathParent01
Dim strRegPathParent02
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.shell")
'==============================================
' Change variables here
'==============================================
'
'This is where our HKCU is temporarily loaded, and where we need to write to it
RegRoot = "HKLM\TEMPHIVE"
'
strRegPathParent01 = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
strRegPathParent02 = "Software\Microsoft\Internet Explorer\Main"
'
'======================================================================
Call ChangeRegKeys() 'Sets registry keys per user
Sub ChangeRegKeys
'Option Explicit
On Error Resume Next
Const USERPROFILE = 40
Const APPDATA = 26
Dim iResult
Dim iResult1
Dim iResult2
Dim objShell
Dim strUserProfile
Dim objUserProfile
Dim strAppDataFolder
Dim strAppData
Dim objDocsAndSettings
Dim objUser
Set objShell = CreateObject("Shell.Application")
Dim sCurrentUser
sCurrentUser = WshShell.ExpandEnvironmentStrings("%USERNAME%")
strUserProfile = objShell.Namespace(USERPROFILE).self.path
Set objUserProfile = fso.GetFolder(strUserProfile)
Set objDocsAndSettings = fso.GetFolder(objUserProfile.ParentFolder)
'Update settings for the user running the script
'(0 = default, 1 = disable password cache)
WshShell.RegWrite "HKCU\" & strRegPathParent01 & "\DisablePasswordCaching", "00000001", "REG_DWORD"
WshShell.RegWrite "HKCU\" & strRegPathParent02 & "\FormSuggest PW Ask", "no", "REG_SZ"
strAppDataFolder = objShell.Namespace(APPDATA).self.path
strAppData = fso.GetFolder(strAppDataFolder).Name
' Enumerate subfolders of documents and settings folder
For Each objUser In objDocsAndSettings.SubFolders
' Check if application data folder exists in user subfolder
If fso.FolderExists(objUser.Path & "\" & strAppData) Then
'WScript.Echo "AppData found for user " & objUser.Name
If ((objUser.Name <> "All Users") and _
(objUser.Name <> sCurrentUser) and _
(objUser.Name <> "LocalService") and _
(objUser.Name <> "NetworkService")) then
'Load user's HKCU into temp area under HKLM
iResult1 = WshShell.Run("reg.exe load " & RegRoot & " " & chr(34) & objDocsAndSettings & "\" & objUser.Name & "\NTUSER.DAT" & chr(34), 0, True)
If iResult1 <> 0 Then
WScript.Echo("*** An error occurred while loading HKCU: " & objUser.Name)
Else
WScript.Echo("HKCU loaded: " & objUser.Name)
End If
WshShell.RegWrite RegRoot & "\" & strRegPathParent01 & "\DisablePasswordCaching", "00000001", "REG_DWORD"
WshShell.RegWrite RegRoot & "\" & strRegPathParent02 & "\FormSuggest PW Ask", "no", "REG_SZ"
iResult2 = WshShell.Run("reg.exe unload " & RegRoot,0, True) 'Unload HKCU from HKLM
If iResult2 <> 0 Then
WScript.Echo("*** An error occurred while unloading HKCU: " & objUser.Name & vbcrlf)
Else
WScript.Echo(" unloaded: " & objUser.Name & vbcrlf)
End If
End If
Else
'WScript.Echo "No AppData found for user " & objUser.Name
End If
Next
End Sub
嗨,这看起来像我想:)我现在正在测试,但我得到一个错误 [DCC错误] Privilege.pas(646):E2251模糊重载调用'StrLen' – 2009-10-06 18:42:36
新错误:项目.. 。提出的异常类EPrivilegdError带有消息“权限SeBackupPrivilege不由用户持有” (我是管理员的成员) – 2009-10-06 19:10:58
以下是特权组件对此问题作者的回复======== - 用户帐户必须......... (a)持有SE_RESTORE_NAME和SE_BACKUP_NAME权限======== (b)必须启用特权。 ======== ======== 它的管理员,超级用户或普通用户帐户无关紧要。管理员确实*保留*权限,但在大多数情况下,他们不*启用。拥有(持有)权限与启用权限不同。 ======== Regedit启用reqd权限,就像任何其他程序在尝试执行所需操作之前一样。 – Mick 2009-10-07 04:58:10
我们在前一天有完全相同的问题。
我们发现您可以打开HKEY_USERS
配置单元并将更改写入每个用户的SID。
而且,如果您希望任何新用户的设置都存在,您还应该将设置应用于HKEY_USERS/.DEFAULT
密钥。
也就是说,只写你的设置,以...
HKEY_USERS\S-1-5-XX-XXXXXXXX-XXXXXXXXX-XXXXXXXX-XXXX\Software\...
对于每一个现在和小岛屿发展中国家:
HKEY_USERS\.DEFAULT\Software\...
只有当前登录用户的SID将在那里。如果用户未登录,则操作系统不会加载该用户的注册表配置单元,因此该用户没有子项。 – 2009-10-05 16:45:05
对于Rob概述的原因,这是一个不完整的解决方案。我的答案解决了这个问题。 – Mick 2009-10-05 17:27:30
我已为您的解决方案+1了。 – 2009-10-05 18:07:19
为什么你想让所有用户共享同一个文件夹?如果它们最终会覆盖彼此的最爱,那么这会让很多用户烦恼。 – 2009-10-05 14:17:56
同意 - 不要更改位置。使用常见的收藏夹: 收藏夹为所有用户:C:\ Documents and Settings \所有用户\收藏夹 特定用户的收藏夹:C:\ Documents and Settings \ \ Favorites –
DmitryK
2009-10-05 14:30:09
是的,Remus人们已经使用了这些功能。请问你真的想问一些关于他们的问题。是/否这样的问题没有用处。 – 2009-10-05 16:48:56