Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! python3
- import os
- import subprocess
- import datetime
- from pathlib import Path
- import xml.etree.ElementTree as ET
- ISO_PATH="C:\\Users\\ipony\\Downloads\\ms\\GSP1RMCHPXFRER_RU_DVD.iso"
- SHARED_FOLDER_NAME="vShare"
- SHARED_FOLDER_PATH="C:\\Users\\ipony\\Documents\\vShare"
- def getUniqueVMname():
- name="win_"+datetime.datetime.now().strftime("%y%m%d%H%M%S")
- return name
- def getDefaultMachineFolder():
- VirtualBox_xml_path=Path.home() / '.VirtualBox' / 'VirtualBox.xml'
- tree=ET.parse(VirtualBox_xml_path)
- xml_node=tree.find(".//{http://www.virtualbox.org/}SystemProperties")
- return Path(xml_node.attrib['defaultMachineFolder'])
- def main():
- my_name=getUniqueVMname()
- defaultMachineFolder=getDefaultMachineFolder()
- diskFilePath=os.path.join(defaultMachineFolder, my_name, my_name+".vdi")
- subprocess.call('VBoxManage createvm --name {} --ostype Windows7_64 --register'.format(my_name))
- subprocess.call('VBoxManage modifyvm {} --memory 2048 --vram 128 --pae off --nic1 none'.format(my_name))
- # subprocess.call('VBoxManage modifyvm {} --accelerate3d on --accelerate2dvideo on --graphicscontroller vboxsvga'.format(my_name))
- subprocess.call('VBoxManage createmedium --filename "{}" --size 25600'.format(diskFilePath))
- subprocess.call('VBoxManage storagectl {} --name "SATA" --add sata --controller IntelAhci --portcount 2'.format(my_name))
- subprocess.call('VBoxManage storageattach {} --storagectl "SATA" --port 0 --device 0 --type hdd --medium "{}"'.format(my_name, diskFilePath))
- subprocess.call('VBoxManage sharedfolder add {} --name "{}" --hostpath "{}" --automount'.format(my_name, SHARED_FOLDER_NAME, SHARED_FOLDER_PATH))
- subprocess.call('VBoxManage unattended install {} --iso="{}" --install-additions'.format(my_name, ISO_PATH))
- os.popen('VBoxManage startvm {}'.format(my_name))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement