Sign in to follow this  
Followers 0
ryantollefson

RegWrite to all users?

8 posts in this topic

I know I can access other user's registry values under HKEY_USERS, but the entries will be different on other computers. Is there a way to write a registry value for all users on a computer?

Or perhaps there is a way to retrieve all users listed under HKEY_USERS and store them to an array and use that to write back?

Thanks for any help.

Share this post


Link to post
Share on other sites



What is the type of info you want to write?

Could you not put it into HKEY_LOCAL_MACHINE instead?

Share this post


Link to post
Share on other sites

What is the type of info you want to write?

Could you not put it into HKEY_LOCAL_MACHINE instead?

In some cases I can (and have done so when possible), but in others I can't. I'm trying to change settings for Media Center for all users (like the skip ahead/back intervals).

Share this post


Link to post
Share on other sites

I know I can access other user's registry values under HKEY_USERS, but the entries will be different on other computers. Is there a way to write a registry value for all users on a computer?

Or perhaps there is a way to retrieve all users listed under HKEY_USERS and store them to an array and use that to write back?

Thanks for any help.

How about something based on the following (UNTESTED):

const $sLoginKeyName = '\Software\Microsoft\Windows\CurrentVersion\Explorer'
const $sLoginValueName = 'Logon User Name'
$iInstance = 1
$sUser = RegEnumKey('HKU', $iInstance)
while @error = 0
  $sLoginName = RegRead($sUser & $sLoginKeyName, $sLoginValueName)
  if @error = 0 then msgbox(64, $sUser, $sLoginName, 5)
  $iInstance += 1
  $sUser = RegEnumKey('HKU', $iInstance)
wend

You might need to look at the value returned by RegEnumKey to make it work ...

Share this post


Link to post
Share on other sites

In some cases I can (and have done so when possible), but in others I can't. I'm trying to change settings for Media Center for all users (like the skip ahead/back intervals).

So, on my XP Pro installation, I just noticed that the unique SID for each user only exists under HKEY_USERS when they're logged on: if I'm logged on, only my SID entry is there. If I use fast user switching and log on another user, then both SID keys are there. If I log off, my SID key is removed, etc. Registry entries for users that aren't logged on are stored in the "ntuser.dat" file in the root of their profile directory. It looks like you would need to be able to modify the ntuser.dat file for each user then. A quick google turned up http://blog.shijaz.com/search/label/NTUser.dat which describes a tool that can do just that.

Another option might be to store your settings in a LOCAL_MACHINE key, then have a script that auto runs when a user logs on and copies the settings to the appropriate key in the CURRENT_USER portion of the registry? Storing them in LOCAL_MACHINE as opposed to hard coding them into the auto run script means you can have a fairly generic script and make any changes you need in the future only to the LOCAL_MACHINE part. Just a thought...

Share this post


Link to post
Share on other sites

So, on my XP Pro installation, I just noticed that the unique SID for each user only exists under HKEY_USERS when they're logged on: if I'm logged on, only my SID entry is there. If I use fast user switching and log on another user, then both SID keys are there. If I log off, my SID key is removed, etc.

Oh. I saw all the SIDs when I checked my machine earlier. But, running the following:

const $sLoginKeyName = '\Software\Microsoft\Windows\CurrentVersion\Explorer'
const $sLoginValueName = 'Logon User Name'
$iInstance = 1
$sUser = RegEnumKey('HKU', $iInstance)
while @error = 0
  $sLoginName = RegRead('HKU\' & $sUser & '\' & $sLoginKeyName, $sLoginValueName)
                                                                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sUser = ' & $sUser & @crlf);### Debug Console
                                                                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sLoginName = ' & $sLoginName & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
 ; if @error = 0 then msgbox(64, $sUser, $sLoginName, 5)
  $iInstance += 1
  $sUser = RegEnumKey('HKU', $iInstance)
wend

Produces the following console output:

@@ Debug(7) : $sUser = .DEFAULT

@@ Debug(8) : $sLoginName =

>Error code: 0

@@ Debug(7) : $sUser = S-1-5-19

@@ Debug(8) : $sLoginName =

>Error code: 0

@@ Debug(7) : $sUser = S-1-5-19_Classes

@@ Debug(8) : $sLoginName =

>Error code: 0

@@ Debug(7) : $sUser = S-1-5-20

@@ Debug(8) : $sLoginName =

>Error code: 0

@@ Debug(7) : $sUser = S-1-5-20_Classes

@@ Debug(8) : $sLoginName =

>Error code: 0

@@ Debug(7) : $sUser = S-1-5-21-1957994488-842925246-40105171-196083

@@ Debug(8) : $sLoginName = batemans

>Error code: 0

@@ Debug(7) : $sUser = S-1-5-21-1957994488-842925246-40105171-196083_Classes

@@ Debug(8) : $sLoginName =

>Error code: 0

@@ Debug(7) : $sUser = S-1-5-18

@@ Debug(8) : $sLoginName =

>Error code: 0

Looks like even though the SIDs are there, they're not fully populated. Or put another way, the registry values aren't available to read/set - maybe because the other logins aren't logged on.

@ ResNullis - good catch :whistle:

Share this post


Link to post
Share on other sites

...

Looks like even though the SIDs are there, they're not fully populated. Or put another way, the registry values aren't available to read/set - maybe because the other logins aren't logged on.

The only SIDs that represent created user accounts are long ones that begin "S-1-5-21-" and follow the pattern "S-1-5-21-xxxxxxxxxx-xxxxxxxxx-xxxxxxxx-xxxxxx". The "x" digit pattern will be different on diifferent computers.

If you want to see which SIDs belong to which users, try this:

;based on "SIDlist.vbs by Ramesh Srinivasan, http://windowsxp.mvps.org

#include <Array.au3>
 
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$AccountList=""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount", "WQL", _
                                            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then

    For $objItem In $colItems
        $leftName = StringLeft($objItem.Name,5)

        Switch $objItem.Name

            Case "HelpAssistant","SUPPORT_388945a0","ASPNET" ;exclude "special" built-in accounts"
                ContinueLoop

            Case $objItem.Disabled <> 0 ; exclude disabled accounts, comment out this aqnd next line to include them
                ContinueLoop

            Case $leftName = "IUSR_" OR $LeftName = "IWAM_" ;exclude more non-relevant accounts
                ContinueLoop 

            Case Else
                $AccountList &= $objItem.Name & " = " & $objItem.SID & @CR
        EndSwitch
    Next

Else
    Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_UserAccount" )
Endif

$AccountList = StringTrimRight($AccountList,1)
$aAccountList = StringSplit($AccountList,@CR)
_ArrayDisplay($aAccountList)

Share this post


Link to post
Share on other sites

... Is there a way to write a registry value for all users on a computer?...

...I'm trying to change settings for Media Center for all users (like the skip ahead/back intervals).

If you've got a script built to apply the settings based upon "Current User" reg entries, you can use Active Setup to apply the settings when each user logs in (only applies once unless you were to update the version of your configuration app).

Then you'd put the installation trigger in:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{YOUR_APP_GUID}

Basically, you'd be using a function similar to "RunOnce" with the variation being that it would apply to all existing users as well as all new users created on the box.

Links to help with the process:

Microsoft's GUID Generator -> here

A simple overview of using Active Setup -> here


- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0