When running windows system check scripts it’s nice to know when your server was last rebooted. The command shown bellow generates this information.
net stats srv | findstr "since"
The Windows built in command “net user” allows modification of local account settings.
: Creates account and sets password + user full name & description
net user <username> <password> /ADD /fullname:"name" /comment:"description"
: Set Account Password to never expire and add account description
net user <username> /EXPIRES:NEVER /COMMENT:"<comment>"
net user <username> /ACTIVE:NO
net user <username> /DELETE
:Full net user configuration flags and options
net user /help
A few cautionary warnings… this script will delete files from whatever location you specify as LOGPATH. Use with care. As a best practice I always create my logs with a pre-fix. ex: CheckUpTime-.log which can then be used in the deletion script. This will ensure that you only delete logs that start with “CheckUpTime”.
:: Delete log files older then 14 days
:: Echo’s logs which will be deleted (use this before using the command which contains “del”)
forfiles -p %LOGPATH% -m CheckUpTime-*.* -d -14 -c “cmd /c echo 0x22@Path@File0x22”
:: Actual Delete Command (remove :: to run command)
::forfiles -p %LOGPATH% -m CheckUpTime-*.* -d -14 -c “cmd /c del /q @path”
The built in windows command FindStr mirrors the capabilities of the Unix command Grep.
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ …]]
/B Matches pattern if at the beginning of a line.
/E Matches pattern if at the end of a line.
/L Uses search strings literally.
/R Uses search strings as regular expressions.
/S Searches for matching files in the current directory and all
/I Specifies that the search is not to be case-sensitive.
/X Prints lines that match exactly.
/V Prints only lines that do not contain a match.
/N Prints the line number before each line that matches.
/M Prints only the filename if a file contains a match.
/O Prints character offset before each matching line.
/P Skip files with non-printable characters.
/OFF[LINE] Do not skip files with offline attribute set.
/A:attr Specifies color attribute with two hex digits. See “color /?”
/F:file Reads file list from the specified file(/ stands for console).
/C:string Uses specified string as a literal search string.
/G:file Gets search strings from the specified file(/ stands for console).
/D:dir Search a semicolon delimited list of directories
strings Text to be searched for.
[drive:][path]filename Specifies a file or files to search.
Example of using Findstr to search for multiple strings in succession within a log file.
findstr “ERROR Caused Fail” c:logslog.log
This command will search for the String ERROR then Caused, and Fail while parsing down a file. So if the file looked like this:
Line1: Error Script Failed
Line4: Caused by process down
The FindStr output would look like this:
Error Script Failed
Caused by Process down
Find out when a Windows host was last restarted using native windows commands.
Run net stats srv
Server Statistics for \LAP1
Statistics since 9/16/2008 9:14 AM
Sessions accepted 1
Sessions timed-out 0
Sessions errored-out 0
Kilobytes sent 0
Kilobytes received 0
Mean response time (msec) 0
System errors 0
Permission violations 0
Password violations 0
Files accessed 0
Communication devices accessed 0
Print jobs spooled 0
Times buffers exhausted
Big buffers 0
Request buffers 0
The command completed successfully.
Pipe to findstr to filter out unecessary stats.
net stats srv | findstr “since”
Statistics since 9/16/2008 9:14 AM
:: Keep variables local
SETLOCAL (Define at beginning of script)
ENDLOCAL (Release variables at end of script)
:: Set Date Variable
:: Current Host Name
::Current working directory
%CD% – Gives current working directory with no preceding \
%~dp0 – Gets current working directory with a preceding \
Bat_To_exe_Converter allows conversion and creation of executables from Windows Batch Files. No installation is necessary, just unpack the zipped executable and point it to the .bat file you would like converted.