This script can be used to configure Windows to start logging debug information and turnover the log file when required. The

Install.bat will configure Windows, install a .vbs script and set up a task schedule to run the .vbs script on startup.

Why:

If you just enable the UserEnvDebugLevel it will start logging to userenv.log, but the file will rename itself to userenv.bak on startup if its size exceeds 300kb. Use the scripts below to make a task schedule to rename the userenv.bak to the format of date-time_userenv.log as windows starts up.

How-to:

  1. Open Notepad and copy contain of Install.bat and save it somewhere on your computer.
  2. Open a new Notepad and copy the contain of UserEnvLogTurnover.vbs and save it in the same folder as install.bat
  3. Run Install.bat.

Compability:

  • Windows XP

[code title=”install.bat”]mkdir “%programfiles%UserEnvLogTurnover”

copy .UserEnvLogTurnover.vbs “%programfiles%UserEnvLogTurnoverUserEnvLogTurnover.vbs”

REG ADD “HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogon” /v UserEnvDebugLevel /t REG_DWORD /d 196610 /f

schtasks /delete /tn “UserEnvLogTurnover” /F

schtasks /create /tn “UserEnvLogTurnover” /tr “%systemroot%system32wscript.exe “%programfiles%UserEnvLogTurnoverUserEnvLogTurnover.vbs”” /sc onstart /ru System[/code]

[code title=”UserEnvLogTurnover.vbs”]pathtofile = “c:windowsdebugusermodeuserenv.bak”

pathtonewfile = “c:windowsdebugusermode” & FormatYYYYMMDD(date) & “-” & FormatHHMMSS(time) & “_” & “userenv.log”

‘msgbox pathtofile & ” -> ” & pathtonewfile

Set objFSO = CreateObject(“Scripting.FileSystemObject”)

IF objFSO.FileExists (pathtofile) then

Set file = objFSO.GetFile(pathtofile)

file.move pathtonewfile

End if

Function FormatYYYYMMDD(timeStamp)

Dim dateYear : dateYear = DatePart(“yyyy”, timeStamp)

Dim dateMonth : dateMonth = DatePart(“m”, timeStamp)

Dim dateDay : dateDay = DatePart(“d”, timeStamp)

IF dateMonth < 10 Then dateMonth = “0” & dateMonth

IF dateDay < 10 Then dateDay = “0” & dateDay

FormatYYYYMMDD = dateYear & dateMonth & dateDay

End Function

Function FormatHHMMSS(timestamp)

Dim timeSecond : timeSecond = DatePart(“s”, timeStamp)

Dim timeMinute : timeMinute = DatePart(“n”, timeStamp)

Dim timeHour : timeHour = DatePart(“h”, timeStamp)

IF timeHour < 10 Then dateHour = “0” & dateString

IF timeMinute < 10 Then dateMinute = “0” & dateMinute

IF timeSecond < 10 Then dateSecond = “0” & dateSecond

FormatHHMMSS = timeHour & timeMinute & timeSecond

End Function[/code]