Search code examples
batch-filetimestampwindows-xpxcopy

batch command to backup folders and rename with timestamp doesn't works in XP power user permission


I have formed a batch command script below but it doesn't work in Windows XP with Power User permission

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%

set stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%

xcopy "D:\secure" "D:\secure_bak\bak - %stamp%" /i

I am getting an error as below

Failed to register mof file(s). Only the administrator group members can use WMIC.EXE. Reason:Win32 Error: Access is denied

Please suggest alternative for WMIC.EXE so I can also use this with Power User permission in XP.

Thank in advance for your help.

Regards,


Solution

  • This script gives you reliable variables but using VBS in a batch file:

      :: date time using WSH/VBS
      :: datetime.bat V4.2
      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      ::
      :: This uses Windows Scripting Host to set variables to
      :: the current date/time/day/day_number/week_of_year etc
      :: for Win9x/ME/NT/W2K/XP/Vista/Win7/Win8 etc
      :: Thanks go to Todd Vargo for his scripting
      ::
      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      @echo off
      set TmpFile="%temp%.\tmp.vbs"
      echo> %TmpFile% n=Now
      echo>>%TmpFile% With WScript
      echo>>%TmpFile% .Echo "set m1="   + monthname(month(n), true)
      echo>>%TmpFile% .Echo "set m2="   + monthname(month(n), false)
      echo>>%TmpFile% .Echo "set woy="  + CStr(datepart("ww", n))
      echo>>%TmpFile% .Echo "set year=" + CStr(Year(n))
      echo>>%TmpFile% .Echo "set yr="   + Right(Year(n),2)
      echo>>%TmpFile% .Echo "set month="+ Right(100+Month(n),2)
      echo>>%TmpFile% .Echo "set day="  + Right(100+Day(n),2)
      echo>>%TmpFile% .Echo "set hour=" + Right(100+Hour(n),2)
      echo>>%TmpFile% .Echo "set min="  + Right(100+Minute(n),2)
      echo>>%TmpFile% .Echo "set sec="  + Right(100+Second(n),2)
      echo>>%TmpFile% .Echo "set dow="  + WeekDayName(Weekday(n),1)
      echo>>%TmpFile% .Echo "set dow2=" + WeekDayName(Weekday(n))
      echo>>%TmpFile% .Echo "set iso="  + CStr(1 + Int(n-2) mod 7)
      echo>>%TmpFile% .Echo "set iso2=" + CStr(Weekday(n,2))
      echo>>%TmpFile% End With
      cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
      call "%temp%.\tmp.bat"
      del  "%temp%.\tmp.bat"
      del  %TmpFile%
      set TmpFile=
      set stamp=%year%-%month%-%day%.%hour%_%min%_%sec%
    
      if not "%~1"=="" goto :EOF
    
      echo The year  is "%year%" or "%yr%"
      echo The month is "%month%" "%m1%" "%m2%"
      echo The day   is "%day%" "%dow%" "%dow2%"
      echo.
      echo ISO8601 Day-Of-Week number is "%iso%" and week of year is: "%woy%"
    
      echo.
      echo The time in hh:mm:ss is "%hour%:%min%:%sec%"
      echo The hour   is "%hour%"
      echo The minute is "%min%"
      echo The second is "%sec%"
      echo.
    
      echo The date and time stamp is "%stamp%"
      echo.
      echo date A yyyymmdd "%year%%month%%day%"
      echo date B mmddyyyy "%month%%day%%year%"
      echo date C ddmmyyyy "%day%%month%%year%"
      echo date D yymmdd   "%yr%%month%%day%"
      echo date E mmddyy   "%month%%day%%yr%"
      echo date F ddmmyy   "%day%%month%%yr%"
      pause
      :: datetime.bat
      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::