Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run jupyter lab within Anaconda when open .ipynb file.
@echo off
@REM To associate extension with file type
@REM assoc [<.ext>[=[<filetype>]]]
@REM To set open command for file type
@REM ftype [<filetype>[=[<opencommandstring>]]]
@REM To set up Anaconda environment. Replace PATH at the end.
@REM cmd.exe "/K" PATH:to\Anaconda3\Scripts\activate.bat PATH:to\env
@REM Get admin
@REM Check for permissions
if "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) else (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)
@REM If error flag set, we do not have admin.
if '%errorlevel%' neq '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else (
goto gotAdmin
)
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params= %*
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
@REM Get admin end
assoc .ipynb=jupyter
ftype jupyter=cmd.exe /k "PATH:to\Anaconda3\Scripts\activate.bat PATH:to\env& jupyter lab"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.