shiner Posted May 12, 2012 Posted May 12, 2012 I did a search, but didn't come up with anything useful quickly, so:Is there an environment variable or method to grab the date and the currentuser name from a system which can be used in an inf based installer?The inf, after getting the date and currentuser name, will then add this information to the registry of the target system. Quote
ricktendo Posted May 12, 2012 Posted May 12, 2012 Not that I am aware of, if you know how to use cmd or another executable to do it I could probably figure out a way to add it to INF Quote
IceBlackIce Posted May 12, 2012 Posted May 12, 2012 There is the %date% and %username%, at least in Win7...not sure about previous OS Quote
Mr_Smartepants Posted May 12, 2012 Posted May 12, 2012 Here's what I do with batch commands.REM :: This sets the environment variable TimeStamp to the format YYYYMMDD_HHMM. Any leading zeros are dropped.REM :: Adapted from: http://blogs.technet.com/b/pfe-ireland/archive/2008/05/08/batch-files-date-stamp-in-a-filename.aspxSET "TimeStamp="FOR /f "tokens=1-4 delims=/ " %%i in ("%date%") do SET "datestr=%%l%%j%%k"FOR /f "tokens=1-4 delims=.: " %%i in ("%time%") do SET "timestr=%%i%%j"SET "TimeStamp=%datestr%_%timestr%"REM :: Strips any spaces from the variable and replaces them with underscores.SET "TimeStamp=%TimeStamp: =_%" Quote
bphlpt Posted May 12, 2012 Posted May 12, 2012 (edited) Date can be VERY tricky if you want to make sure that it works correctly worldwide. I've used this reliably::: #############################################################################:: :f_GetDate _TodayDate _Year _Month _DayOfMonth:::: Load the ISO format date for today and local date components into variables.:::: Usage: CALL :f_GetDate _TodayVariable _YearVariable _MonthVariable _DayOfMonthVariable:::: This function should get the correct local system date components copied:: into the arguments, passed by reference, regardless of where in the world:: this is run, independent of "International" settings. The arguments are::::: %1 - Variable to receive the date in ISO format (by ref):: %2 - Variable to receive year, 4 digits (by ref):: %3 - Variable to receive month, 2 digits, 01 to 12 (by ref):: %4 - Variable to receive day of month, 2 digits, 01 to 31 (by ref):::: The date in ISO format is equivalent to: %_Year%-%_Month%-%_DayOfMonth%:::: Dependencies: START, REGEDIT [Utilizes a temp file %TEMP%.\_Temp.reg]:::: Originally writen by Rob van der Woude - http://www.robvanderwoude.com as:: SortDate, Version 3.10 for Windows NT4/2000/XP. Adapted for Windows XP with:: help from Kailash Chanduka. Modified slightly by bphlpt.:::: Upon exit, ERRORLEVEL is set to 0.:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:::f_GetDate _TodayDate _Year _Month _DayOfMonthSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION:: Export registry settings to temp file, read exported dataSTART "GET iDATE and sDATE" /WAIT REGEDIT /E "%TEMP%.\_Temp.reg" "HKEY_CURRENT_USER\Control Panel\International"FOR /F "tokens=1* delims==" %%G IN ('TYPE "%TEMP%.\_Temp.reg" ^| FIND /I "iDate"') DO (SET _iDate=%%H)FOR /F "tokens=1* delims==" %%G IN ('TYPE "%TEMP%.\_Temp.reg" ^| FIND /I "sDate"') DO (SET _sDate=%%H):: Delete quotes and delete temp file(SET _iDate=%_iDate:"=%)(SET _sDate=%_sDate:"=%)del "%TEMP%.\_Temp.reg" >nul 2>&1:: Parse today's date depending on registry's date format settingsIF %_iDate%==0 (FOR /F "tokens=1-4* delims=%_sDate%" %%G IN ('DATE/T') DO (SET "_Year=%%I"&SET "_Month=%%G"&SET "_Day=%%H")) ELSE (IF %_iDate%==1 (FOR /F "tokens=1-4* delims=%_sDate%" %%G IN ('DATE/T') DO (SET "_Year=%%I"&SET "_Month=%%H"&SET "_Day=%%G")) ELSE (IF %_iDate%==2 (FOR /F "tokens=1-4* delims=%_sDate%" %%G IN ('DATE/T') DO (SET "_Year=%%G"&SET "_Month=%%H"&SET "_Day=%%I")))):: Remove the day of week if applicable(FOR %%G IN (%_Year%) DO (SET "_Year=%%G"))&(FOR %%G IN (%_Month%) DO (SET "_Month=%%G"))&(FOR %%G IN (%_Day%) DO (SET "_Day=%%G")):: Return date and componentsENDLOCAL&(SET "%2=%_Year%"&SET "%3=%_Month%"&SET "%4=%_Day%"&SET "%1=!%2!-!%3!-!%4!")&EXIT /B 0And this for time::: #############################################################################:: :f_GetTime _Time:::: Load time in a variable, zero padded using ONLY "standard" delimiters (:.):::: Usage: CALL :f_GetTime _Time:::: %_Time% will be set to HH:MM:SS.MSC - NOTE: that MS is now THREE digits:::: Although the default time delimiter, in Windows XP and above is either . or ::: users can change the delimiter to just about any character they like. And you:: know theres always that one guy, the one who writes everything in green ink,:: who will do this! This script always returns HH:MM:SS.MSC, note that MS:: is now 3 digits, no matter which time delimiter has been set in the control:: panel. Based on a discussion at ss64.com, with input from avery_larry and:: bluesxman, and tweaks by bphlpt using examples by Frank Westlake.:::: Dependencies: None:::: Upon exit, ERRORLEVEL is set to 0.:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:::f_GetTime _TimeSETLOCAL ENABLEEXTENSIONSFOR /F "tokens=1-3 delims=1234567890 " %%G IN ("%TIME%") DO (SET "_Delims=%%G%%H%%I")FOR /F "tokens=1-4 delims=%_Delims% " %%G IN ("%TIME%") DO (SET "_hh=00%%G"&SET "_min=00%%H"&SET "_ss=00%%I"&SET "_ms=00%%J0")ENDLOCAL&(SET %1=%_hh:~-2%:%_min:~-2%:%_ss:~-2%.%_ms:~-3%)&EXIT /B 0Cheers and Regards Edited May 12, 2012 by bphlpt Quote
shiner Posted May 13, 2012 Author Posted May 13, 2012 2 IceBlackIce, Mr_Smartepants, bphlptTHANKS.I have made copies of Mr_Smartepants' and bphlpt's scripts and will keep for future use.However, I believe I can use the environment variables provided by IceBlackIce (which I should have known) in an INF under a PostSetupCommand directive.I simply need to get my quotes usage in INFs down pat.This should be sufficient for my current need. Quote
bphlpt Posted May 13, 2012 Posted May 13, 2012 (edited) Here's a link to a pretty good table showing the value of the Windows Environment Variables for both XP and Win7 - http://ss64.com/nt/syntax-variables.htmlCheers and Regards Edited May 13, 2012 by bphlpt Quote
Geej Posted October 2, 2012 Posted October 2, 2012 I come across this batch for global time & date. Might be useful to someone. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.