Set the 'bios' time of the virtual box.

Discussions about using Windows guests in VirtualBox.
bismutant
Posts: 2
Joined: 16. Jun 2009, 10:57
Primary OS: MS Windows XP
VBox Version: OSE other
Guest OSses: Win XP

Re: Set the 'bios' time of the virtual box.

Post by bismutant »

Hi guys,

yes "vbox4me2", your right. After posting the message I realized that. You do not have to remove completely the VBox guest additions (don´t know why). I have done the following to prevent my Windows XP from synchronisation of time:

go to:
Start->Settings->Control panel->managment->Services->Virtual Box Geust Additions (end this service and deactivate it)

Start->Settings->Control panel->managment->Services->Windows Time Service (end this service and deactivate it)

In taskbar go to date ssettings and deactivate time synchronisation with microsoft server

Now take a snapshot of the virtual machine and your done!


Becaus I have a german System here it´s in german:

Start->Einstellungen->Systemsteuerung->Verwaltung->Dienste->Virtual Box Geust Additions (Dienst beenden und deaktivieren)

Start->Settings->Control panel->managment->Services->Windows-Zeitgeber (Dienst beenden und deaktivieren)

In taskbar Doppelklick auf das Datum und unter "Internetzeit" das Häckchen wegmachen für synchronisation mit Microsoft Zeitwerver.
Nun einen Sicherungspunkt erstellen und das wars!
itaics
Posts: 2
Joined: 21. Aug 2009, 23:20
Primary OS: MS Windows 7
VBox Version: OSE Debian
Guest OSses: XP

Re: Set the 'bios' time of the virtual box.

Post by itaics »

Here is some Windows Script I've Written... Can be better I Know :D
Copy & Paste The Following Into A File. I Call It VMx-TimeOffset.bat

Code: Select all

@echo off

cls
echo VMx Timeoffset Patcher v0.01.
echo Copyright(c) 2009 by ET.
echo.

if x%1==x goto Help
SET MS=0
if x%2==x goto Path
Set MS=%2

:Path
SET APPLICATIONPATH="C:\Program Files\Sun\xVM VirtualBox"
IF x%3==x goto Validate
SET APPLICATIONPATH=%3

:Validate
echo Search for VBoxManage.exe in %APPLICATIONPATH%
echo.
rem Check For File Existence
IF EXIST %APPLICATIONPATH%\vboxmanage.exe GOTO Patch
ECHO Path Wrong! Can not Find VirtualBox Folder.
Goto End

:Patch
echo Patching %1 with %MS% Offset:
%APPLICATIONPATH%\vboxmanage modifyvm %1 -biossystemtimeoffset %MS%
echo Time Offset Succesfully Changed.
goto End


:Help
echo.
echo Batch Usage: VMx-TimeOffset ("Virtual Machine Name") (Offset in Milliseconds) (Optional: VirtualBox Path)
echo.
echo Ex. VMx-TimeOffset "ET VMx Server"                                
echo Revert The Machine To Offset 0
echo.
echo Ex. VMx-TimeOffset "ET VMx Server" 1000000
echo Revert The Machine To Offset 1000000
echo.
echo Ex. VMx-TimeOffset "ET VMx Server" 10 C:\VirtualBox
echo Revert The Machine To Offset 10 In Non Standart Path
echo.

:End
pause
Last edited by socratis on 6. Jan 2019, 19:49, edited 1 time in total.
Reason: Enclosed the information in [code] tag for better readability
itaics
Posts: 2
Joined: 21. Aug 2009, 23:20
Primary OS: MS Windows 7
VBox Version: OSE Debian
Guest OSses: XP

Re: Set the 'bios' time of the virtual box.

Post by itaics »

everyone.. at my last script post... There are two Smiles...

There Should Be : P (Without Space), but it's written here at the forum as :P


[ModEdit: fixed on 2019-01-06, by enclosing the script in the <code> tag]
onwieze
Posts: 1
Joined: 9. Dec 2010, 16:07
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Ubuntu & Windows

Re: Set the 'bios' time of the virtual box.

Post by onwieze »

For those who want to have the virtual machine at a certain date when it is started, I created a script with variables so one can reuse it.
It is just for Windows users, its a .cmd file so you can just double click it after you have set the variables.

One can specify the date of the bios for the virtual machine. Every time you boot the virtual machine using this file the offset is recalculated and set for the specified date.

I know it's not pretty doing it this way and the date calculation is not exact, but it has no dependencies this way and it works pretty well. Also the time (not the date of course) in the guest will be the same as on the host...
This script is also attached as a .txt file, rename it to .cmd on your computer.

Code: Select all

@echo off

REM Set the path of the VBoxManage executable.
set vboxmanage="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"

REM Set the name or uuid of the virtualbox to start.
set vmname="Type the name of the VM here..."

REM Set the target date information.
set target_day=10
set target_month=11
set target_year=2010

REM The tokens delims for the output of date, check with date /t what your format is.
REM [Dutch]      When the output is in the format 'do 24-05-2010' the value must be "tokens=2 delims=\ "
REM [US/English] When the output is in the format '24-05-2010' the value must be "tokens=1 delims=\ "
set tokens_delims_output="tokens=2 delims=\ "

REM The tokens and delims for the date, this specifies the delimiter of the date.
REM [Dutch] First, second and third value when delimited by a '-', set the value to "tokens=1,2,3 delims=-"
REM [US] First, second and third value when delimited by a '/', set the value to "tokens=1,2,3 delims=/"
REM [German] First, second and third value when delimited by a '.', set the value to "tokens=1,2,3 delims=\."
set tokens_delims_date="tokens=1,2,3 delims=-"



:getcurrentdate
REM Get the current year.
REM Set the token to 1 when the date /t does only output the date (without day name), otherwise this must be 2.
@For /F %tokens_delims_output% %%A in ('Date /t') do @(
  Set current_date=%%A
)

REM Change the character after delims with the delimiter for your date.
REM Also reverse the day and month value assignment, if the month comes before the day in your date locale.
@For /F %tokens_delims_date% %%A in ('echo %current_date%') do @(
  Set current_day=%%A
  Set current_month=%%B
  Set current_year=%%C
)

REM Check whether the day of the month start with a 0, than remove that char.
set current_day_first_char=%current_day:~0,1%
set current_day_second_char=%current_day:~1,1%
if "%current_day_first_char%" == "0" set current_day=%current_day_second_char%

REM Check whether the month start with a 0, than remove that char.
set current_month_first_char=%current_month:~0,1%
set current_month_second_char=%current_month:~1,1%
if "%current_month_first_char%" == "0" set current_month=%current_month_second_char%

echo The current year is '%current_year%', month is '%current_month%' and day is '%current_day%'.



:calculatedatediff
REM We first multiply the number of months with 30, than we check
set /a days_per_month=365/12

set /a target_finishedmonths=%target_month%-1
set /a current_finishedmonths=%current_month%-1

set /a target_dayofyear_finishedmonths=%target_finishedmonths%*%days_per_month%
set /a current_dayofyear_finishedmonths=%current_finishedmonths%*%days_per_month%

set /a target_dayofyear=%target_dayofyear_finishedmonths%+%target_day%
REM echo target_dayofyear=%target_dayofyear%
set /a current_dayofyear=%current_dayofyear_finishedmonths%+%current_day%
REM echo current_dayofyear=%current_dayofyear%
set /a year_diff=%current_year%-%target_year%

set /a day_diff=%current_dayofyear%-%target_dayofyear%
REM echo day_diff=%day_diff%

if %day_diff% GEQ 0 goto :calculateoffset

echo Calculating the day and year diff because current_dayofyear is less than target_dayofyear.
set /a day_diff=365+%day_diff%
set /a year_diff-=1
goto :calculateoffset



:calculateoffset
echo Calculating the offset for %year_diff% year(s) and %day_diff% day(s) back.

REM We calculate in seconds and add 3 zeros in the argument to overcome the problem of not being able to create integers greater than 32 bit.
REM The value of the month is the year seconds devided by 12, so this is not exact.
REM 1 year in seconds: 365,25*24*60*60 = 31557600 sec
set year_seconds=31557600
set day_seconds=86400

set /a timeoffset=%year_diff%*%year_seconds%
set /a timeoffset+=%day_diff%*%day_seconds%
set /a timeoffset=%timeoffset%*-1
set timeoffset_milliseconds=%timeoffset%000

echo Setting the virtualbox %vmname% with an offset of %timeoffset_milliseconds% msec.
%vboxmanage% modifyvm %vmname% --biossystemtimeoffset %timeoffset_milliseconds%

echo Starting the virtual machine %vmname%.
%vboxmanage% startvm %vmname%

goto :eof
Attachments
startVMWithDateOffset.txt
(4.09 KiB) Downloaded 1254 times
lorcat
Posts: 1
Joined: 29. Jul 2011, 10:24
Primary OS: MS Windows XP
VBox Version: PUEL
Guest OSses: Windows XP, Linux, FreeBSD

Re: Set the 'bios' time of the virtual box.

Post by lorcat »

One can also use this to calculate number of milliseconds when needed
http://www.wolframalpha.com/input/?i=to ... lliseconds
rdutton1971
Posts: 1
Joined: 24. Jul 2015, 17:28

Re: Set the 'bios' time of the virtual box.

Post by rdutton1971 »

thank you, this gave me what i needed to know (even though im just lurking ;)). btw in hopes that this helps someone... instead of writting long scripts in anything linux users can simply say:
let msec="$(($(date -d "2 years ago" +"%s")*1000))"
then change the date calculation to just about anything from a specific date to an offset worded most logical ways works...

this case would return the number of milliseconds from 1/1/1970 for 2 years ago... if you want the offset from now just do the same thing and subtract the 2... i.e.
let msecoff="$(( ($(date +"%s") - $(date -d "2 years ago" +"%s")) *1000 ))"
and for all you micro$oft folks out there cygwin (www dot cygwin dot com) goes a long way ;) that and perhaps some form of :

Code: Select all

cmd /c "$(which vboxmanage.exe)"  modifyvm --biossystemtimeoffset "$(( ($(date +"%s") - $(date -d "2 years ago" +"%s")) *1000 ))"
but no m$ box in front of me to test it... but should be close
qwertyfish01
Posts: 13
Joined: 15. Mar 2015, 22:09

Re: Set the 'bios' time of the virtual box.

Post by qwertyfish01 »

I don't have Guest Additions because I am trying to install Windows Whistler, which will not install unless it is set to a certain time. In order to install Guest Additions, you have to install the OS, and that's a problem for me. How do I set the time then?
loukingjr
Volunteer
Posts: 8851
Joined: 30. Apr 2009, 09:45
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: just about all that run

Re: Set the 'bios' time of the virtual box.

Post by loukingjr »

qwertyfish01 wrote:I don't have Guest Additions because I am trying to install Windows Whistler, which will not install unless it is set to a certain time. In order to install Guest Additions, you have to install the OS, and that's a problem for me. How do I set the time then?
Windows "Whistler" was the pre-release version of XP. It is an OS of course. How are you planning to install an OS without installing the OS?
OSX, Linux and Windows Hosts & Guests
There are three groups of people. Those that can count and those that can't.
qwertyfish01
Posts: 13
Joined: 15. Mar 2015, 22:09

Re: Set the 'bios' time of the virtual box.

Post by qwertyfish01 »

That's my problem. I have to set the time before installing the OS or else Windows will not install. But I have to install Guest Additions with Windows running on the VM, and it's making me mad.
loukingjr
Volunteer
Posts: 8851
Joined: 30. Apr 2009, 09:45
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: just about all that run

Re: Set the 'bios' time of the virtual box.

Post by loukingjr »

FWIW, here are several links that address the issue…
https://www.google.com/search?q=install ... 8&oe=utf-8
OSX, Linux and Windows Hosts & Guests
There are three groups of people. Those that can count and those that can't.
loukingjr
Volunteer
Posts: 8851
Joined: 30. Apr 2009, 09:45
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: just about all that run

Re: Set the 'bios' time of the virtual box.

Post by loukingjr »

OSX, Linux and Windows Hosts & Guests
There are three groups of people. Those that can count and those that can't.
N.M.Kloster
Posts: 1
Joined: 19. Oct 2015, 15:53

Re: Set the 'bios' time of the virtual box.

Post by N.M.Kloster »

I cannot set the BIOS time offset. I shut down the guest. I execute the command-lines for disabling synchronization and for offsetting BIOS time. I can see the lines are added to the .vbox settings-file, but when I start the guest (Win server 2008) the time is still synchronized. When I exit the guest (either pause or shut down) the .vbox-file is overwritten with default values.
Legorol
Posts: 95
Joined: 11. Mar 2014, 21:40

Re: Set the 'bios' time of the virtual box.

Post by Legorol »

N.M.Kloster wrote:I cannot set the BIOS time offset. I shut down the guest. I execute the command-lines for disabling synchronization and for offsetting BIOS time. I can see the lines are added to the .vbox settings-file, but when I start the guest (Win server 2008) the time is still synchronized. When I exit the guest (either pause or shut down) the .vbox-file is overwritten with default values.
If your guest (Win Server 2008) is connected to the Internet, then itself will automatically synchronize the time using network time servers by default. So in addition to disabling all VirtualBox time synchronization features, you also have to disable any such settings in the guest OS as well.
The_Orcale
Posts: 1
Joined: 21. Apr 2016, 11:15

Re: Set the 'bios' time of the virtual box.

Post by The_Orcale »

I made a Powershell script that runs from a single .bat file with pop-ups for user input.
Just copy all the code to an empty .bat file, edit the virtualbox name and you're ready to go!
Tip: If you want the .bat file to run minimized just create a shortcut to the .bat and edit the settings of the shortcut.

Disclamer: The code is tested i W7 64-bit and works for me. However you are using the code at your own risk!

