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
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#16 Post by foxidrive » 13 Aug 2016 03:29

I've been out herding the kangaroos and only just got back after one escaped... but I do like the idea of reporting details when

1) Certain commands are missing or if they have the wrong extension (say a .bat extension)
2) and also report if certain essential items on the PATH statement are missing.

I've implemented 2) below and added a check for permissions (Hmmm, it may have a bug in user mode)

Just adding here that this script concept as it stands is not an "Official" DosTips script and the people running it will always need to be aware of that.

For those watching around now I've edited numerous times and played with the formatting too.

Code: Select all

Windows version    :  Microsoft Windows [Version 6.3.9600]
Product name       :  32 bit Windows 8.1 Pro with Media Center
Processor arch     :  x86, CPU/Number of cores=8

Date/Time format   :  dd/mm/yy (24 hours)   Sat 13/08/2016  20:03:24.57
Extensions         :  system:Enabled   user:Enabled
Delayed expansion  :  system:Disabled  user:Disabled
Locale name        :  en-AU      Code Pages:OEM 850     ANSI 1252
DIR  format        :  11/08/2016  02:05     3,484,418,048 pagefile.sys
Permissions        :  Elevated Admin=No, Admin access=Yes, User access=No

                      Missing from the PATH statement: C:\WINDOWS\system32
                      Missing from the PATH statement: C:\WINDOWS\System32\Wbem




Code: Select all

@echo off &setlocal EnableExtensions DisableDelayedExpansion
 :: prepare some variables to shorten lines in the script
 set "International=HKCU\Control Panel\International"
 set "CurrentVersion=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
 set "CodePage=HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage"
 set "CMDproc=Software\Microsoft\Command Processor"

:: Checks for user permissions
set "Admin=No" & set "A-access=No" & set "user=Yes"
cd "%windir%\system32\config" >nul 2>&1 && (set "A-access=Yes" & set "user=No")
reg query "HKU\S-1-5-19" >NUL 2>&1 && (set "Admin=Yes" & set "A-access=No" & set "user=No")


:: checks path
:: removes random double quotes, adds double quotes, removes trailing slash
set "p=%path%"
set  p=%p:"=%
set  p=%p:;=" "%
set  p=%p:\"="%
set  p="%p%"
:: echo debug &echo.&echo "%p%" & (for %%a in ("%p%") do echo %%a) & pause & goto :EOF

