Installing Excel addins in logonscript (How to use current user SID in cmd)

1

I'm trying to add an Excel addin to my clients using the logonscript. I've checked whether it's possible or not to add it using GPOs, and unfortunately it isn't (even though you can manually exclude them -__- GG MS). The reason why I don't just copy the .xlam to the addins folder is because we update it sometimes so they have to access it from a network drive. My issue is that the key is under CURRENT_USER and therefore I need the current user's SID. Now my question is how do I get the user's SID and use it fx in the .reg file?

The .reg file looks like this:

Windows Registry Editor Version 5.00
[HKEY_USERS\\****SID****\Software\Microsoft\Office\12.0\Excel\Options]
"OPEN"="\"\\****MACRO****.xlam\""

What's the easiest way to get the SID here?

Thanks in advance!

Frederik IH

Posted 2016-03-08T12:45:10.857

Reputation: 31

Answers

1

I need the current user's SID

You can use wmic.

From the command line:

wmic useraccount where name='%username%' get sid

F:\test>wmic useraccount where name='%username%' get sid
SID
S-1-5-21-1699878757-1063190524-3119395976-1000

From a batch file (GetSID.cmd):

@echo off
setlocal
rem use findstr to strip blank lines from wmic output
rem skip the heading
for /f "usebackq skip=1" %%i in (`wmic useraccount where name^="%username%" get sid ^| findstr /r /v "^$"`) do (
  set _sid=%%i
  )
echo %_sid%
endlocal    

Notes:

  • The batch file stores the SID in %_sid% for use late if required.

Example Usage:

F:\test>GetSID
S-1-5-21-1699878757-1063190524-3119395976-1000

F:\test>

How can I use the current user's SID in a .reg file?

The easiest option is probably to use the reg command to add the keys required directly to the registry.

You can write a batch file that:

  1. Runs the wmic command.

  2. Saves the SID in an environment variable, eg %_sid%.

  3. I've done this already in the batch file GetSID.cmd above.

  4. Now add the appropriate reg add commands with %-sid% in the correct place to add the values to the registry.


Further Reading

DavidPostill

Posted 2016-03-08T12:45:10.857

Reputation: 118 938

0

Okay, I figured out the facepalm solution to my problem. Apparently the key also exists under HKEY_CURRENT_USER so that is by far the easiest solution.

But thank you very much for the other solution! I will most probably use your batch file implementation method in my solution.

Thanks for the comprehensive, excellent and insanely fast solution, David!

Frederik IH

Posted 2016-03-08T12:45:10.857

Reputation: 31