Advertisement
Guest User

vbox_unattended

a guest
Mar 5th, 2020
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. #! python3
  2. import os
  3. import subprocess
  4. import datetime
  5. from pathlib import Path
  6. import xml.etree.ElementTree as ET
  7.  
  8.  
  9. ISO_PATH="C:\\Users\\ipony\\Downloads\\ms\\GSP1RMCHPXFRER_RU_DVD.iso"
  10. SHARED_FOLDER_NAME="vShare"
  11. SHARED_FOLDER_PATH="C:\\Users\\ipony\\Documents\\vShare"
  12.  
  13.  
  14. def getUniqueVMname():
  15.     name="win_"+datetime.datetime.now().strftime("%y%m%d%H%M%S")
  16.     return name
  17.  
  18.  
  19. def getDefaultMachineFolder():
  20.     VirtualBox_xml_path=Path.home() / '.VirtualBox' / 'VirtualBox.xml'
  21.     tree=ET.parse(VirtualBox_xml_path)
  22.     xml_node=tree.find(".//{http://www.virtualbox.org/}SystemProperties")
  23.     return Path(xml_node.attrib['defaultMachineFolder'])
  24.  
  25.  
  26. def main():
  27.     my_name=getUniqueVMname()
  28.     defaultMachineFolder=getDefaultMachineFolder()
  29.     diskFilePath=os.path.join(defaultMachineFolder, my_name, my_name+".vdi")
  30.  
  31.     subprocess.call('VBoxManage createvm --name {} --ostype Windows7_64 --register'.format(my_name))
  32.     subprocess.call('VBoxManage modifyvm {} --memory 2048 --vram 128 --pae off --nic1 none'.format(my_name))
  33.     # subprocess.call('VBoxManage modifyvm {} --accelerate3d on --accelerate2dvideo on --graphicscontroller vboxsvga'.format(my_name))
  34.     subprocess.call('VBoxManage createmedium --filename "{}" --size 25600'.format(diskFilePath))
  35.     subprocess.call('VBoxManage storagectl {} --name "SATA" --add sata --controller IntelAhci --portcount 2'.format(my_name))
  36.     subprocess.call('VBoxManage storageattach {} --storagectl "SATA" --port 0 --device 0 --type hdd --medium "{}"'.format(my_name, diskFilePath))
  37.     subprocess.call('VBoxManage sharedfolder add {} --name "{}" --hostpath "{}" --automount'.format(my_name, SHARED_FOLDER_NAME, SHARED_FOLDER_PATH))
  38.     subprocess.call('VBoxManage unattended install {} --iso="{}" --install-additions'.format(my_name, ISO_PATH))
  39.     os.popen('VBoxManage startvm {}'.format(my_name))
  40.  
  41.  
  42. if __name__ == "__main__":
  43.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement