@echo off :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: You must set the 3 variables below: :: :: 1. "partSize"- :: :: Vista Users: 1. If mounting to the Persistent Storage, set this to 0 (zero). :: :: 2. If creating an additional partition, set the size (in MB) of the partition to create:: :: XP users: should set this to 0 (zero). :: :: :: :: 2. "partLetter" is the drive letter of the additional partition or Persistent Storage drive (whichever you are mounting to):: :: Vista and Windows 7 users are recommended to set a partition size. :: :: XP users: must use the Persistent Storage drive letter or have an additional partition already created. :: :: :: :: 3. "junctionDir" is the directory to mount to the partition--USE QUOTES IF THERE ARE SPACES IN THE FILE PATH!! :: :: :: :: NOTE: The directory specified for the junctionDir variable will remain unprotected. This will allow perminent changes to :: :: be made to this directory. :: :: :: :: :: :: :: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: 3 Variables for user to define... Set partSize= Set partLetter= Set junctionDir="" :: Sends OS version to file, processes file, assigns value to variable, and deletes file ver>C:\version.txt For /f "skip=1 tokens=3" %%a IN (C:\version.txt) DO ( set version=%%a ) del /f /q C:\version.txt ::Checks OS IF %version% EQU XP GOTO XPMount :PartitionCheck IF %partSize% EQU 0 GOTO Mount :Disk :: Writes Diskpart commands to file >"C:\diskpart_commands.txt" echo select disk 0 >>"C:\diskpart_commands.txt" echo select partition 1 >>"C:\diskpart_commands.txt" echo shrink desired=%partSize% >>"C:\diskpart_commands.txt" echo create partition primary >>"C:\diskpart_commands.txt" echo assign letter=%partLetter% >>"C:\diskpart_commands.txt" echo format fs=ntfs >>"C:\diskpart_commands.txt" echo exit :: Runs Diskpart commands diskpart /s "C:\diskpart_commands.txt" del /f /q "C:\diskpart_commands.txt" GOTO Mount :EndDisk GOTO EOF :Mount :: Writes Volume Name for mount point to text file mountvol %partLetter%:\ /l>"C:\VolumeName.txt" :: Assigns Volume Name to variable from text file set /p volname= <"C:\VolumeName.txt" :: This moves all files from the junction directory to the volume it will be mounted on. ::A directory cannot be mounted w/ files in it. robocopy /e /r:2 /w:1 %junctionDir% %partLetter%:\ rd /s /q %junctionDir% md %junctionDir% :: CREATES THE JUNCTION TO THE VOLUME mountvol %junctionDir% %volname% :: Deletes temp file holding string value del /f /q "C:\VolumeName.txt" :EndMount GOTO EOF :XPMount ::Creates a RunOnce registry entry to execute the batch file ::This must be done in XP, b/c the xcopy command cannot be used in a remote execute script (i.e. as SYSTEM acct) reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce" /f /v Mount /t REG_SZ /d "C:\xpmount.bat" ::Writes commands to batch file for RunOnce >C:\xpmount.bat echo xcopy /e /c /q /h /k /y %junctionDir% %partLetter%:\ >>C:\xpmount.bat echo rd /s /q %junctionDir% >>C:\xpmount.bat echo md %junctionDir% ::Processing to get volume name for RunOnce batch mountvol %partLetter%:\ /l>"C:\VolumeName.txt" set /p volname= <"C:\VolumeName.txt" ::Writes commands to batch file for RunOnce >>C:\xpmount.bat echo mountvol %junctionDir% %volname% ::Additional RunOnce batch reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce" /f /v Mount1 /t REG_SZ /d "C:\xpmount1.bat" >C:\xpmount1.bat echo del /f /q "C:\VolumeName.txt" >>C:\xpmount1.bat echo del /f /q "C:\xpmount.bat" >>C:\xpmount1.bat echo del /f /q "C:\xpmount1.bat" :EndXPMount :EOF ::Reboots the computer shutdown -f -r -t 10