Trying to execute power-shell at user startup

Welcome Forums General PowerShell Q&A Trying to execute power-shell at user startup

Viewing 2 reply threads
  • Author
    Posts
    • #213261
      Participant
      Topics: 3
      Replies: 2
      Points: 39
      Rank: Member

      Hi All,

      I’m trying to achieve something due by Org policies.

      I have the below command, i’m able to manually run it through CMD but when running in user start up (say Run once registry key or through Active setup registry) it is not writing the registry.

      I’m not user where the mistake is, can some one guide me. Command line below:

      C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -executionpolicy ByPass -command $personal = $env:USERPROFILE; $personal = $personal + "\Documents\Custom Office Templates"; Reg ADD "HKCU\Software\Microsoft\Office\16.0\Word\Options" /v "PersonalTemplates" /d $personal /t REG_SZ /f;

      I was told that when there is no console, there could be issue in resolving the environment variables, so i have even tried below and luck

      C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -executionpolicy ByPass -command $personal = $(get-itemproperty 'HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders').personal;$personal = $personal + '\Custom Office Templates';Reg ADD "HKCU\Software\Microsoft\Office\16.0\PowerPoint\Options" /v "PersonalTemplates" /d $personal /t REG_SZ /f;

       

    • #213309
      Participant
      Topics: 12
      Replies: 1607
      Points: 2,495
      Helping Hand
      Rank: Community Hero

      First suggestion would be to use Powershell and not REG.EXE as it’s unnecessary to mix them:

      Set-ItemProperty -Path HKCU:Software\Microsoft\Office\16.0\Word\Options -Name PersonalTemplates -Value ("{0}\Documents\Custom Office Templates" -f $env:USERPROFILE)
      
    • #213657
      Participant
      Topics: 3
      Replies: 2
      Points: 39
      Rank: Member

      I would try and let you know the feedback

Viewing 2 reply threads
  • You must be logged in to reply to this topic.