Set datetime (VBScript)

This code can be found in Chapter 2 of Windows Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' ---------------------------------------------------------------
' From the book "Windows Server Cookbook" by Robbie Allen
' ISBN: 0-596-00633-0
' ---------------------------------------------------------------

WScript.Echo "Current time: " & Now

strCommand = "cmd.exe /c time 23:02:00"
set objWshShell = WScript.CreateObject("WScript.Shell")
intRC = objWshShell.Run(strCommand, 0, TRUE)
if intRC <> 0 then
   WScript.Echo "Error returned from time command: " & intRC
else
   WScript.Echo "time command completed successfully"
end if

strCommand = "cmd.exe /c date 11/01/2004"
intRC = objWshShell.Run(strCommand, 0, TRUE)
if intRC <> 0 then
   WScript.Echo "Error returned from date command: " & intRC
else
   WScript.Echo "date command completed successfully"
end if

WScript.Echo "New time: " & Now

This code has been viewed 2765 times.

New from the creators of TechTasks.com: StatSheet.com