44

Using virtual box is it possible to set your virtual machine time to be different from host time. Say 1 year into the past.

If I wanted to run the windows XP images provided by Microsoft from here.
http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11575

It is noted for the XP image that:

Expires: This image will shutdown and become completely unusable on February 14, 2013.

It is one of the better ways to test IE 6, and IE 7. Other XP typical tests.

1

7 Answers 7

57

It's no problem at all. Just remember to disable the time synchronisation in the VirtualBox Guest Additions, then set the date+time in the virtual machine as you like. There is also an option to go into the Virtual BIOS and set the date+time there, if that's needed at install time.

This command disables the synchronization:
http://www.virtualbox.org/manual/ch09.html#disabletimesync

VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

The following option allows to set an offset in milliseconds: http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvm

VBoxManage modifyvm "VM name" --biossystemtimeoffset <msec>
4
8

Example of a windows powerShell script

startVM.ps1

# Starts the VM always on the date 12/30/2016

$tempo = ""+([datetime]"12/30/2016" - [datetime]::Now).TotalMilliseconds
$tempo = ""+[math]::Round($tempo)
$nome = "virtualMachineName"

& ${env:ProgramFiles}\Oracle\VirtualBox\VBoxManage setextradata $nome "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

& ${env:ProgramFiles}\Oracle\VirtualBox\VBoxManage modifyvm $nome --biossystemtimeoffset $tempo

& ${env:ProgramFiles}\Oracle\VirtualBox\VBoxManage startvm $nome
1
  • Any idea on why would this not work?, I tried using 2011 and 2012 as the year May 16, 2021 at 20:33
1

Based on the ".ps1" (Windows PowerShell script) example above, I've written a regular ".bat" script file to change the clock time at which the VirtualBox's virtual machine starts.

The desired start time is set at variable "TEMPO_START_TIMESTAMP" in epoch format. You can get your desired start time epoh equivalent at "http://www.timestampconvert.com/".

The name of the VirtualBox's virtual machine to be started is needed in variable "NOME" (same nomenchature used in the ".ps1" script above).

echo off
echo %time%

set NOME="Windows_7_x64"

set TEMPO_CS_2_MS=0
set TEMPO_S_2_MS=000

rem # Starts the VM always on the date 07/11/2014 - 11h58
rem http://www.timestampconvert.com/

set   TEMPO_START_TIMESTAMP=1415361480

for /f "delims=" %%x in ('cscript /nologo toEpoch.vbs') do set epoch=%%x
rem %epoch%

set TEMPO_CURRENT_TIMESTAMP=%epoch%
rem set TEMPO_CURRENT_TIMESTAMP=1544518714

set /A TEMPO_TEMP=(%TEMPO_START_TIMESTAMP%-%TEMPO_CURRENT_TIMESTAMP%)

call set TEMPO=%TEMPO_TEMP%%TEMPO_S_2_MS%
rem %TEMPO_TEMP%
rem %TEMPO%

c:\Progra~1\Oracle\VirtualBox\VBoxManage setextradata %NOME% "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
c:\Progra~1\Oracle\VirtualBox\VBoxManage modifyvm %NOME% --biossystemtimeoffset %TEMPO%
c:\Progra~1\Oracle\VirtualBox\VBoxManage startvm %NOME%

You'll also need the current time in epoh format, for this use the following script (save as "toEpoch.vbs", this visual basic script is called from the ".bat" script above):

WScript.Echo DateDiff("s", "01/01/1970 00:00:00", Now())

To run the virtual machine, simply execute the ".bat" script file above. No need to open the "Oracle VM VirtualBox Administration" interface.

I hope this helps.

Regards

1
  • You should be on the path of VBox, it almost be like that (C:\Program Files\Oracle\VirtualBox)

  • open your Virtual Box and from Start menu > CMD >cd C:\Program Files\Oracle\VirtualBox

  • The prompt will be like this C:\Program Files\Oracle\VirtualBox>
  • Then write the following command: [remember to get your VBox Name] VBoxManage setextradata "Put_your_VM_Name"
    "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
  • Full command will be like this in the CMD
    C:\Program Files\Oracle\VirtualBox>VBoxManage setextradata "Put_your_VM_Name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

after implementing these steps you will be able to change the VBox date and time.

Command of sync Data and time

Good Luck

1

Just some info that can be of help to be known, the command:

VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

Can be run with the "VM name" guest running and it take effect inmediatly (at least on a Windows Host and a Windows Guest).

After run it (also is the guest is running) you can change the date and it does not revert back to host date; there is no need to shutdown or reboot the guest.

1

This command disables the synchronization: http://www.virtualbox.org/manual/ch09.html#disabletimesync

VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

I have used the same code as provided by other answers just you have to replace the "VM name" with your virtual machine name. My Virtual Machine name was Win7. Below is the Screenshot of Command Prompt.

Screen Shot

1

in addition to solution proposed by https://superuser.com/users/684955/eliseu following two changes in his code would let us keep HH:mm the same as on host:

$hm = (get-date).AddMinutes(1).ToString("HH:mm")

$tempo = ""+([datetime]"12/30/2016 $hm" - [datetime]::Now).TotalMilliseconds

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .