Jump to content
Sign in to follow this  

Date Suffix on %computername%

Recommended Posts


Hello Everyone!

 I'm attempting to put together a code that reports select system information, and I'd like the name to include the current date/time both on the name of the file and inside. This code that I've put together puts the date and time in the text, then adds system info, but when it adds the system info, it puts spaces between everything. See below:

$act =  WinActivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt

Sleep(500) ;sleep half second
if ProcessExists("cmd.exe") Then
   $act ;refocus command prompt
   ;retrieve current time
   Send("echo Date: %date:~4% Time: %time:~0,2%:%time:~3,2%PST >> " & Chr(34) & "%USERPROFILE%\Desktop\%COMPUTERNAME%.txt" & Chr(34) & "{Enter}")
   Sleep(250) ;sleep quarter second(.25s)
   ;retrieve model number
   Send("WMIC ComputerSystem get model,name,manufacturer,systemtype >> " & Chr(34) & "%USERPROFILE%\Desktop\%COMPUTERNAME%.txt" & Chr(34) & "{Enter}")
   Sleep(250) ;sleep quarter second(.25s)
   ;retrieve serial number
   Send("WMIC bios get serialnumber >> " & Chr(34) & "%USERPROFILE%\Desktop\%COMPUTERNAME%.txt" & Chr(34) & "{Enter}")
   Sleep(250) ;sleep quarter second(.25s)
   Send("XCopy " & Chr(34) & "%USERPROFILE%\Desktop\%COMPUTERNAME%.txt" & Chr(34) & " " & Chr(34) & "\\ServerLocation\ComputerIDs\" & Chr(34) & "{Enter}")
   Sleep(250) ;sleep quarter second(.25s)
   ;Send("ren %COMPUTERNAME%.txt %COMPUTERNAME%-%Date:~4%.txt{Enter}")
   Send("TaskKill /F /FI " & Chr(34) & "IMAGENAME eq cmd*" & Chr(34) & "{Enter}")

Results show this(edited), date and time on one line, other info on second line. If the file is opened, and you press enter after the group of spaces after "SystemType" and then do the same thing after "x64-based PC" then everything is lined up, just spaced. 

Date: 07/22/2016 Time: 13:47PST 
M a n u f a c t u r e r     M o d e l               N a m e                     S y s t e m T y p e                     0 0 0 0 0 0                 0 0 0 0 0 0 0 0 0 0     0 0 0 0 0 0 - 0 0 0 - 0     x 6 4 - b a s e d   P C        S e r i a l N u m b e r       0 0 0 0 0 0 0 0

 Ideally it would look like this:

Date: 07/22/2016 Time: 13:47PST 
Manufacturer     Model         Name             SystemType
000000           000000000     000000-000-0     x64-based PC

Second part is the filename...probably a dos thing. I'm trying to add just the current date to the file, like "computername-date.txt" When the line below runs, I receive the message "The system cannot find the file specified." even though it's still on the desktop.

Send("ren %COMPUTERNAME%.txt %COMPUTERNAME%-%Date:~4%.txt{Enter}")

In the end, I'd love a file that had all info, without the spaces, renamed on the server with the computer name and date. Also, I found if I add the date in after the system info inside the file, it shows up in kanji(I think?) characters like this "慄整›㜰㈯⼲〲㘱吠浩㩥ㄠ㨴㘱卐⁔਍"

So, aside from writing out the commands too long, what else am I doing wrong and how can I fix it? Thanks ahead for any suggestions.

Share this post

Link to post
Share on other sites

use CHCP command in CMD session at first command  to change to a Unicode page.
@chcp 65001>nul

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this