title: Execute PS from bat for Intune Win32
body: <p>I am so confused and actually also not so familiar with PS and bat after my troubles with them.</p>
  <p>I want to set the Lockscreen in Windows 10 with Intune through an IntuneWin file (WIN32 application).</p>
  <p>I have a folder with the image, which I want to set, a copy.bat which should copy the image in the directory and also execute the PS file for setting the login image and a del.bat for deleting the image.</p>
  <p><strong>copy.bat</strong></p>
  <pre><code>md %AllUsersProfile%\sz
  copy /Y Wallpaper.jpg %AllUsersProfile%\sz
  powershell -ExecutionPolicy Bypass -File Set-Lockscreen.ps1 -verb RunAs
  </code></pre>
  <p><strong>del.bat</strong></p>
  <pre><code>del /Y %AllUsersProfile%\sz\Wallpaper.jpg
  </code></pre>
  <p><strong>Set-Lockscreen.ps1</strong></p>
  <pre><code>$RegKeyPath = &quot;HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationLS&quot;
  $LockScreenPath = &quot;LockScreenImagePath&quot;
  $LockScreenStatus = &quot;LockScreenImageStatus&quot;
  $LockScreenUrl = &quot;LockScreenImageUrl&quot;
  $StatusValue = &quot;1&quot; 
  
  $path = &quot;C:\ProgramData\Elinvar&quot;
  $LockScreenImageValue = &quot;C:\ProgramData\sz\Wallpaper.jpg&quot;
  
   sIf ((Test-Path -Path $path) -eq $false)
  {
   New-Item -Path $path -ItemType directory
  }
   
  if (!(Test-Path $RegKeyPath))
  {
   Write-Host &quot;Creating registry path $($RegKeyPath).&quot;
   New-Item -Path $RegKeyPath -Force | Out-Null
  }
   
  New-ItemProperty -Path $RegKeyPath -Name $LockScreenStatus -Value $StatusValue -PropertyType DWORD -Force | Out-Null
  New-ItemProperty -Path $RegKeyPath -Name $LockScreenPath -Value $LockScreenImageValue -PropertyType STRING -Force | Out-Null
  New-ItemProperty -Path $RegKeyPath -Name $LockScreenUrl -Value $LockScreenImageValue -PropertyType STRING -Force | Out-Null
   
  RUNDLL32.EXE USER32.DLL, UpdatePerUserSystemParameters 1, True
  </code></pre>
  <p>I pack all these files with <a href="https://github.com/Microsoft/Microsoft-Win32-Content-Prep-Tool" rel="nofollow noreferrer">Microsoft Win32 Content Prep Tool</a> and upload this in Intune as Win32 file.
  Upload works, assigning to a group works, installation is successful. All good so far, I thought.</p>
  <p>If I check the directory, the image is in %AllUsersProfile%\sz.
  But when I check the reg, the entry is not set.</p>
  <p>When I run the copy.bat file manually, It doesn't work. Only when I run it as administrator.
  When I run the last line in cmd as administrator, so</p>
  <pre><code>powershell -ExecutionPolicy Bypass -File Set-Lockscreen.ps1 -verb RunAs
  </code></pre>
  <p>It works as well.</p>
  <p>I think Intune is not running the script as administrator.
  In Intune there is no configuration to say, run this command as administrator.
  Maybe with a syntax? Does anyone know this?
  Something like</p>
  <pre><code>copy.bat RunAs
  </code></pre>
  <p>I also export the reg file and import this with</p>
  <pre><code>reg import PersonalizationLS.reg
  </code></pre>
  <p>It didn't work.</p>
  <p>I think there must be a way to execute the installation command in intune to run the script as admin.
  It needs just for the last line the administrator privilege , md and copy work without administrator privileges. (same also for important reg file).</p>