Sunday, January 28, 2018

Build events: copy file with elevated rights

Leave a Comment

I need a command that I can use in Visual Studio's Post-build event command line that can copy a file using elevated rights.

  • runas is not an option as my user can elevate privileges.
  • starting VS as admin is also not an option.

What is the best way?

For the sake of completeness: I want to install CustomComponents for SSIS automatically on my development machine.

1 Answers

Answers 1

The solution is to start a powershell with elevated privileges. In this powershell a gacutil und copy are used to install the CustomComponents locally.

The command I use in VS2015 with SQLServer 2017 is:

powershell -Command "Start-Process cmd -ArgumentList('/K', 'copy /Y \"$(TargetPath)\" \"C:\Program Files (x86)\Microsoft SQL Server\140\DTS\PipelineComponents\" && \"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\gacutil.exe\" /i \"$(TargetPath)\" /f')" -Verb RunAs 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment