Hello Everyone,

I built managed installs for SQL 2008, 2012 and 2014. Now in order to use Management Studio properly on Windows 10, they need to run as an admin so I created a script to make them work as an admin for all users on the computer. I built the below batch file code which basically forces cmd to run with admin rights and make the required change to the Management Studio file (in the below example for SQL 2012). If I run the batch file locally it always works but when I push it through K1000 as part of my MI or script it never works. Any thoughts?

@echo on

     call :isAdmin

     if %errorlevel% == 0 (
        goto :run
     ) else (
        echo Requesting administrative privileges...
        goto :UACPrompt

     exit /b

        fsutil dirty query %systemdrive% >nul
     exit /b


set "reg_key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
reg add "%reg_key%" /v "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe" /d "RUNASADMIN" /f
     exit /b

       echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
       echo UAC.ShellExecute "cmd.exe", "/c %~s0 %~1", "", "runas", 1 >> "%temp%\getadmin.vbs"

       del "%temp%\getadmin.vbs"
3 Comments   [ - ] Hide Comments


  • The AMPAgent runs in the system context, so there shouldn't be a need to work around UAC constraints. Your issue might be related to the registry key being in the 64bit space of the registry, in which case you need to add the /reg:64 to the command.
    • Hi Chucksteel, thanks for the feedback. Apologies for my lack of experience with this. If I were to ignore the UAC constraint, how would I apply your recommendation to the lines that apply the change:

      set "reg_key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
      reg add "%reg_key%" /v "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe" /d "RUNASADMIN" /f
      • Just run this:
        reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe" /d "RUNASADMIN" /f /reg:64

        You also might want to check the path, I don't have a machine with the Management Studio installed, but I'm pretty sure it's bin and not binn.
  • Nope, it's 'BINN'. Lord only knows why.
  • @chucksteel thank you! That fixed the issue! It now works great all within my MI as a single batch file to install SQL and then set the appropriate admin level.
Please log in to comment

There are no answers at this time
Answer this question or Comment on this question for clarity