Batch file ... works as an administrator

I successfully created a batch file to clear my DNS ...

I added a pause, I noticed in the title bar of the console window ... It does not work as an administrator.

I already tried a couple of variations of this ... Just a small guide would be appreciated best.

I remember reading a blog somewhere, he said that something about capitalization is not important ... Is the camel body important when writing batch files?

@echo off echo. pause CD.. CD.. echo. runas /user:<Administrator> ipconfig /flushdns echo. pause echo. 
0
batch-file administrator runas
source share
1 answer

To execute a command using this method, enter one of the following values:

 RUNAS /NOPROFILE /USER:computername/username "IPCONFIG /FLUSHDNS" RUNAS /PROFILE /ENV /USER:domain/username "IPCONFIG /FLUSHDNS" RUNAS /ENV /USER:username@domain "IPCONFIG /FLUSHDNS" 

Replace "computer_name", "username" and / or "domain" with the corresponding information. The problem with these methods is that they require an administrator password, which I could not figure out on my machine. However, if it is something like linux, it is a random hash hidden by the system. Another way you can try:

32-bit:

 REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V "%HOMEDRIVE%\WINDOWS\System32\ipconfig.exe" /D RUNASADMIN 

64-bit:

 REG ADD "HKLM\SOFTWARE\WOW6432\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V "%HOMEDRIVE%\WINDOWS\System32\ipconfig.exe" /D RUNASADMIN 

This method will add the program to the registry so that it starts with administrator rights every time it starts (compatibility mode). This method only works until your directory changes. You must specify the direct path to the program in your registry. You could have a script look something like this:

 @ECHO OFF CD \ REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V "%HOMEDRIVE%\WINDOWS\System32\ipconfig.exe" /D RUNASADMIN IPCONFIG /FLUSHDNS PAUSE>NUL 

Hope this helps you. You can check Verboon for more information on this REG ADD command and compatibility mode.

+1
source share

All Articles