1

I've been a lurker here for a long time and nearly always found a question to my answer using the search question, but this time I need some help. I want to create a script/.reg file that automatically registers some Powerpoint AddIns to the computers in my domain. Pretty straightforward, it needs to do this:

[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\PowerPoint\AddIns\PPMacro]
"AutoLoad"=dword:ffffffff 
"Path"="C:\\Users\\%USERNAME%\\AppData\\Roaming\\Microsoft\\AddIns\\PPMacro.ppam"

Basically, it makes an entry in Powerpoint's registry pointing it to a macro in the AppData folder. However, while this 'Path' key is a static path to the macro, I would like this static path to have a variable username in the script, since this differs per computer I want to apply the script to.

I cannot seem to figure out how to do this. It keeps literally putting %USERNAME% in the key, which is logical since it's in parenthesis, but I don't know how I am supposed to do it. Could anyone help me out here? Thanks in advance!

TommyDJ
  • 13
  • 1
  • 3

2 Answers2

2

Use the REG command:

REG ADD "HKCU\Software\Microsoft\Office\16.0\PowerPoint\AddIns\PPMacro" /v Path /t REG_SZ /d "C:\\Users\\%USERNAME%\\AppData\\Roaming\\Microsoft\\AddIns\\PPMacro.ppam" /f
Greg Askew
  • 35,880
  • 5
  • 54
  • 82
  • Thanks, that worked! I actually changed %USERNAME% to %USERPROFILE%, since some of our users have a . user folder. However your comment pointed me in the right direction! – TommyDJ Jun 27 '17 at 13:04
1

To write in the registry you can use powershell and these commmandlets :

$RegKey="HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\PowerPoint\AddIns\PPMacro"
Set-ItemProperty -Path $RegKey -Name AutoLoad -Value ffffffff 
Set-ItemProperty -Path $RegKey -Name Path -Value "C:\\Users\\%USERNAME%\\AppData\\Roaming\\Microsoft\\AddIns\\PPMacro.ppam"

or, for creating a new entry you can use new-item

And for the username, you can use the global variable %USERNAME%. With a GPO, you will be able to execute this script on all desired computer.

.

Sorcha
  • 1,325
  • 8
  • 11
  • I actually prefer to do it through a bat script, so Greg's solution is more suitable. Many thanks for taking the time to answer my question though! – TommyDJ Jun 27 '17 at 13:05