How to run a program automatically as admin on Windows 7 at startup?

You need to plug it into the task scheduler, such that it is launched after login of a user, using a user account that has administrative access on the system, with the highest privileges that are afforded to processes launched by that account. This is the implementation that is used to autostart processes with administrative … Read more

Detect if running as Administrator with or without elevated privileges?

Try this out: using Microsoft.Win32; using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Security.Principal; public static class UacHelper { private const string uacRegistryKey = “Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System”; private const string uacRegistryValue = “EnableLUA”; private static uint STANDARD_RIGHTS_READ = 0x00020000; private static uint TOKEN_QUERY = 0x0008; private static uint TOKEN_READ = (STANDARD_RIGHTS_READ | TOKEN_QUERY); [DllImport(“advapi32.dll”, SetLastError = true)] [return: … Read more

Windows batch file starting directory when ‘run as admin’

Try to access the batch files path like this: echo %~dp0 For more information see the following quote from the command for /? that describes how the above command works: You can now use the following optional syntax: %~I – expands %I removing any surrounding quotes (“) %~fI – expands %I to a fully qualified … Read more

Request UAC elevation from within a Python script?

As of 2017, an easy method to achieve this is the following: import ctypes, sys def is_admin(): try: return ctypes.windll.shell32.IsUserAnAdmin() except: return False if is_admin(): # Code of your program here else: # Re-run the program with admin rights ctypes.windll.shell32.ShellExecuteW(None, “runas”, sys.executable, ” “.join(sys.argv), None, 1) If you are using Python 2.x, then you should … Read more

How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?

There is an easy way without the need to use an external tool – it runs fine with Windows 7, 8, 8.1, 10 and 11 and is backwards-compatible too (Windows XP doesn’t have any UAC, thus elevation is not needed – in that case the script just proceeds). Check out this code (I was inspired by the … Read more

Can you force Visual Studio to always run as an Administrator in Windows 8?

In Windows 8, Windows 10, and Windows 11, you have to right-click devenv.exe and select “Troubleshoot compatibility”. Select “Troubleshoot program” Check “The program requires additional permissions” Click “Next” Click “Test the program…” Wait for the program to launch Click “Next” Select “Yes, save these settings for this program” Click “Close” If, when you open Visual … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)