Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::::::::::::::::::::::::::::::::::::::::::::
- :: Elevate.cmd - Version 4
- :: Automatically check & get admin rights
- :: see "https://stackoverflow.com/a/12264592/1016343" for description
- ::::::::::::::::::::::::::::::::::::::::::::
- @echo off
- CLS
- ECHO.
- ECHO =============================
- ECHO Running Admin shell
- ECHO =============================
- :init
- setlocal DisableDelayedExpansion
- set cmdInvoke=1
- set winSysFolder=System32
- set "batchPath=%~0"
- for %%k in (%0) do set batchName=%%~nk
- set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
- setlocal EnableDelayedExpansion
- :checkPrivileges
- NET FILE 1>NUL 2>NUL
- if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
- :getPrivileges
- if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
- ECHO.
- ECHO **************************************
- ECHO Invoking UAC for Privilege Escalation
- ECHO **************************************
- ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
- ECHO args = "ELEV " >> "%vbsGetPrivileges%"
- ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
- ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
- ECHO Next >> "%vbsGetPrivileges%"
- if '%cmdInvoke%'=='1' goto InvokeCmd
- ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
- goto ExecElevation
- :InvokeCmd
- ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
- ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"
- :ExecElevation
- "%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
- exit /B
- :gotPrivileges
- setlocal & cd /d %~dp0
- if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
- ::::::::::::::::::::::::::::
- ::START
- ::::::::::::::::::::::::::::
- REM Run shell as admin (example) - put here code as you like
- start /wait "" "%~dp0VirtualBox-6.1.32-r149290.msi" /passive
- echo y | "%programfiles%\Oracle\VirtualBox\VBoxManage.exe" extpack install --replace "%~dp0Oracle_VM_VirtualBox_Extension_Pack-6.1.32-149290.vbox-extpack"
- start /wait "" "%programfiles%\Oracle\VirtualBox\VBoxManage.exe" import "%~dp0antiX-21_x64-base.ova"
- start /wait "" "%~dp0share_setup.exe"
- REM End of batch file
- _________________________________________________________________
- share_setup.exe python code
- import glob
- import os
- import subprocess
- import time
- def edit_file(file_loc, search_string, replace_string):
- try:
- with open(file_loc, 'r') as tmp_f:
- tmp_data = str(tmp_f.read()).replace(search_string, replace_string)
- with open(file_loc, 'w') as tmp_f:
- tmp_f.write(tmp_data)
- except Exception as e:
- print('Error in editing file: ' + str(e))
- def find_file_by_string(dir_loc, infile_string):
- file_paths = []
- try:
- for i in glob.iglob(dir_loc + '/**/*', recursive=True):
- if os.path.isfile(i):
- if str(i).__contains__(infile_string):
- file_paths.append(i)
- except Exception as e:
- print('Error in finding file: ' + str(e))
- return file_paths
- def main_run():
- query = 'echo | set /p dummyName="%userprofile%\VirtualBox VMs"'
- response = subprocess.Popen(query, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8').strip()
- vbox_config_loc = find_file_by_string(response, 'antiX-21_x64-base.vbox')[0]
- print('found file location: ' + vbox_config_loc)
- if os.path.isfile(vbox_config_loc):
- replace_string = str(os.path.abspath(os.getcwd() + "/../../"))
- print('new share location: ' + replace_string)
- edit_file(vbox_config_loc, '/media/ramdisk', replace_string)
- time.sleep(3)
- if __name__ == '__main__':
- print('changing default share location, up two levels from current file location...')
- main_run()
- _________________________________________________________________
- the only thing that is missing is "accept dialog" during virtualbox install driver setup, tweak it yourself :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement