Creating a script to gather PC information - to assist those asking for help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Creating a script to gather PC information - to assist those asking for help

#106 Post by aGerman » 04 Sep 2016 02:37

Great :) Then I hope no major bugs are left in the script.

Steffen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Creating a script to gather PC information - to assist those asking for help

#107 Post by dbenham » 05 Sep 2016 21:56

I've run into a problem on my Win 10 machine at home. I thought the script was supposed to be non-destructive, but when I run the script it changes my console font from "Raster Fonts" size 8x12 to "Courier New" size 12. Ouch :!: :cry:
The text becomes so small I can hardly read it.

Here is the result for my machine:

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 10.0.14393]
Product name           :  Windows 10 Pro, 64 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 4192432 kilobytes

Date/Time format       :  mm/dd/yy (12 hours)     Mon 09/05/2016  23:35:49.16
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  09/01/2016  01:03 AM     6,174,015,488 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes

                          Missing from the tool collection:  debug
Most everything looks good, except the Date/Time format line surprises me. It claims the time is in 12 hour format, but the sample time is in 24 hour format (the same as I get using %TIME%).

Does the 12 hour indicator pertain to DIR output? If so, then perhaps the info layout should change.


Dave Benham

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Creating a script to gather PC information - to assist those asking for help

#108 Post by aGerman » 06 Sep 2016 00:56

Thanks Dave!

dbenham wrote:I've run into a problem on my Win 10 machine at home. I thought the script was supposed to be non-destructive, but when I run the script it changes my console font from "Raster Fonts" size 8x12 to "Courier New" size 12. Ouch :!: :cry:

Hu :shock: Reading values does change the font? Hard to believe :? I'll try to find somthing in the internet if any of the used commands has this side effect.

dbenham wrote:Does the 12 hour indicator pertain to DIR output? If so, then perhaps the info layout should change.

Good question. You are the first person that I know where the formats of %time% and DIR differ.

Steffen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Creating a script to gather PC information - to assist those asking for help

#109 Post by dbenham » 06 Sep 2016 06:07

aGerman wrote:
dbenham wrote:I've run into a problem on my Win 10 machine at home. I thought the script was supposed to be non-destructive, but when I run the script it changes my console font from "Raster Fonts" size 8x12 to "Courier New" size 12. Ouch :!: :cry:

Hu :shock: Reading values does change the font? Hard to believe :? I'll try to find somthing in the internet if any of the used commands has this side effect.
Has anyone else tried Win 10 yet? My guess it is a Win 10 specific issue.

aGerman wrote:
dbenham wrote:Does the 12 hour indicator pertain to DIR output? If so, then perhaps the info layout should change.

Good question. You are the first person that I know where the formats of %time% and DIR differ.
I'm pretty sure %TIME% always returns 24 hour time with centiseconds, regardless of locale. I believe the only thing that may change is the character used for the decimal point. DATE /T and %DATE% give the same format, but TIME /T and %TIME% do not.

Code: Select all

C:\test>date /t
Tue 09/06/2016

C:\test>echo %date%
Tue 09/06/2016

C:\test>time /t
08:04 AM

C:\test>echo %time%
 8:04:27.82

There is lots of time parsing code out there that depends on the %TIME% format, including on DosTips :wink:

Dave Benham

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Creating a script to gather PC information - to assist those asking for help

#110 Post by dbenham » 06 Sep 2016 08:03

Yea :!:
It works great on my work machine where REG has been blocked :D

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 6.1.7601]
Product name           :  Windows 7 Enterprise, 32 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 3659820 kilobytes

Date/Time format       :  mm/dd/yy (12 hours)     09/06/2016   9:48:04.50
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  08/24/2016  06:07 PM     3,747,655,680 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes


What does "Admin group=Yes" mean :?: I am surprised to see that result given that configuration of my machine is completely locked down.

I cannot do any of the following
  • install software
  • change the date or time
  • I'm not sure, but I don't think I can open command prompt as administrator. The Window opens, but the title does not indicate admin mode.

Dave Benham

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Creating a script to gather PC information - to assist those asking for help

#111 Post by aGerman » 06 Sep 2016 08:54

Thank's so much for testing Dave!

dbenham wrote:Has anyone else tried Win 10 yet? My guess it is a Win 10 specific issue.

Yes I did at home. It's a 32 bit Home edition though.

dbenham wrote:I'm pretty sure %TIME% always returns 24 hour time with centiseconds, regardless of locale. I believe the only thing that may change is the character used for the decimal point. DATE /T and %DATE% give the same format, but TIME /T and %TIME% do not.

That's a pretty logical assumption. Unfortunately I didn't find anything about it yet.

dbenham wrote:It works great on my work machine where REG has been blocked :D

Thats good news :D

dbenham wrote:What does "Admin group=Yes" mean :?:

Actually it means that you belong to the local administrator group. No idea what your system admins did to restrict the permissions of that group. At least I hoped it would be an indicator if you would be able to gain elevated rights. Now it doesn't seem we could rely on it :(

Steffen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Creating a script to gather PC information - to assist those asking for help

#112 Post by dbenham » 06 Sep 2016 09:25

I really like Sponge Belly's suggestion to include info on the AutoRun setting

Code: Select all

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

It is typically undefined, but when it is defined, it can really wreak havoc with FOR /F results.

I recommend gathering AutoRun info by redirecting output of REG QUERY and/or WMIC to a temp file, and then reading the result with SET /P, thus avoiding problems with FOR /F if AutoRun happens to be set to something problematic.

Another good thing to report on is %COMSPEC%, as pipes are dependent on it.


Dave Benham

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Creating a script to gather PC information - to assist those asking for help

#113 Post by aGerman » 06 Sep 2016 12:26

Thanks Dave!
That was definitely something I didn't think about yet.

Steffen

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Creating a script to gather PC information - to assist those asking for help

#114 Post by aGerman » 07 Sep 2016 16:05

I did the changes
viewtopic.php?f=3&t=7347&p=48700#p48700

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 10.0.10586]
Product name           :  Windows 10 Home, 32 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 2023612 kilobytes

Date/Time format       :  (dd/mm/yy)  08.09.2016   0:06:37,12
ComSpec                :  C:\WINDOWS\system32\cmd.exe
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  de-DE       Code Pages: OEM  850    ANSI 1252
DIR  format            :  04.09.2016  16:45       738.197.504 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes
User    AutoRun found  :      AutoRun    REG_SZ    rem "hello"




Dave
I wasn't able to find something that would explain the font failure. Could you do me a favour: Please have a look into your registry. Is there any subkey in HKCU\Console with a different FaceName, FontFamily, or FontSize value that could have caused it?

Steffen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Creating a script to gather PC information - to assist those asking for help

#115 Post by dbenham » 07 Sep 2016 19:35

The problem occurs with the following command:

Code: Select all

CHCP 1252
Very odd. :? There seems to be some incompatibility with the new Win 10 Console.

When looking at the Console properties window, Options Tab, I have the "Use legacy console" option unchecked so that I can use new features like ANSI escape sequences, and [Ctrl-V] paste, etc.

Normally my code page is 437, and my console is using a raster font.
When I issue CHCP 1252, all hell breaks loose. The font changes to Courier New, and the text is tiny. CHCP 437 does not reset the console font back to a raster font.

If I activate the "Use legacy console" option, close the console, and then open a new one, then all is good. I can change the code page with CHCP at will with no ill effects. The console font remains a raster font. But now I cannot use the new console features :(


Dave Benham

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Creating a script to gather PC information - to assist those asking for help

#116 Post by aGerman » 08 Sep 2016 00:49

Thanks Dave!

The "Use legacy console" option is unchecked at my laptop too. A friend of mine has a 64 bit Win 10. I'll ask him to test it.

FWIW Did you run sfc /scannow in order to check if there was anything corrupted?

Steffen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Creating a script to gather PC information - to assist those asking for help

#117 Post by dbenham » 08 Sep 2016 05:53

No, I have not.

But I believe the problem stems from my use of a raster font. MS recommends that raster font not be used on the grounds that it may be hard to read on a high DPI screen. I personally find the reverse to be true. But I wonder if there is a deeper reason to not use raster font, and perhaps the switch to a non-raster font is a "feature" of the new console.

If I set my font to something like Courier New or Lucida Console, and set the size to something I can read, then all is fine when I use your utility.


Dave Benham

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Creating a script to gather PC information - to assist those asking for help

#118 Post by dbenham » 08 Sep 2016 06:37

I have some more suggestions:

Display %PATHEXT% value. Problems can occur if the order is changed, or if key values are missing. I think most of us know that there are default values (hidden) if the value is undefined. But I only recently learned that if it is undefined, and you launch a new CMD session with cmd.exe, then the new session will have PATHEXT defined with the default values. On my machine the default is PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC

You define SYS32 as %systemroot%\System32. I see a few potential problems with that:
  • The SYSTEMROOT variable may be undefined, or improperly defined
  • You assume you want the System32 subdirectory

I believe you should use %__APPDIR__% instead, for the following reasons:
  • It directly gives the value you are looking for (C:\WINDOWS\System32\ on my machine)
  • It cannot be overriden (except on XP). Even if a user defines SET __APPDIR__=SomeInvalidValue, then all versions (post XP) still expand %__APPDIR__% with the correct value - the user defined value is ignored. See StackOverflow: Why can't I access a variable named __CD__ on Windows 7? for more info.

I think it would be a good idea to show the value of %__APPDIR__%. It could be useful to compare to the value of %COMSPEC%.

It would be nice to report if there are any standard external commands that are overriden because there are folders within PATH that contain non-standard EXE, BAT etc. files with the same base name as standard external commands.

I have written the following to probe for this, but they may be too slow to incorporate into the main script. Perhaps they can be companion scripts:

FastTestOverride.bat - Only tests commands that are listed by HELP

TestOverride.bat - Tests all EXE and COM files within %__APPDIR__% (quite slow)

Each file tested is briefly displayed on the screen. Only failures remain on the screen. I found 4 surprises on my work machine :!:

FastTestOverride.bat

Code: Select all

@echo off
if "%~1" equ "__:TestOverride__" (
  if not defined pathext set "pathExt=.com;.exe;.bat;.cmd"
  goto :TestOverride
)
call :TestOverride
exit /b
 
 
:TestOverride
setlocal disableDelayedExpansion
if not defined pathext (
  "%__APPDIR__%cmd.exe" /c "%~f0" __:TestOverride__
  exit /b
)
 
:: Define LF to contain a new line (0x0A) character
(set LF=^
%= Do not remove or alter this line =%
)
:: Prepare the list of paths in PATH
set "list=.\;%path:"=""%"
set "list=%list:^=^^%"
set "list=%list:&=^&%"
set "list=%list:|=^|%"
set "list=%list:<=^<%"
set "list=%list:>=^>%"
set "list=%list:;=^;^;%"
set list=%list:""="%
set "list=%list:"=""Q%"
set "list=%list:;;="S"S%"
set "list=%list:^;^;=;%"
set "list=%list:""="%"
setlocal EnableDelayedExpansion
set "list=!list:"Q=!"
for %%N in ("!LF!") do set "list="!list:"S"S=.\"%%~N"!""
setlocal disableDelayedExpansion
for /f %%C in ('copy /z "%~dpf0" nul') do (
  for /f %%A in (
    '^""%__APPDIR__%help.exe" ^| "%__APPDIR__%findstr.exe" /rc:"^[^ ][^ ]*   "^"'
  ) do for /f "delims=" %%F in ('dir /b "%__APPDIR__%%%A.exe" "%__APPDIR__%%%A.com" 2^>nul') do (
    <nul set /p "=.%%C                                                                              %%C%%F"
    set "skip="
    setlocal enableDelayedExpansion
    for /f "delims=" %%P in ("!list!") do if not defined skip (
      if "!!" equ "" endlocal
      for %%X in (%pathext%) do if not defined skip (
        if exist "%%~fP%%~nF%%X" (
          if /i "%%~fF" neq "%%~dpP%%~nF%%X" echo  is overridden by "%%~dpP%%~nF%%X"
          set "skip=1"
        )
      )
      if /i "%%~dpF" equ "%%~dpP" set "skip=1"
    )
  )
  (echo(%%C                                                                              )
)
exit /b

TestOverride.bat

Code: Select all

@echo off
if "%~1" equ "__:TestOverride__" (
  if not defined pathext set "pathExt=.com;.exe;.bat;.cmd"
  goto :TestOverride
)
call :TestOverride
exit /b
 
 
:TestOverride
setlocal disableDelayedExpansion
if not defined pathext (
  "%__APPDIR__%cmd.exe" /c "%~f0" __:TestOverride__
  exit /b
)
 
:: Define LF to contain a new line (0x0A) character
(set LF=^
%= Do not remove or alter this line =%
)
:: Prepare the list of paths in PATH
set "list=.\;%path:"=""%"
set "list=%list:^=^^%"
set "list=%list:&=^&%"
set "list=%list:|=^|%"
set "list=%list:<=^<%"
set "list=%list:>=^>%"
set "list=%list:;=^;^;%"
set list=%list:""="%
set "list=%list:"=""Q%"
set "list=%list:;;="S"S%"
set "list=%list:^;^;=;%"
set "list=%list:""="%"
setlocal EnableDelayedExpansion
set "list=!list:"Q=!"
for %%N in ("!LF!") do set "list="!list:"S"S=.\"%%~N"!""
setlocal disableDelayedExpansion
for /f %%C in ('copy /z "%~dpf0" nul') do (
  for %%F in (
    "%__APPDIR__%*.exe"
    "%__APPDIR__%*.com"
  ) do (
    <nul set /p "=.%%C                                                                              %%C%%F"
    set "skip="
    setlocal enableDelayedExpansion
    for /f "delims=" %%P in ("!list!") do if not defined skip (
      if "!!" equ "" endlocal
      for %%X in (%pathext%) do if not defined skip (
        if exist "%%~fP%%~nF%%X" (
          if /i "%%~fF" neq "%%~dpP%%~nF%%X" echo  is overridden by "%%~dpP%%~nF%%X"
          set "skip=1"
        )
      )
      if /i "%%~dpF" equ "%%~dpP" set "skip=1"
    )
  )
  (echo(%%C                                                                              )
)
exit /b


Dave Benham

elzooilogico
Posts: 128
Joined: 23 May 2016 15:39
Location: Spain

Re: Creating a script to gather PC information - to assist those asking for help

#119 Post by elzooilogico » 08 Sep 2016 11:39

dbenham wrote:Yea :!:
It works great on my work machine where REG has been blocked :D

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 6.1.7601]
Product name           :  Windows 7 Enterprise, 32 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 3659820 kilobytes

Date/Time format       :  mm/dd/yy (12 hours)     09/06/2016   9:48:04.50
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  08/24/2016  06:07 PM     3,747,655,680 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes


What does "Admin group=Yes" mean :?: I am surprised to see that result given that configuration of my machine is completely locked down.

I cannot do any of the following
  • install software
  • change the date or time
  • I'm not sure, but I don't think I can open command prompt as administrator. The Window opens, but the title does not indicate admin mode.

Dave Benham



Steffen, as Dave has found, there's a typo on line 86, where there is

Code: Select all

if defined whoami 2>nul %whoami% /groups|>nul %findstr% /i "\<S-1-5-32-544\>" && set "LocalAdmin=Yes" || set "LocalAdmin=Yes"
there shoul be

Code: Select all

if defined whoami 2>nul %whoami% /groups|>nul %findstr% /i "\<S-1-5-32-544\>" && set "LocalAdmin=Yes" || set "LocalAdmin=No"


This is what I get on my win 8 enterprise laptop
as administrator

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Versi¢n 6.2.9200]
Product name           :  Windows 8 Enterprise, 64 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 8298772 kilobytes

Date/Time format       :  (dd/mm/yy)  08/09/2016  17:57:42,09
ComSpec                :  C:\Windows\system32\cmd.exe
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  es-ES       Code Pages: OEM  850    ANSI 1252
DIR  format            :  08/09/2016  12:03     8.485.076.992 pagefile.sys
Permissions            :  Elevated Admin=Yes, Admin group=Yes

                          Missing from the tool collection:  debug

as user

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Versi¢n 6.2.9200]
Product name           :  Windows 8 Enterprise, 64 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 8298772 kilobytes

Date/Time format       :  (dd/mm/yy)  08/09/2016  17:58:25,06
ComSpec                :  C:\Windows\system32\cmd.exe
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  es-ES       Code Pages: OEM  850    ANSI 1252
DIR  format            :  08/09/2016  12:03     8.485.076.992 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Nope

                          Missing from the tool collection:  debug



And on a win 2008R2 server
as administrator

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Versi¢n 6.1.7601]
Product name           :  Windows Server 2008 R2 Standard, 64 bit
Performance indicators :  Processor Cores: 8      Visible RAM: 14677960 kilobytes

Date/Time format       :  (dd/mm/yy)  08/09/2016  18:08:58,69
ComSpec                :  C:\Windows\system32\cmd.exe
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  es-ES       Code Pages: OEM  850    ANSI 1252
DIR  format            :  05/09/2016  02:02    15.030.231.040 pagefile.sys
Permissions            :  Elevated Admin=Yes, Admin group=Yes

                          Missing from the tool collection:  debug

as user

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Versi¢n 6.1.7601]
Product name           :  Windows Server 2008 R2 Standard, 64 bit
Performance indicators :  Processor Cores: 8      Visible RAM: 14677960 kilobytes

Date/Time format       :  (dd/mm/yy)  08/09/2016  18:12:45,34
ComSpec                :  C:\Windows\system32\cmd.exe
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  es-ES       Code Pages: OEM  850    ANSI 1252
DIR  format            :  05/09/2016  02:02    15.030.231.040 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Nope

                          Missing from the tool collection:  debug



Codepages may produce weird characters when language special chars are used, here Versi¢n should be Versión.
I know there is a senseless work, but if someone with locale "xx-ES" would like to take care of accents

change

Code: Select all

:: create the information file and send the information to the clipboard if clip is available
>>"%temp%\info.txt" (
  for /f "delims=" %%a in ('ver') do echo Windows version        :  %%a
  setlocal EnableDelayedExpansion
  echo Product name           :  !ProductName!, !bit! bit
  echo Performance indicators :  Processor Cores: !NUMBER_OF_PROCESSORS!      Visible RAM: !ram! kilobytes&echo(


to something like

Code: Select all

:: create the information file and send the information to the clipboard if clip is available
>>"%temp%\info.txt" (
  for /f "delims=" %%a in ('ver') do set "token=%%a"
  setlocal EnableDelayedExpansion
  echo !LocaleName! | find /I "-ES">nul && call :subst_spanish_acentos token
  echo Windows version        :  !token!
  echo Product name           :  !ProductName!, !bit! bit
  echo Performance indicators :  Processor Cores: !NUMBER_OF_PROCESSORS!      Visible RAM: !ram! kilobytes&echo(


and add a new sub routine

Code: Select all

:subst_spanish_acentos
set "token=!%1!"
set "token=!token: =á!"
set "token=!token:‚=é!"
set "token=!token:¡=í!"
set "token=!token:¢=ó!"
set "token=!token:£=ú!"
set "token=!token:¤=ñ!"
set "token=!token:¥=Ñ!"
set "%~1=%token%"
goto :eof



Now the output is

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Versión 6.2.9200]
Product name           :  Windows 8 Enterprise, 64 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 8298772 kilobytes

Date/Time format       :  (dd/mm/yy)  08/09/2016  17:58:45,31
ComSpec                :  C:\Windows\system32\cmd.exe
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  es-ES       Code Pages: OEM  850    ANSI 1252
DIR  format            :  08/09/2016  12:03     8.485.076.992 pagefile.sys
Permissions            :  Elevated Admin=Yes, Admin group=Yes

                          Missing from the tool collection:  debug


douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: Creating a script to gather PC information - to assist those asking for help

#120 Post by douglas.swehla » 08 Sep 2016 13:48

douglas.swehla wrote:

Code: Select all

--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 6.1.7601]
Product name           :  Windows 7 Professional, 64 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 4072532 kilobytes

Date/Time format       :  mm/dd/yy (12 hours)     Wed 08/31/2016  11:14:26.87
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  08/29/2016  09:46 AM     4,170,272,768 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes

                          Missing from the tool collection:  debug


I am able to use delayed expansion, so not sure what's up with that. When I have more time, I'll step through the code to see what's going on.


I've noticed that all the results posted so far report that delayed expansion is disabled for both the system and the user. That seems unlikely, and I think it's because the test is backwards.

The current code starts off assuming that delayed expansion is disabled, and only changes it if it finds an enabling registry entry. My system doesn't have a registry entry for delayed expansion, and it still works, so I assume that it's enabled by default, and has to be turned off. The code should reflect that by starting off %du% and %ds% as Enabled, and only change to Disabled if a disabling entry is found.

For users that, for whatever reason, can't use REG or WMIC, you can test the user's ability directly with something like this:

Code: Select all

set "du=Enabled"
setlocal EnableDelayedExpansion
if not "%du%" equ "!du!" set "du=Disabled"
(endlocal & set "du=%du%")


Current script code, for reference:

Code: Select all

:::::: Starts at line line 114 in version 09/07/2016. ::::::
:: Extensions and DelayedExpansion
for %%a in (es eu ds du) do set "%%a=Disabled"
if %RegUserCMDproc%==1 (call :RegUserProc) else if defined wmic call :WmiUserProc
if %RegSysCMDproc%==1 (call :RegSysProc) else if defined wmic call :WmiSysProc
if not defined eu set "eu=%ex_noreg%"
if not defined du set "du=%de_noreg%"


:::::: Starts at line 270 in version 09/07/2016. ::::::
:RegUserProc
%reg% query "HKCU\%CMDproc%" /v "EnableExtensions" 2>nul|%find% "0x1">nul && set "eu=Enabled "
%reg% query "HKCU\%CMDproc%" /v "DelayedExpansion" 2>nul|%find% "0x1">nul && set "du=Enabled "
goto :eof

:WmiUserProc
%RegHead% GetDWORDValue hDefKey^="&H%HKCU%" sSubKeyName^="%CMDproc%" sValueName^="EnableExtensions" %RegTail%
if "%dat%"=="1" set "eu=Enabled "
%RegHead% GetDWORDValue hDefKey^="&H%HKCU%" sSubKeyName^="%CMDproc%" sValueName^="DelayedExpansion" %RegTail%
if "%dat%"=="1" set "du=Enabled "
goto :eof

:RegSysProc
%reg% query "HKLM\%CMDproc%" /v "EnableExtensions" 2>nul|%find% "0x1">nul && set "es=Enabled "
%reg% query "HKLM\%CMDproc%" /v "DelayedExpansion" 2>nul|%find% "0x1">nul && set "ds=Enabled "
goto :eof

:WmiSysProc
%RegHead% GetDWORDValue hDefKey^="&H%HKLM%" sSubKeyName^="%CMDproc%" sValueName^="EnableExtensions" %RegTail%
if "%dat%"=="1" set "es=Enabled "
%RegHead% GetDWORDValue hDefKey^="&H%HKLM%" sSubKeyName^="%CMDproc%" sValueName^="DelayedExpansion" %RegTail%
if "%dat%"=="1" set "ds=Enabled "
goto :eof

Post Reply