/build/static/layout/Breadcrumb_cap_w.png

K1000 Won't Run cmd command with UAC

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

     :isAdmin
        fsutil dirty query %systemdrive% >nul
     exit /b

     :run
      
setlocal

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

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

       "%temp%\getadmin.vbs"
       del "%temp%\getadmin.vbs"

3 Comments   [ + ] Show 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. - chucksteel 6 years ago
    • 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 - clozecall 6 years ago
      • 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. - chucksteel 6 years ago
  • Nope, it's 'BINN'. Lord only knows why. - anonymous_9363 6 years ago
  • @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. - clozecall 6 years ago

Answers (0)

Be the first to answer this question

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