Created
November 21, 2016 21:57
-
-
Save idkaaa/861a642b5fd84db98707dc9107f04b42 to your computer and use it in GitHub Desktop.
Elevates process using UAC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Adds Create Database permission for the built-in Windows Authenticated Users group if it can. | |
/// </summary> | |
public static void AddPermissionAuthenticatedUsersCreateDb(string Server) | |
{ | |
Log.Trace($"Trying to add create database permission for authenticated users group on server: {Server}"); | |
string SqlcmdLogFile = @"${specialfolder:CommonApplicationData}\" + | |
Application.CompanyName + @"\" + | |
Application.ProductName + @"\" + | |
@"Data\SqlCmd.log"; | |
string SqlCmdPrefix = $@"-S {Server} -o {SqlcmdLogFile} -E -Q "; | |
string CreateLoginSqlScript = $@"CREATE LOGIN [NT AUTHORITY\Authenticated Users] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english];"; | |
string AddPermissionSqlScript = $@"ALTER SERVER ROLE [dbcreator] ADD MEMBER [NT AUTHORITY\Authenticated Users];"; | |
string CommandAddPermission = $@"{SqlCmdPrefix}""{CreateLoginSqlScript}{AddPermissionSqlScript}"""; | |
string ProcessArgumentsString = $@"{CommandAddPermission}"; | |
Log.Trace($"Process arguments string: {ProcessArgumentsString}"); | |
ProcessStartInfo info = new ProcessStartInfo(); | |
info.FileName = "sqlcmd.exe"; | |
info.Arguments = ProcessArgumentsString; | |
info.UseShellExecute = true; | |
info.Verb = "runas"; | |
Log.Trace($"Starting Process."); | |
Process AddPermissionProcess = Process.Start(info); | |
Log.Trace($"Waiting for Process to finish."); | |
AddPermissionProcess.WaitForExit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment