title: Use List of Windows accounts to add reg keys using SIDS
body: <h1>edit re explanation to improve answers.</h1>
  <p><strong>Project</strong></p>
  <p>As a third party engineer I am attending a site to install a piece of Software. The Infrastructure is &quot;very&quot; locked down. I will be supplied with an admin account for the day to install the software. However, to make the software work properly FOR ALL USERS (not just admin logged in) I have been instructed by IT dept. to manually create a KEY and then add a string value within created key for every user account on the PC. Our software in a standard environment caters for this with an all users reg key but it doesn't run (not allowed - don't ask!) in these specific places.</p>
  <p>The location of where they want the the KEY is within the HKEY_USERS path in the reg:-</p>
  <p>HKEY_USERS\S-1-5-21-XXXXXXXXX-XXXXXXXXX-XXXXXXXXXX-XXXXX\Software\Microsoft\</p>
  <p>so lets say 2 people logged in this PC and they need to use our software later on</p>
  <p>john.jones</p>
  <p>mary.shelley</p>
  <p>I need to find the sid relating to john jones and go and add the key to his section in HKEY_USERS</p>
  <p>I then need to find mary.shelley sid and then go and the key to her HKEY_USERS section, etc.</p>
  <p>Now I know from the environments I work in there could be 20 + user acounts on there so really would like to avoid manually adding they keys over and over for all the accounts on every PC I'm installing at.</p>
  <p>A log on script would be better, but this all I have to deal with at present.</p>
  <p><strong>State of Script Now</strong></p>
  <pre><code>@echo off
  REM Read file with user names
  FOR /F &quot;usebackq tokens=*&quot; %%G in (&quot;users.txt&quot;) do (
      REM use user name to find SID
      FOR /F &quot;delims=&quot; %%H IN ('&quot;wmic useraccount where name='%%~G' get sid| findstr /vi &quot;SID&quot;&quot;') DO (
          REM Strip trailing line with CR
          FOR /F &quot;delims= &quot; %%I IN (&quot;%%~H&quot;) DO (
              REM %%I is now the SID of the USER
              REG ADD &quot;HKEY_USERS\%%I\Software\Microsoft\addstuffhere&quot; /f
              REG ADD &quot;HKEY_USERS\%%I\Software\Microsoft\addstuffhere&quot; /t REG_SZ /d &quot;addstuffhere&quot;&quot; /f
          )
      )
  )
  </code></pre>
  <p>This is pretty much automating the whole thing as planned; loops through a text file of user names of users who use the PC, grabs the SID, applies sid as variable, then is used to write the key in the right place for that user, and on through the list doing to same for every account listed.</p>
  <p>The only part that may need altering is the WMIC section is not finding certain users who have bona fide windows accounts.</p>
  <p>when I tested the working code on my laptop it worked fine for my administrator account, but me logged in as joe_blogs (e.g.) came up with &quot;no instance available&quot;. Because in isolation the WMIC code just brought up only a few not all, so couldn't do what it needed to do.</p>
  <p>I know from previous questions this WMIC code brings up every account:-</p>
  <pre><code>WMIC Path Win32_UserProfile Where &quot;Special='False' And Not LocalPath='Null'&quot; Get LocalPath,SID | find /v &quot;&quot;
  </code></pre>
  <p>Perhaps that can be incorporated into current working code to make sure every account is catered for.</p>
  <p>I know the users all need to have logged in at each PC for this to work, so with regards to the list of user profiles, I can garner that on the day asking &quot;who of your users needs to use our stuff on the PC's&quot; and make the users.txt</p>
  <p>thanks  - hope that really explains it :/</p>
  <h1>edit instructions for what I have been asked to do (altered key names slightly for privacy)</h1>
  <pre><code>1. Log on to the PC with a standard technician admin account
  2. Open regedit.exe
  3. Navigate to* HKEY_USERS\S-1-5-21-XXXXXXXXX-XXXXXXXXX-XXXXXXXXXX-     XXXXX\Software\Microsoft\Terminal Server Client\Default\Addins\
  a. Right-click Addins &gt; New &gt; Key and create foo
  b. Right-click foo &gt; New &gt; String Value and create Name
  c. Double-click Name and in Value Data enter† C:\foo\file\foo.dll
  4. Repeat step 3 for each user: it should be possible to edit the SID in an exported key by right-clicking on the next 
  HKEY_USERS entry &gt; Rename &gt; Ctrl+C &gt; Esc then replacing the SID in the exported reg key – this has not been tested but may be worth trying
  
  *The user SID is unique so this has to be done per user. If there are a lot of users listed in the registry it is possible to find which SID belongs to which user by checking the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
  </code></pre>