0

I have tried suggestion postd here ( https://stackoverflow.com/a/52517718/10011235 ) by Sire. I have replaced cmd.exe with my bat file location. But it did not work.

AsAdmin.bat content :

set "params=%*"
cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || (  echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "%temp%\userfile.bat", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )

here userfile.bat contains netsh command.

Any help is much appreciated !

SomethingDark
  • 13,229
  • 5
  • 50
  • 55
  • 3
    The only way to run a program elevated without a user prompt is to use a scheduled task. – user14797724 Feb 20 '21 at 03:54
  • @user14797724, I need to call this batch file on a certain event from my application ... I have no idea about the possibilities to instruct task scheduler from within my application to execute the script. – Pooja Singh Feb 20 '21 at 23:42
  • After i posted this question i tried few things with my script and got my script running as admin after i pasted content of userfile.bat below the command mentioned above. There was no need to replace cmd.exe with my batch file name. Even though now it runs but it still asks me to click OK to let it run as admin.... since this script supposed to run in back end how can i skip this prompt ? is there a way to pass some argument to run as command may be ..so that it would not prompt for permission ? – Pooja Singh Feb 20 '21 at 23:51
  • 1
    I repeat the **only** way is to schedule a task. See `schtasks /?` for help. EG the `/run` switch. – user14797724 Feb 21 '21 at 03:50
  • `%temp%` is a terrible place to be dropping and executing scripts, especially if they are going to be run elevated. – jwdonahue Feb 21 '21 at 06:36
  • @user14797724, Yes I tried using schtasks command as well, Again it needs an elevated cmd to be able to run. Sorry I did not specify the scenario properly. There are many users using this application and we can not ask them to run this script explicitly. – Pooja Singh Feb 22 '21 at 17:27
  • But now network team has pitched in to handle this issue , though I am not sure how they would be handling. I suppose as Mofi suggested they must create some policy or something. Thank you everyone for all your help!! :) BR , Pooja – Pooja Singh Feb 22 '21 at 17:34

0 Answers0