:: Checks for certain path elements and reports if they are missing
set "p-1=%windir%"
set "p-2=%windir%\system32"
set "p-3=%windir%\System32\Wbem"
for %%a in (%p%) do (
  if /i "%%~a"=="%p-1%" set "p-1=%p-1%.yes"
  if /i "%%~a"=="%p-2%" set "p-2=%p-2%.yes"
  if /i "%%~a"=="%p-3%" set "p-3=%p-3%.yes"
   )

 set "cores=%NUMBER_OF_PROCESSORS%" & set "arch=%PROCESSOR_ARCHITECTURE%"
 set "pad=                      "
 :: Check for 64 bit windows.  Defaults to 32 bit
 set bit=32 bit
 if exist "%SystemRoot%\SysWOW64\" set bit=64 bit
 :: create a set of many varibles: checking date and time formats is one use
 for /f "tokens=1,2,*" %%a in ('reg query "%International%"^|find "REG_"')  do set "%%a=%%c"
 if "%iDate%"=="0" (set format=mm/dd/yy) else if "%iDate%"=="1" (set format=dd/mm/yy) else if "%iDate%"=="2" (set format=yy/mm/dd)
 if "%iTime%"=="0" (set hours=12) else if "%iTime%"=="1" (set hours=24)
 :: get the DIR command format to display
 for /f "delims=" %%a in ('dir "%SystemDrive%\pagefile.sys" /a ^|find ":"') do set DirFormat=%%a
 :: determines the state of delayed expansion and extensions
 for %%a in (es eu ds du) do set "%%a=Disabled"
 reg query "HKLM\%CMDproc%" /v "EnableExtensions" 2>nul|find "0x1">nul && set "es=Enabled "
 reg query "HKCU\%CMDproc%" /v "EnableExtensions" 2>nul|find "0x1">nul && set "eu=Enabled "
 reg query "HKLM\%CMDproc%" /v "DelayedExpansion" 2>nul|find "0x1">nul && set "ds=Enabled "
 reg query "HKCU\%CMDproc%" /v "DelayedExpansion" 2>nul|find "0x1">nul && set "du=Enabled "
 :: create the information file and send the information to the clipboard if clip is available
 >"%temp%\info.txt" (
  echo [code^]
  for /f "delims=" %%a in ('ver') do echo Windows version    :  %%a
  for /f "tokens=2*" %%a in ('
    reg query "%CurrentVersion%"^|find /i "ProductName"') do echo Product name       :  %Bit% %%b
  echo Processor arch     :  %arch%, CPU/Number of cores=%cores%&echo(

  echo Date/Time format   :  %format% (%hours% hours^)   %date%  %time%
  for /f "tokens=3" %%a in ('reg query "%CodePage%" /v "OEMCP"') do (
  for /f "tokens=3" %%b in ('reg query "%CodePage%" /v "ACP"')   do (
  echo Extensions         :  system:%es%  user:%eu%
  echo Delayed expansion  :  system:%ds%  user:%du%
  echo Locale name        :  %LocaleName%      Code Pages:OEM %%a     ANSI %%b))
  echo DIR  format        :  %DirFormat%
  echo Permissions        :  Elevated Admin=%Admin%, Admin access=%A-access%, User access=%user%&echo(

  rem report if path elements are missing
  for %%a in ("%p-1%" "%p-2%" "%p-3%") do (
   if /i not "%%~xa"==".yes" echo.%pad%Missing from the PATH statement: %%~a
   )
  echo [/code^]
)
clip >nul 2>&1 && clip < "%temp%\info.txt"
:: load the information into Notepad where it can also be copied to the clipboard
start "" notepad.exe "%temp%\info.txt" & ping -n 2 localhost>nul & del "%temp%\info.txt"

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

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

#17 Post by douglas.swehla » 13 Aug 2016 13:33

foxidrive wrote:I've been out herding the kangaroos and only just got back after one escaped...

Is this a metaphor for being busy, or have you actually been chasing down marsupials?

foxidrive wrote:but I do like the idea of reporting details when

1) Certain commands are missing or if they have the wrong extension (say a .bat extension)
2) and also report if certain essential items on the PATH statement are missing.

I've implemented 2) below and added a check for permissions (Hmmm, it may have a bug in user mode)


I see that you're testing specifically for system32 in the PATH check. Do you want to look for SysWOW64 as well? My system has both System32 and SysWOW64 in %windir%, and a lot of commands are duplicated between them. It's not clear to me why that is (32- and 64-bit versions?), or what the impact would be if either of them were missing from %PATH%.

Here's a snippet from a StackOverflow answer dealing with admin elevation, that takes SysWOW64 into consideration. It uses %SystemRoot% instead of %windir%, which are the same on my system. Not sure if there's a reason for that, or just the author's habit.

Code: Select all

REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

REM --> If error flag set, we do not have admin.


The script above goes on to do an admin check via UAC, using VBS. It's pretty short, and might solve the language-dependency issue that aGerman was running into.

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

#18 Post by aGerman » 13 Aug 2016 15:22

douglas.swehla wrote:The script above goes on to do an admin check via UAC, using VBS. It's pretty short, and might solve the language-dependency issue that aGerman was running into.

I already know that technique. But as I said - I don't want to run the script elevated.
Acting on your former suggestion to use WMIC:

Code: Select all

@echo off &setlocal

set "localadmin="
wmic path Win32_Group WHERE "LocalAccount='TRUE' AND SID='S-1-5-32-544'" assoc /assocclass:Win32_GroupUser|>nul findstr /c:Name^=\"%username%\" && set "localadmin=1"

if defined localadmin (echo Can obtain administrative elevation.) else echo Doesn't belong to the local administrators.
pause

But WMIC isn't that downward compatible since XP is still a walking dead.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#19 Post by foxidrive » 13 Aug 2016 16:43

douglas.swehla wrote:
foxidrive wrote:I've been out herding the kangaroos and only just got back after one escaped...

Is this a metaphor for being busy, or have you actually been chasing down marsupials?

There are no marsupials anywhere near here, it's just been life getting in the way.

foxidrive wrote:I've implemented 2) below and added a check for permissions (Hmmm, it may have a bug in user mode)


I see that you're testing specifically for system32 in the PATH check. Do you want to look for SysWOW64 as well? My system has both System32 and SysWOW64 in %windir%, and a lot of commands are duplicated between them. It's not clear to me why that is (32- and 64-bit versions?), or what the impact would be if either of them were missing from %PATH%.

Here's a snippet from a StackOverflow answer dealing with admin elevation, that takes SysWOW64 into consideration. It uses %SystemRoot% instead of %windir%, which are the same on my system. Not sure if there's a reason for that, or just the author's habit.

Code: Select all

REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

REM --> If error flag set, we do not have admin.


The script above goes on to do an admin check via UAC, using VBS. It's pretty short, and might solve the language-dependency issue that aGerman was running into.


You're absolutely right. I don't use 64 bit windows at this point so it wasn't on my radar.
I also use an admin account with UAC disabled as a matter of course so don't see anything breaking because of that. Oops.

Thanks for your comments Douglas.

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

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

#20 Post by douglas.swehla » 13 Aug 2016 23:18

aGerman wrote:

Code: Select all

set "localadmin="
wmic path Win32_Group WHERE "LocalAccount='TRUE' AND SID='S-1-5-32-544'" assoc /assocclass:Win32_GroupUser|>nul findstr /c:Name^=\"%username%\" && set "localadmin=1"

if defined localadmin (echo Can obtain administrative elevation.) else echo Doesn't belong to the local administrators.
pause


Nice! How do you figure out what SID to use?

aGerman wrote:But WMIC isn't that downward compatible since XP is still a walking dead.

I didn't realize WMIC was that new. What about JScript or VBScript? If we can't find a universal solution, we can resort to version-specific ones. Do you know of anything that would work for XP, even if it doesn't work on later versions?

aGerman wrote:I don't want to run the script elevated.

Why not? I'm assuming you want to abide the general principal of "Spend the least possible time as admin so you can't break anything." If that's the case, then of course it makes sense to not run the whole script as admin. But what about just one command? Is there a security concern or some other danger I'm not seeing?

Like a lot of people, I use a non-admin account for most things, and enter the admin credentials of another, different account as needed. So, I see the elevation question as two parts:
1. Does the currently running account have admin privileges, even if they're not in use right now?
2. Does this user have access to an admin account, even if they're not using it right now?

As far as I know, Windows thinks that my ordinary and admin accounts are two completely separate entities, and has no way of mapping a relationship between them, which is as it should be. When I run the code above, it correctly reports that user "Douglas" is not part of the local admin group. When I want to run as admin, I authenticate as user "Admin", and that's what's stored in %username% for that session.

The only way I can think of for a script to learn whether a user has credentials for a different account is to prompt the user to enter them. If there's a way to do that without actually going on to do something as that account, then sure, let's do that. If not, though, would it be so bad to just open a new shell and immediately exit? That's not a rhetorical question; I'm really asking, and if the answer is "Yes, it would be so bad", I'm prepared to hear it.

If we're not willing to enter admin mode at all, then we'd need to tell questioners to be sure to use an admin account when running the script, if they have one, or just ask them to tell us, if it's relevant. Neither of those are terribly difficult, but getting people to follow instructions and answer questions is, apparently, difficult enough that we're resorting to automation to make it happen.

All that said, I'm really not super invested in getting question 2 answered in the main script. I think that most solutions provided here don't require admin access, and for the ones that do, it can be addressed then. I just want to be sure we understand the problem the same way. If you and Foxy think it's best to never enter admin mode, it's cool with me.

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

#21 Post by aGerman » 14 Aug 2016 05:17

douglas.swehla wrote:How do you figure out what SID to use?

Code: Select all

wmic path Win32_Group WHERE "LocalAccount='TRUE'" get /value

https://support.microsoft.com/en-us/kb/243330


douglas.swehla wrote:I didn't realize WMIC was that new. What about JScript or VBScript?

Yes the WMI can easily be scripted with these languages.


douglas.swehla wrote:
aGerman wrote:I don't want to run the script elevated.

Why not?

Because the purpose of the script is to collect informations of the opportunities that questioners have.


douglas.swehla wrote:Like a lot of people, I use a non-admin account for most things, and enter the admin credentials of another, different account as needed.

That would be for sure our first question if a certain command in the askers script would need elevated rights and we saw that his current account can't obtain them.


Regards
aGerman

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

#22 Post by dbenham » 14 Aug 2016 07:40

Cool script, but it may run into problems in some environments.

The network administrators have locked down all the computers at my job, and we cannot access the registry :!: :cry:
So the script would pretty much be useless at my workplace.


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

#23 Post by aGerman » 14 Aug 2016 08:29

Oh that's strange. Our administrators locked quite alot via GPO. But we have full access to HKCU and we can at least query informations from HKLM. I'm wondering why they completely locked you out. I was pretty sure some applications wouldn't even work without querying the registry :?

Regards
aGerman

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

#24 Post by dbenham » 14 Aug 2016 09:00

I'm working from memory at this point - all my past attempts to access the registry had failed. I'll verify on Monday.


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

#25 Post by dbenham » 15 Aug 2016 06:24

Confirmed - I cannot run the script at my workplace.

I get an error ( ERROR: Registry editing has been disabled by your administrator. ) when I attempt to run a command like reg query "HKLM\%CMDproc%" /v "EnableExtensions"


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

#26 Post by aGerman » 15 Aug 2016 07:21

Haha, you don't even "edit" anything with a query. Nevermind. Do you get the same error if you try to query HKCU?

Regards
aGerman

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

#27 Post by dbenham » 15 Aug 2016 07:42

Yes, I get the same error with HKCU

I'm not able to use REG or REGEDIT at all.


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

#28 Post by aGerman » 15 Aug 2016 07:53

That makes things more complicated :? Any suggestions much appreciated.

Another thing we have to change is the initial setlocal EnableExtensions. If extensions are disabled SETLOCAL doesn't even accept arguments. I think we should rather restart the script using CMD /E:ON /V:OFF /C.

Regards
aGerman

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

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

#29 Post by penpen » 15 Aug 2016 11:41

Depends on how the admins have locked your registry access;
maybe one of these two methods are working (if it is allowed to compile this c# source):

Code: Select all

// // >nul 2> nul & @goto :main
/*
 * Author: Ulf Schneider aka penpen
 * Free for non profit use only.
 * For profit use contact me at www.dostips.com via private message (PM).
 * readReg.cs.bat
 */

/*
:main
   @echo off
   setlocal
   cls
   set "csc="

   pushd "%SystemRoot%\Microsoft.NET\Framework"
   for /f "tokens=* delims=" %%i in ('dir /b /o:n "v*"') do (
      dir /a-d /b "%%~fi\csc.exe" >nul 2>&1 && set "csc="%%~fi\csc.exe""
   )
   popd

   if defined csc (
      echo most recent C#.NET compiler located in:
      echo %csc%.
   ) else (
      echo C#.NET compiler not found.
      goto :eof
   )

   for %%a in ("%~dpn0") do for %%b in ("%%~dpna") do (
rem      %csc% /?
      %csc% /nologo /optimize /warnaserror /nowin32manifest /unsafe /debug- /target:exe /out:"%%~b.exe" "%~f0"
   )
   exit /B
*/


using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.AccessControl;
using Microsoft.Win32;


public class ReadRegistryKey {
   public static RegistryKey getRoot(string keyName) {
      if (keyName == null) return null;
      else switch(replaceRootAbbreviation(keyName).Split(new char[] {'\\'})[0]) {
         case "HKEY_CURRENT_USER" :   return Registry.CurrentUser;
         case "HKEY_LOCAL_MACHINE":   return Registry.LocalMachine;
         case "HKEY_CLASSES_ROOT":   return Registry.ClassesRoot;
         case "HKEY_USERS":      return Registry.Users;
         case "HKEY_PERFORMANCE_DATA":   return Registry.PerformanceData;
         case "HKEY_CURRENT_CONFIG":   return Registry.CurrentConfig;
         case "HKEY_DYN_DATA":   /*
                  // Win 95/98/Me only
                     return Registry.DynData;
                  // Win XP++
                  */
                     return Registry.PerformanceData;
         default:         return null;
      }
   }

   public static string replaceRootAbbreviation(string keyName) {
      if (keyName == null) {
      } else if (keyName.StartsWith("HKCU")) { keyName = "HKEY_CURRENT_USER"     + keyName.Substring(4);
      } else if (keyName.StartsWith("HKLM")) { keyName = "HKEY_LOCAL_MACHINE"    + keyName.Substring(4);
      } else if (keyName.StartsWith("HKCR")) { keyName = "HKEY_CLASSES_ROOT"     + keyName.Substring(4);
      } else if (keyName.StartsWith("HKU" )) { keyName = "HKEY_USERS"            + keyName.Substring(3);
      } else if (keyName.StartsWith("HKPD")) { keyName = "HKEY_PERFORMANCE_DATA" + keyName.Substring(4);
      } else if (keyName.StartsWith("HKCC")) { keyName = "HKEY_CURRENT_CONFIG"   + keyName.Substring(4);
      } else if (keyName.StartsWith("HKDD")) { keyName = "HKEY_DYN_DATA"         + keyName.Substring(4);
      }

      return keyName;
   }

   public static void ReadKey1(string keyName, string valueName) {
      Console.WriteLine("Try reading \"" + valueName + "\" using Registry.GetValue: ");

      try {
         Console.WriteLine("Success: " + Registry.GetValue(replaceRootAbbreviation(keyName), valueName, "Default: \"" + valueName + "\" does not exist."));
      } catch (SecurityException securityException) { Console.WriteLine("Failure: " + securityException.Message);
      } catch (      IOException       iOException) { Console.WriteLine("Failure: " +       iOException.Message);
      } catch (ArgumentException argumentException) { Console.WriteLine("Failure: " + argumentException.Message);
      } catch (        Exception         exception) { Console.WriteLine("Failure: " +         exception.Message);
      }

      Console.WriteLine("");
   }



   public static void ReadKey2(string keyName, string valueName) {
      string [] keyNames = keyName.Split(new char[] {'\\'});
      string subKeyName = keyName.Substring(keyNames[0].Length);
      RegistryKey root = getRoot(keyName);
      RegistryKey [] subKeys = new RegistryKey[keyNames.Length];
      RegistryKey subKey = root;

      subKeys[0] = subKey;

      Console.WriteLine("Try reading \"" + valueName + "\" using RegistryKey.OpenSubKey and RegistryKey.GetValue: ");

      try {
         for (int i = 1; i < subKeys.Length; ++i) {
            subKeys[i] = subKey.OpenSubKey(keyNames[i]);
            subKey = subKeys[i];
         }
         Console.WriteLine("Success: " + subKey.GetValue(valueName, "Default: \"" + valueName + "\" does not exist."));
      } catch (SecurityException securityException) { Console.WriteLine("Failure: " + securityException.Message);
      } catch (      IOException       iOException) { Console.WriteLine("Failure: " +       iOException.Message);
      } catch (ArgumentException argumentException) { Console.WriteLine("Failure: " + argumentException.Message);
      } catch (        Exception         exception) { Console.WriteLine("Failure: " +         exception.Message);
      }

      Console.WriteLine("");

      for (int i = 1; i < subKeys.Length; ++i) {
         if (subKeys[i] != null) subKeys[i].Close();
      }
   }


   public static unsafe void Main(string[] args) {
      string [][] regValues = new string[][] {
         new string[] { "HKCU\\Control Panel\\International", "iDate" },
         new string[] { "HKCU\\Control Panel\\International", "iTime" },
         new string[] { "HKU\\.DEFAULT\\Control Panel\\International", "iDate" },
         new string[] { "HKU\\.DEFAULT\\Control Panel\\International", "iTime" },

         new string[] { "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName" },

         new string[] { "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage", "OEMCP" },
         new string[] { "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage", "ACP" },

         new string[] { "HKLM\\Software\\Microsoft\\Command Processor", "EnableExtensions" },
         new string[] { "HKLM\\Software\\Microsoft\\Command Processor", "DelayedExpansion" },
         new string[] { "HKCU\\Software\\Microsoft\\Command Processor", "EnableExtensions" },
         new string[] { "HKCU\\Software\\Microsoft\\Command Processor", "DelayedExpansion" },
      };

      if (args.Length < 2) {
         for (int i = 0; i < regValues.Length; ++i) {
            ReadKey1(regValues[i][0], regValues[i][1]);
            ReadKey2(regValues[i][0], regValues[i][1]);
         }
      } else {
         ReadKey1(args[0], args[1]);
         ReadKey2(args[0], args[1]);
      }
   }
}


penpen

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

#30 Post by aGerman » 15 Aug 2016 12:36

I know from former posts that csc was removed from Dave's PC at work :(

I'll try to work around that problems.
Alternatives (after trying to query the registry keys):
- Clock hours could be left out because it should be visible at least at the output of DIR.
- Date order could be read from the date command (even if it would be language dependent).
- enabled extensions and delayed expansion could be checked using IF statements. E.g.:

Code: Select all

@echo off
if "%1"=="restart" goto script

cmd /c "if /i "a"=="b" causes a syntax error if extensions are disabled" 2>nul
if errorlevel 1 (set ex_noreg=No) else (set ex_noreg=Yes)

if "!!"=="" (set de_noreg=Yes) else (set de_noreg=No)

cmd /e:on /v:off /c %0 restart

pause
goto :eof


:script
cd /d "%~dp0"

REM all the other code here
echo Extensions         :  %ex_noreg%
echo Delayed expansion  :  %de_noreg%


REM very last line; if extensions are disabled the label :eof doesn't implicitely exist
:eof

- I wonder if we could determine the locale name out of MUI folders/files?

Code: Select all

for /f %%i in ('dir /ad /b "%SystemRoot%\System32\??-??"^|findstr /x "[a-z][a-z]-[a-z][a-z]"') do (
  if exist "%SystemRoot%\System32\%%i\ulib.dll.mui" echo %%i
)

- OEMCP can be extracted from CHCP.
- ACP ??? No idea yet.

Regards
aGerman

Post Reply