Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8455215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:13:42+00:00 2026-06-10T12:13:42+00:00

I have a script that scans computers for a certain registry entry. I want

  • 0

I have a script that scans computers for a certain registry entry. I want to make it to where after the scan the text file that is created, to include the date and time of day as part of the filename (date from the local machine is ok). I have found some examples that seem to do this but either I don’t understand their answer or they are not including it in the file name.

Please, if you give an answer to explain what each part is that allows the date to be in the file name. I have seen things about tokens and indices and I do not understand what those are but I am very new to scripting and am trying to learn about this.

Below is the code I have so far for my script.

@echo off

Setlocal
::Test Script
echo This script is used to find a registry setting.(Actual registry patch has been changed for use as an example)
set /p c= Input computer name and push enter: 
set stamp=%date% at %time%
set DateTime=%stamp

call :screen
call :log

pause

:screen
echo.
echo Computer name: %c%
reg query "\\%c%\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Registry Folder\Registry Folder2\" /V "Registry Key" | FIND "Registry Key"
echo.
goto :eof

:log
echo.
echo Registry value for %c% on %stamp% >TextFile.txt
reg query "\\%c%\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Registry Folder\Registry Folder2\" /V "Registry Key" | FIND "Registry Key" >>TextFile.txt
echo.
goto :eof

As you can see I changed the actual registry key I was looking for. Honestly any command can be put there as I am focused on trying to find out how to make the text file that is being created have the correct timestamp within the file name.

Operating System: Windows XP and Windows 7
Note: Please excuse me not being able to give the exact name of the scripting language I am using as the only way I know how to refer to it is “Windows Command Line Script”… I don’t even know if that is correct.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:13:43+00:00Added an answer on June 10, 2026 at 12:13 pm

    I found the answer mostly with help from a co-worker and also some with various stack overflow posts. I was concerned with not only seeing the answer but what exactly was going on with the commands.

    Below sets the DateTime variable to the local date and time in yyyymmdd_hhmmss This code is correctly used being placed in your script.

    for /f "skip=1" %%c in ('wmic os get LocalDateTime') do set DateTime=%%c
    set DateTime=%DateTime:~0,8%_%DateTime:~8,6%
    

    Explanation:
    If you run the below command in cmd

    wmic os get LocalDateTime
    

    you get the output of (different numbers depending on the date/time you do this):

    LocalDateTime
    20120829151726.702000-300
    

    Now we need to format this. For this purpose I only care for the date and time. The second line has the date and time in the format yyyymmddhhmmss with some extra gobbly goop. We obviously don’t want the first line and we don’t want the .702000-300.

    To remove this we need to format. By using “skip=1”,you are skipping the first line. The :~#,# helps you to choose which characters to use (Don’t actually use the # character, I’m only using that as a placeholder so you know a number goes there). The first # is your starting value and the second # is the number of characters after the starting value. We want to use the first 8 characters for the date (yyymmdd) and therefore we have the starting value as 0 (the first #) and the second # as 8.

    I then add the underscore and the information needed for the 6 characters for the time (hhmmss).

    Within your script you can now have the code to call the DateTime variable.

    echo Hello!>>BestFileEver_%DateTime%.txt
    

    Now the text file with the word hello in it will have the file name below:

    BestFileEver_20120829_153326.txt
    

    Now obviously the numbers will be different depending on the time you did this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple python script that should scan a text file, which
I want to make a script that scans source files, and add a string
I have to make a script in PHP that will scan other PHP files
I have script that reads remote file content and writes it to local server.
I have a script that scans ports for open proxy servers. Problem is if
I have a script that scans all my servers in my domains and outputs
I have a script that scans subdirectories recursively and deletes files older than X
Here's exactly what I want to do: have a script that, upon detecting that
I have a shell script that calls a java jar file and runs an
I want to compare two text files that i have generated from one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.