I got a .bat file containing:
call C:\ProgramData\Anaconda3\Scripts\activate.bat conda activate py36 python C:\Users\User\button5.py conda deactivate If I run it directly from command line it works, but wenn I execute the .bat file it stops after conda activate py36 with no error message.
Edit: I see now the problem, when the script is executed in normal prompt it dosen't work, it works only in admin command prompt. But when I run the .bat as admin the normal prompt starts. How can I force it to open with admin cmd?
21 Answer
Yes you can make the batch file auto-elevate:
goto="Batch" /* :Admin call C:\ProgramData\Anaconda3\Scripts\activate.bat conda activate py36 python C:\Users\User\button5.py conda deactivate exit /b 0 :RunAsAdmin color 4f & echo Running Admin Shell, Please wait.... & call cscript //nologo /e:JScript "%~f0" RunAsAdmin "%1" & exit /b :"Batch" @echo off & setlocal enabledelayedexpansion & cls openfiles >nul 2>&1 || goto :RunAsAdmin goto :Admin :"JScript" */ function RunAsAdmin(self, arguments) { WSH.CreateObject('Shell.Application').ShellExecute(self, arguments, '', 'runas', 1) } if (WSH.Arguments.length>=1 && WSH.Arguments(0)=='RunAsAdmin') RunAsAdmin(WSH.ScriptFullName,WSH.Arguments(1)); // It will check for elevated priviliges, and if not present an UAC dialog for prompting for administrative priviliges. Another way:
@echo off & powershell.exe -command "& {Start-Process cmd.exe -ArguemntList 'conda activate py36 & python C:\Users\User\button5.py & conda deactivate' -Verb RunAs}" 3