It can surely be written in a better manner so I challenge you to prove that you are better than me. (which shouldn't be hard)

Code: Select all

;@echo off
;@Findstr -bv ;@ "%~f0" | powershell -noprofile -command - & goto:eof
# All except ;@ is a powershell script!

# Config parameters #
# Path of the VBoxManage executable.
$VB_MANAGE ='C:\Program Files\Oracle\VirtualBox\VBoxManage'

# Name or uuid of the virtualbox to start.
$vmname ='ENTER NAME HERE'

# Default BIOS time mm/dd/yyyy
$BIOStime = '12/08/2015'

function CustomInputBox([string] $title, [string] $message, [string] $defaultText) {
  [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
  [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

 $userForm = New-Object System.Windows.Forms.Form
  $userForm.Text = "$title"
  $userForm.Size = New-Object System.Drawing.Size(300,150)
  $userForm.StartPosition = "CenterScreen"
      $userForm.AutoSize = $False
      $userForm.MinimizeBox = $False
      $userForm.MaximizeBox = $False
      $userForm.SizeGripStyle= "Hide"
      $userForm.WindowState = "Normal"
      $userForm.FormBorderStyle="Fixed3D"  
      $userForm.ShowInTaskBar = $False
     
  $OKButton = New-Object System.Windows.Forms.Button
  $OKButton.Location = New-Object System.Drawing.Size(115,80)
  $OKButton.Size = New-Object System.Drawing.Size(75,23)
  $OKButton.Text = "OK"
  $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
  $userForm.AcceptButton = $OKButton
  $userForm.Controls.Add($OKButton)
  $OKButton.tabindex = 1

 $CancelButton = New-Object System.Windows.Forms.Button
  $CancelButton.Location = New-Object System.Drawing.Size(195,80)
  $CancelButton.Size = New-Object System.Drawing.Size(75,23)
  $CancelButton.Text = "Cancel"
  $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
  $userForm.CancelButton = $CancelButton
  $userForm.Controls.Add($CancelButton)
  $CancelButton.tabindex = 2

 $userLabel = New-Object System.Windows.Forms.Label
  $userLabel.Location = New-Object System.Drawing.Size(20,20)
  $userLabel.Size = New-Object System.Drawing.Size(280,20)
  $userLabel.Text = "$message"
  $userForm.Controls.Add($userLabel) 

 $objTextBox = New-Object System.Windows.Forms.TextBox
  $objTextBox.Location = New-Object System.Drawing.Size(100,40)
  $objTextBox.Size = New-Object System.Drawing.Size(100,20)
  $objTextBox.Text="$defaultText"
  $userForm.Controls.Add($objTextBox) 
  $objTextBox.tabindex = 0

 $userForm.Topmost = $True
  $userForm.Opacity = 1
  $userForm.ShowIcon = $False

 $userForm.Add_Shown({$userForm.Activate(); $objTextBox.Focus()})
 $dialogResult = $userForm.ShowDialog()
 if ($dialogResult -eq [System.Windows.Forms.DialogResult]::OK) { $objTextBox.Text } 
 $userForm.dispose() }

do {
$title = "Input BIOS date for VM $vmname"
$msg   = "Enter new BIOS date in the format of mm/dd/yyyy:"
$reply = CustomInputBox $title $msg $BIOStime
if($reply.Length -eq 0) { exit }
$date = ($reply + " " + [datetime]::Now.ToShortTimeString()) -as [datetime]
if (!$date) { $shell = new-object -comobject "WScript.Shell"
$shell.popup("Date is not in a valid format",0,"Syntax error",0+48+4096) }
} while ($date -isnot [datetime])

start-process $VB_MANAGE 'setextradata', $vmname, 'VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled 1' -NoNewWindow 

$timeoffset_milliseconds='{0:0}' -f ([datetime]$date - [datetime]::Now).TotalMilliseconds

$shell = new-object -comobject "WScript.Shell"
$result = $shell.popup("Do you want to set the BIOS time of virtualbox $vmname to $date wich equals an offset of $timeoffset_milliseconds msec from current time and start the virtual machine?",0,"Verify action for VM $vmname",4+32+4096)
# $result will be 6 for yes, 7 for no.
if ($result -eq 7) { exit }

start-process $VB_MANAGE 'modifyvm', $vmname, '--biossystemtimeoffset', $timeoffset_milliseconds -NoNewWindow 

echo "Starting the virtual machine $vmname"
start-process $VB_MANAGE startvm, $vmname

exit
And finally a Thank You! to all who have written examples on the net that I used to get this script working!
nostradamus
Posts: 1
Joined: 26. Aug 2017, 14:28

Re: Set the 'bios' time of the virtual box.

Post by nostradamus »

Hi guys
I am new in this forum, sorry for my bad english i am from Belgium i want to use the script from above !!!

I youst startet the batch file in the host operation system change the start date click ok evething woks fine the exact Virtualmachine startet automaticly just fine but the the systen date is the original from the host system
- what´s wrong ?
- is there any specific installation guide " how to "
- host operation system is win7 64 bit and guest operation system is win 10 64 bit

thanks for any help .......................
Post Reply