Topic: something about batch syntax and cmd.exe  (Read 7808 times)

Re: something about batch syntax and cmd.exe
« Reply #40 on: January 02, 2019, 12:00:41 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi Slore,

Can you attach a.lnk and b.lnk ,
So I can also test when at home.

Normally I do not use Windows network, very rare...

*
I feel above works fine (%100 or %99 or !) with none Network shortcuts ?

*
VBS(wshLink object) can create shortcuts.
I am sure VBS and AutoIT can create better,
Still
I had recently read a way to create shortcuts with cmd......

*
* reply later about the proxy thing.
Take your time. :great:
I am also very slow when responding to some cases. 

:mphone::turtle:

Re: something about batch syntax and cmd.exe
« Reply #41 on: January 03, 2019, 01:37:06 AM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
a.lnk, b.lnk shortcuts maked in Windows 7.

* network_shortcut.zip (1.89 kB - downloaded 86 times.)

FYI:
Office's shortcut is maked in GUID/CLSID, those one both test.cmd or gettarget.vbs can't got the result.
and shortcut of cmd.exe, docker(bash.exe), git(bash.exe) can't work with gettarget.vbs, but the test.cmd works.
« Last Edit: January 03, 2019, 01:39:45 AM by slore »

Re: something about batch syntax and cmd.exe
« Reply #42 on: January 04, 2019, 07:46:09 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi slore,

thanks, I start to slowly work on that

start testing Command Prompt.lnk as you suggest
which has target: %windir%\system32\cmd.exe
that cause failure

I use
If [%LNKTarget%]==[] For /f "%SKIP_OPT%delims=" %%A In ('Type %LnkFile% ^|find /i "windir"') Do Set LNKTarget="%%A"
to catch the line
but it returns with an extra á
->
"á%windir%\system32\cmd.exe"

I try to get rid of á but it is not easy (nothing I start these days becomes easy  :lol: )

this did not work (just to test I use bla)
Set LNKTarget=%LNKTarget:á=bla%
so I feel á is a special chr so I decide to put it to a variable:

set str=%LNKTarget:~0,2%
Echo str: %str%
set str=%str:~-1%
Echo str: %str%

this get %str% variable have á value
but putting it into set did not work

Set LNKTarget=%LNKTarget:%str%=bla%

I need your cmd expertise again ?

Attached is a test.cmd so you can see the point I come so far:
:turtle:

Re: something about batch syntax and cmd.exe
« Reply #43 on: January 05, 2019, 06:34:13 AM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Code: [Select]
The type+find trick works for most shortcuts(95%?), but the text search in binary file is not correct way,
so some case it will failed.

as I stated, it is unstable way to find the target of shortcut.

I create a shortcut of cmd.exe, your test.cmd can get the right result, but your cmd's shortcut got a 0xA0 char before it.

this character is break code line, so "set" can't work as expected.

>temp.txt , and use binmay.exe to  replace A0 => 0A0D(new line), AND use "for /f" again, you will got it.

https://docs.microsoft.com/en-us/sysinternals/downloads/strings

strings *.lnk
strings -a *.lnk
strings -u *.lnk

will list the ANSI,UNICODE strings in file, maybe this one is better for this way.(I used this tool for finding MiniNT key in which exe or dll about RDP addtions.)

Code: [Select]
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: ]
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: ]
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: ]
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: +00
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: /C:\
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: M\s
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: Windows
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: M\s.
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: TAG
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: GWindows
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: System32
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: LM
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: System32
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: cmd.exe
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: cmd.exe
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: C:\Windows\System32\cmd.exe
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: C:\Windows\System32
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: D.
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: Q
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: cy-20160827xlvn
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: ~oC
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: ~oC
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: 1SPS
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: sf"=
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: System32 (C:\Windows)
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: 1SPS
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: L8C
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: S-1-5-21-985247172-2772233126-3468038988-1001
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: 1SPS0
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: cmd.exe
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk:
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: ^(u
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: ]
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: 1SPS
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: jc(=
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: C:\Windows\System32\cmd.exe
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: 1SPS
D:\Backup\Desktop\Command_Prompt_Test\cmd.exe_WIN10_ZH-CN.lnk: H@.
D:\Backup\Desktop\Command_Prompt_Test\Command Prompt.lnk: %@%windir%\system32\shell32.dll,-22534
D:\Backup\Desktop\Command_Prompt_Test\Command Prompt.lnk: %HOMEDRIVE%%HOMEPATH%
D:\Backup\Desktop\Command_Prompt_Test\Command Prompt.lnk: %windir%\system32\cmd.exe
D:\Backup\Desktop\Command_Prompt_Test\Command Prompt.lnk: %windir%\system32\cmd.exe
D:\Backup\Desktop\Command_Prompt_Test\Command Prompt.lnk: %windir%\system32\cmd.exe
D:\Backup\Desktop\Command_Prompt_Test\Command Prompt.lnk: 1SPS
D:\Backup\Desktop\Command_Prompt_Test\Command Prompt.lnk: L8C
D:\Backup\Desktop\Command_Prompt_Test\Command Prompt.lnk: 1SPSU(L


I Attached my cmd.exe shortcut(Win10 zh-CN). I compared it with yours, a lots difference in them, but all of them work, and right-click to property to see,
nothing different.

so this way is no guarantee for all.(for normal files maybe good, and can take a fallback to vbs or strings or others.)

ila_rendered
* Command_Prompt_Test_2.zip (154.2 kB - downloaded 89 times.)
« Last Edit: January 05, 2019, 06:40:07 AM by slore »

Re: something about batch syntax and cmd.exe
« Reply #44 on: March 27, 2019, 08:41:11 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi slore,

sorry, limited time and too many things to learn and catch these days with a heavy load of life ....
 I have a long "to do" list, in the end you will see me on previous subjects...

*
Here something I prepared and working fine,
 You know I am new on cmd world, DelayedExpansion, For ...
   It is working fine but probably I may miss something, I am only an amateur

The goal of cmd:
To avoid double .mui files to gain space (optimization)
Here Project basic plugins do not produce double .mui files but end user extracting source mui with \??-??\ naturally cause such thing. New syntax requires new solutions.  :wink:

My comments about Cmd :
+ To avoid cmd Autorun I avoid using For /F (Assumption: using only For do not cause cmd Autorun  :wink:)
+ I also avoid using findstr to avoid any line/path limitation of findstr (current method using gsar or binmay have no such limitation)
+ for now I use gsar,
 ( I need more practice and time with binmay and have a better picture about x86/x64 difference but I am sure you can do same with binmay, maybe binmay not required at all .... )

ps: I use gsar to manipulate text file to add line header to each line, probably there is an easier way to do this.

Memo: If you test other tools to add line header, make sure output format is the same ("CarriageReturn" + "LineFeed")

**
Here is cmd file:
Edit: See next post

To test change 2 lines at top
Same or similar cmd can be used with WimBuilder too
Edit: (and LiveSystemPro >NT5 projects or any current >NT5 projects in the world )
eg.
Set TargetDir=D:\WimBuilder\_Factory_\target\WIN10XPE\mounted
Set MuiLangAll=es-MX;es-ES;en-US

Edit
Space paths supported
eg.
Set TargetDir=D:\Wim Builder\_Factory_\target\WIN10XPE\mounted
Set MuiLangAll=es-MX;es-ES;en-US

**
and a small question:
I assume dir *>test.txt always creates Ascii files ?

using current gsar/binmay method only valid for Ascii files.

:turtle:

Edit
« Last Edit: March 27, 2019, 01:33:56 PM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #45 on: March 27, 2019, 09:37:05 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
A little update:
fix /d /c
improve delayed expansion control at the beginning of cmd

removed attachment to avoid end user failure, see next posts...

:turtle:
« Last Edit: March 27, 2019, 03:03:32 PM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #46 on: March 27, 2019, 01:33:22 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Additional info about initial topic subject :

a.cmd
b.cmd

inside a.cmd line
Code: [Select]
cmd.exe /c b.cmd
==>
b.cmd executed inside THE SAME CMD screen.
 Something everbody knows.  :wink:
  But there are some Important things to consider I realize (learning cmd).

Important1:
It does not execute Autorun from the registry (Interesting  :wink: )
eg.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
Autorun=Echo UserName = %UserName%&Title UserName = %UserName%

Important2:
If a.cmd have settings with SetLocal ... settings
 cmd.exe /c b.cmd does not transfer "a.cmd SetLocal ... settings" to b.cmd
  (having THE SAME cmd screen can make one feel It is transferred but it does not)


Summary:
cmd.exe /c b.cmd
-->
- No Autorun
+ Use Default HostOS SetLocal ... settings (keep in mind registry ...)

For /F .... (initial topic subject)
since it starts hidden cmd.exe /C
+ Yes Autorun
+ Use Default HostOS SetLocal ... settings (keep in mind registry ...) (I assume (not tested))

Conclusion:
+ AutoRun only executed for every CMD screen NOT every cmd.exe execution.
      (Keep in mind: For /F creates hidden CMD screen with cmd.exe execution -> so It does AutoRun)
+ Every cmd.exe execution always takes SetLocal from HostOS

***
I have a feeling to use  (starting cmd.exe with Default behaviour)
cmd.exe /D /V:Off /E:ON /C blabla.cmd
  all the time to get expected results by everyone ...  :cool:
    and never use For /F ... (instead, slore 3rd solution using temp files)

:turtle:

Edit: Improved Conclusion



Additional:
Pipe | internally use "cmd.exe  /S /D /c"
so no Autorun  :thumbsup:

But there is still SetLocal case one better keep in mind.
« Last Edit: March 31, 2019, 06:55:42 AM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #47 on: March 27, 2019, 02:54:55 PM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Code: [Select]
>Optimize_Mui_Del_20190327_1235.7z

I don't know if gsar.exe will be faster, but for simpler batch script, I perfer:

Code: [Select]
set LANG=zh-CN
for /f "delims=" %%i in ('dir /a-d /b en-US\') do (
    echo rem del /q \Windows\System32\%LANG%\%%i
) 1>>out.txt
pause


echo [dummy_for_crlf] > 1.txt
dir /b /a-d %LANG%\ >> 1.txt
V.S.
copy /b a.txt+b.txt c.txt

Quote
::Set MuiLangAll=es-MX;es-ES;en-US;kk-kk;mm-mm;nn-nn;oo-oo

I did es-MX;es-ES;en-US;zh-CN, but the result is:
Optimize_TargetSys_Mui_Delete_CMD_en-US____AT____zh-CN.txt

I think should keep the zh-CN mui files, delete en-US's files.


PS:
Default should be rem del /q for dryrun mode, than real delete the files!
I don't have builded target, so I set Set TargetDir=C:\   ...  :w00t:

Re: something about batch syntax and cmd.exe
« Reply #48 on: March 27, 2019, 03:37:23 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
I don't have builded target, so I set Set TargetDir=C:\   ...  :w00t:
I hope all ok on your side  :sad:
I quickly removed attachment to avoid others do a similar mistake...
(total download 1)

*
I had thought
If "%TargetDir%" Equ "%SystemDrive%" Exit
but I will also add
If "%TargetDir%" Equ "%SystemDrive%\" Exit
If "%TargetDir%" Equ "%SystemDrive%/" Exit
If "%TargetDir%" Equ "%SystemDrive%\\" Exit
If "%TargetDir%" Equ "%SystemDrive%//" Exit

.cmd is currently part of project (beta not active but it will be soon) that is the reason not at drymode,
 still my mistake, I will use drymode on topics.

I put more warning to the top of the file...

I was expecting you test with WimBuilder.....  :sad:

*
Thanks, good idea to add Echo [dummy_for_crlf] before dir  :thumbsup:
(and after dir on my case)

*
As I wrote I avoid For /F
 That is the reason I use gsar .
   gsar is under my control, For /F works with hidden cmd.exe /c which I prefer to avoid.

very theory eg.
 somebody with Autorun having exit or whatever and I can start cmd.exe with cmd.exe /D /V:Off /E:ON /C to avoid such things....
   but using For /F goes out of control ... Looks very bad on my side.

+
Well, I was expecting something easier to edit the header of each line inside txt maybe even without [dummy_for_crlf] ....

*
I did es-MX;es-ES;en-US;zh-CN, but the result is:
Optimize_TargetSys_Mui_Delete_CMD_en-US____AT____zh-CN.txt

I think should keep the zh-CN mui files, delete en-US's files.
Order is important
PrimaryLanguage;SubLanguage;.......;en-US

en-US is the last fallback ...

I changed Debug tests examples and put more info to the top of cmd and to Debug tests.
Code: [Select]
Echo TargetDir Value important - Delete Files - Do not use for your HostOS
Echo Info MuiLangAll Order is important "PrimaryLanguage;SubLanguage;.......;en-US" en-US always last

*
here is updated file with drymode.  :embarrassed:
([dummy_for_crlf] later...)
Edit: Updated with DryMode 2019.03.31 x2
If you need Further updates ask on current topic, latest version via plugin ...

Edit: Latest update of following and some other cmd files available inside Finals\"PrePost" plugin (For Today under [Optimize_Mui_Del_CMD] ).

Code: [Select]
Rem ------------------------- CMD Start HERE ----- Above Lines maybe added by another tool -- Remove if required --------
Cls
@Echo off
Echo Lancelot 2019.03.27 : CMD File To optimize mui files with deduction (Natural Result of using \??-??\ for mui files)
Echo Special Thanks to slore Reply 44 and later http://TheOven.org/index.php?topic=2669.msg32597#msg32597
Echo Parameters for cmd file: 1 TargetDir 2 MuiLangAll
Echo eg. blabla.cmd "D:\B ase\Target\Win10PESE" "es-MX;es-ES;en-US"
Echo tip: You can use set at top of cmd without parameters See relevant lines at ::FOR DEBUG TESTS
Echo TargetDir Value important - Delete Files - Do not use for your HostOS
Echo Info MuiLangAll Order is important "PrimaryLanguage;SubLanguage;.......;en-US" en-US always last
Echo Cmd have Del *.txt use under an empty folder
Echo search drymode inside cmd to test with drymode - No Delete
Rem ---
cd /d "%~dp0"
Rem --- To Avoid cmd Autorun AND relevant registry settings
:: https://searchwindowsserver.techtarget.com/tip/Is-Delayed-Expansion-on
:: If Not %Comspec%==!Comspec! Echo Delayed Expansion is Not enabled.
SetLocal DisableDelayedExpansion
Set t=%ErrorLevel%
If %t% Neq 0 Echo %t%
If %t% Neq 0 Exit /b %t%
If %Comspec%==!Comspec! Exit
SetLocal EnableExtensions
Set t=%ErrorLevel%
If %t% Neq 0 Echo %t%
If %t% Neq 0 Exit /b %t%
Rem ---------------
::FOR DEBUG TESTS
::Set TargetDir=D:\B ase\Target\Win10PESE
:: Info MuiLangAll Order is important PrimaryLanguage;SubLanguage;.......;en-US
::Set MuiLangAll=en-US
::Set MuiLangAll=es-MX;es-ES;en-US
::Set MuiLangAll=es-MX;es-ES;el-GR;cs-CZ;da-DK;en-US
::FOR DEBUG TESTS
Rem ---------------
If %1- Neq - Set TargetDir=%~1
If %2- Neq - Set MuiLangAll=%~2
Rem ---------------
Rem To Avoid end user wrong usage - PreCheck Exit ---- Start
If "%TargetDir%" Equ "" Exit
If "%TargetDir%" Equ "." Exit
If "%TargetDir%" Equ ".." Exit
If "%TargetDir%" Equ "\" Exit
If "%TargetDir%" Equ ".\" Exit
If "%TargetDir%" Equ "..\" Exit
Rem --
If "%TargetDir%" Equ "%SystemDrive%" Exit
If "%TargetDir%" Equ "%SystemDrive%\" Exit
If "%TargetDir%" Equ "%SystemDrive%\\" Exit
If "%TargetDir%" Equ "%SystemDrive%/" Exit
If "%TargetDir%" Equ "%SystemDrive%//" Exit
Rem --
Call Set t=%%TargetDir:%SystemRoot%=Bla__%%
If Not "%t%" Equ "%TargetDir%" Exit
Call Set t=%%TargetDir:%WinDir%=Bla__%%
If Not "%t%" Equ "%TargetDir%" Exit
Rem -
If "%TargetDir%" Equ "%SystemRoot%" Exit
If "%TargetDir%" Equ "%SystemRoot%\" Exit
If "%TargetDir%" Equ "%SystemRoot%\\" Exit
If "%TargetDir%" Equ "%SystemRoot%/" Exit
If "%TargetDir%" Equ "%SystemRoot%//" Exit
If "%TargetDir%" Equ "%WinDir%" Exit
If "%TargetDir%" Equ "%WinDir%\" Exit
If "%TargetDir%" Equ "%WinDir%\\" Exit
If "%TargetDir%" Equ "%WinDir%/" Exit
If "%TargetDir%" Equ "%WinDir%//" Exit
Rem To Avoid end user wrong usage - PreCheck Exit ---- Finish
Rem ---------------
Del *.txt
Rem ---------------
Set gsarexe=.\gsar_gnuwin32_M_HostOS\gsar.exe
If Not Exist %gsarexe% Exit
Rem ---------------
Echo TargetDir:       %TargetDir%
Echo MuiLangAll:      %MuiLangAll%
Rem ---------------
If Not Exist "%TargetDir%" Exit
Rem ---------------
Set MuiLangTotal=0
For %%G In (%MuiLangAll%) Do (Set /a MuiLangTotal+=1)
Echo MuiLangTotal:    %MuiLangTotal%
Rem ---------------
::Cls
::@Echo off
If %MuiLangTotal% Geq 1 (
SetLocal EnableDelayedExpansion
Set MuiLangOptimize=%MuiLangAll%
Call :Start_Mui_Optimize \Windows\System32\ Optimize_TargetSys_Mui_
Set MuiLangOptimize=%MuiLangAll%
Call :Start_Mui_Optimize \Windows\System32\drivers\ Optimize_TargetSys-drivers_Mui_
Set MuiLangOptimize=%MuiLangAll%
Call :Start_Mui_Optimize \Windows\ Optimize_TargetWin_Mui_
Set MuiLangOptimize=%MuiLangAll%
If Exist "%TargetDir%\Windows\SysWOW64\" Call :Start_Mui_Optimize \Windows\SysWOW64\ Optimize_TargetWin-SysWOW64_Mui_
SetLocal DisableDelayedExpansion
)
Rem -
Echo.
Echo.
Echo.
Echo.
Echo.
::Pause
Exit
cmd.exe /D /V:Off /E:ON
Exit
Rem -
:Start_Mui_Optimize
Set FileHeader=%2
Echo Start_Mui_Optimize:MuiLangOptimize           !MuiLangOptimize!
::-
Set MuiLangOptimizeTotal=0
For %%G In (!MuiLangOptimize!) Do (Set /a MuiLangOptimizeTotal+=1)
:: Echo Start_Mui_Optimize:MuiLangOptimizeTotal:     !MuiLangOptimizeTotal!
If !MuiLangOptimizeTotal! Gtr 1 (
::-
Set t=0
For %%G In (!MuiLangOptimize!) Do (
Set /a t+=1
If !t! Equ 1 Set First=%%G
If !t! Equ 1 Set MuiLangOptimize=!MuiLangOptimize:%%G;=!
If !t! Gtr 1 (
Rem Echo First !First!
Rem Echo %%G
Echo !First! %%G
::Echo on
Set s=1
Echo %TargetDir%%1%!First!
Echo %TargetDir%%1%%%G
If Not Exist "%TargetDir%%1%!First!\*" Set s=0
Echo !s!
If Not Exist "%TargetDir%%1%%%G\*" Set s=0
Echo !s!
If !s! Equ 1 (
If Not Exist Delete_Dir_B_A-D_!First!.txt dir "%TargetDir%%1%!First!\*" /b /A-D>!FileHeader!Delete_Dir_B_A-D_!First!.txt
Rem -
Echo [Dummy_For_crlf:]>!FileHeader!Delete_CMD_!First!____AT____%%G.txt
Type !FileHeader!Delete_Dir_B_A-D_!First!.txt>>!FileHeader!Delete_CMD_!First!____AT____%%G.txt
Echo [Dummy_For_crlf:]>>!FileHeader!Delete_CMD_!First!____AT____%%G.txt
Rem -
Echo !First!
Echo %%G
Rem -------
Set TargetDirGsar=%TargetDir::=::%
Echo !TargetDirGsar!
Rem x22 is quote
%gsarexe% -o -i "-s:x0A" "-r:x0ADel /q /f :x22!TargetDirGsar!%1%%G\\" !FileHeader!Delete_CMD_!First!____AT____%%G.txt
Rem Remove [Dummy_For_crlf:] at the end with replacement
%gsarexe% -o -i "-sDel /q /f :x22!TargetDirGsar!%1%%G\:x5BDummy_For_crlf:x3A:x5D:x0D:x0ADel /q /f :x22!TargetDirGsar!%1%%G\\" "-r" !FileHeader!Delete_CMD_!First!____AT____%%G.txt
Rem Remove [Dummy_For_crlf:] from top
%gsarexe% -o -i "-s:x5BDummy_For_crlf:x3A:x5D:x0D:x0A" "-r" !FileHeader!Delete_CMD_!First!____AT____%%G.txt
Rem Add quote to the end
%gsarexe% -o -i "-s:x0D:x0A" "-r:x22:x0D:x0A" !FileHeader!Delete_CMD_!First!____AT____%%G.txt
If Exist !FileHeader!Delete_CMD_!First!____AT____%%G.cmd Del /q /f !FileHeader!Delete_CMD_!First!____AT____%%G.cmd
Ren !FileHeader!Delete_CMD_!First!____AT____%%G.txt !FileHeader!Delete_CMD_!First!____AT____%%G.cmd
Rem drymode when you comment out next line___
Rem Call !FileHeader!Delete_CMD_!First!____AT____%%G.cmd
Ren !FileHeader!Delete_CMD_!First!____AT____%%G.cmd !FileHeader!Delete_CMD_!First!____AT____%%G.txt
)
)
)
Call :Start_Mui_Optimize %1 %2
)
Goto :EOF

**
Again very sorry,
I hope all ok on your side  :sad:
« Last Edit: April 02, 2019, 05:17:44 PM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #49 on: March 27, 2019, 04:08:42 PM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Quote
I hope all ok on your side  :sad:

That is OK. just zh-CN\*.mui resources, I extracted them again from the ISO.

I thought only text file operation, missing the line
Code: [Select]
cmd.exe /d /c !FileHeader!Delete_CMD_!First!____AT____%%G.cmd

Re: something about batch syntax and cmd.exe
« Reply #50 on: March 27, 2019, 04:16:19 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Thanks for the Good news.  :cheers:

All my mistake, always drymode on topics.... me cmd amateur  :embarrassed:
nobody tried plugins on hostos before since plugins ...... updating my bad habit with cmd ....

:turtle:

Re: something about batch syntax and cmd.exe
« Reply #51 on: March 28, 2019, 07:01:16 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
echo [dummy_for_crlf] > 1.txt
dir /b /a-d %LANG%\ >> 1.txt
V.S.
copy /b a.txt+b.txt c.txt

Hi slore,

Inside cmd I keep untouched copy of dir result to be used by other lines (loops)
 to speed up without dir again and again.  :wink:
  and untouched to keep things tidy.
   (keep things tidy naturally, do not produce max speed, but have other advantages ...... ,
     I am after optimum max speed with tidy adjustments.)
Code: [Select]
If NOT Exist Delete_Dir_B_A-D_!First!.txt dir "%TargetDir%%1%!First!\*" /b /A-D>!FileHeader!Delete_Dir_B_A-D_!First!.txt
Copy !FileHeader!Delete_Dir_B_A-D_!First!.txt !FileHeader!Delete_CMD_!First!____AT____%%G.txt


This makes me not use your Echo [dummy_for_crlf] idea with 1) Echo 2) Dir. (I will use at other places.  :thumbsup: )

Does this looks ok from your eyes using your idea with 1) Echo 2) Type ?

eg.
Code: [Select]
cd /d "%~dp0"
rem ----------
dir /b /A-D "%SystemRoot%\System32\en-us\">Dir_B_A-D.txt
rem ----------
Echo [dummy_for_crlf:] > aaa.txt
Type Dir_B_A-D.txt>>aaa.txt
Echo [dummy_for_crlf:] >> aaa.txt
rem ----------
Echo things with aaa.txt here Later we need bbb.txt
rem ----------
Echo [dummy_for_crlf:] > bbb.txt
Type Dir_B_A-D.txt>>bbb.txt
Echo [dummy_for_crlf:] >> bbb.txt
cmd

I am not sure If "using ready file" is better compared to 1) Echo 2) Copy way ?
 Looks very similar to me. 1) Echo 2) Copy --- 1) Echo 2) Type
  You have more experience ... ?

:turtle:

Re: something about batch syntax and cmd.exe
« Reply #52 on: March 31, 2019, 10:19:28 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi slore,

*
updated previous post with drymode
 Reply 48 http://theoven.org/index.php?topic=2669.msg32612#msg32612

Changes:
+ Prefer Type which is tidier
+ used [Dummy_For_crlf:] which gives a better explanation.  :thumbsup:


*
I learn Pipe | internally use "cmd.exe  /S /D /c"
 Add Reply 46 Additional info http://theoven.org/index.php?topic=2669.msg32607#msg32607
  I believe cmd authors simply forget /D with For /F ....

*
I could not figure out how to replace string using variables

eg.
Code: [Select]
@Echo Off
cls
Rem Hardcoded Works
Set t=C:\Windows\System32\
Set t=%t:C:\Windows=Bla__%
Echo %t%
Rem Using variable fails
Set t=C:\Windows\System32\
Set t=%t:%SystemRoot%=Bla__%
Echo %t%
cmd.exe /D /V:Off /E:ON

Maybe you have an idea ?

:turtle:

Re: something about batch syntax and cmd.exe
« Reply #53 on: March 31, 2019, 11:20:00 AM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Hi, Lancelot

Quote
updated previous post with drymode
:thumbsup:


Quote
I am not sure If "using ready file" is better compared to 1) Echo 2) Copy way ?
 Looks very similar to me. 1) Echo 2) Copy --- 1) Echo 2) Type
  You have more experience ... ?

type or copy both OK on my side for this(only ascii strings in text file).
just chose one you like.


Quote
I learn Pipe | internally use "cmd.exe  /S /D /c"
I use cmdWrapper for disabling Autorun entry to keep the code in same.
I don't have intensive study on it, follow your research.  :tongue:

Quote
I could not figure out how to replace string using variables

Code: [Select]
Rem Using variable
rem 1. call
Set t=C:\Windows\System32\
call Set t=%%t:%SystemRoot%=Bla__%%
Echo %t%

Code: [Select]
rem 2.DELAYEDEXPANSION
setlocal ENABLEDELAYEDEXPANSION
Set t=C:\Windows\System32\
Set t=!t:%SystemRoot%=Bla__!
Echo %t%
« Last Edit: March 31, 2019, 11:20:37 AM by slore »

Re: something about batch syntax and cmd.exe
« Reply #54 on: March 31, 2019, 11:55:32 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Thanks,

I will practice when I get back home  :thumbsup:

*
Yes I know, I write here keeping in mind others can also benefit....  :wink:

*
HKLM and or HKCU there is
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
EnableExtensions
DelayedExpansion

Which are to me like autorun, potential troubles  :wink:
(
Since cmd.exe initiation with pipe and "cmd.exe /C" on same cmd window start with these values
)

Maybe good idea you get your cmdWrapper not read these values during start (HKLM HKCU * 2 values = Probably 4 )
And always start default ( EnableExtensions 1 - DelayedExpansion 0 )

I am still on learning period about them, Just an idea to share. :bubblegum:

:mphone::turtle:

Re: something about batch syntax and cmd.exe
« Reply #55 on: March 31, 2019, 01:40:21 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi slore,

Code: [Select]
call Set t=%%t:%SystemRoot%=Bla__%%

WOW, first time I use Call that way. :magic: Thanks a lot  :cheerleader:

I am not sure if such a thing documented !
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call
 :xmas-thumbsup:

**
This make me remind another question about Call , maybe you have other magics :

Is there a way to start a label directly (eg. TestB ) on SecondCmdFile from first CmdFile

CMDFile.cmd
Code: [Select]
cd /d "%~dp0"
@Echo Off
cls
Call SecondCMDFile.cmd :TestB
cmd



SecondCMDFile.cmd
Code: [Select]
:TestA
Echo Test A
Pause
Goto :EOF

:TestB
Echo Test B
Pause
Goto :EOF

Following syntax:
call [Drive:][Path]<FileName> [<BatchParameters>] [:<Label> [<Arguments>]]

I feel I can jump to label of Second Batch file, but I could not figure out ?

Call SecondCMDFile.cmd :TestB
Call SecondCMDFile.cmd ::TestB
Call SecondCMDFile.cmd :\:TestB

All failed ....

:turtle:
« Last Edit: March 31, 2019, 01:42:26 PM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #56 on: March 31, 2019, 02:20:34 PM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Quote
Is there a way to start a label directly (eg. TestB ) on SecondCmdFile from first CmdFile

see:
D:\D e v\WimBuilder2\Projects\WIN10XPE\prepare.bat

:BEFORE_WIM_MOUNT
:BEFORE_HIVE_LOAD

There are 2 label functions.

D:\D e v\WimBuilder2\bin\_Process.bat
Code: [Select]
rem call prepare.bat before mounting
if exist "%WB_PROJECT_PATH%\prepare.bat" (
    call "%WB_PROJECT_PATH%\prepare.bat" :BEFORE_WIM_MOUNT
)

...

rem call prepare.bat before hive load
if exist "%WB_PROJECT_PATH%\prepare.bat" (
    call "%WB_PROJECT_PATH%\prepare.bat" :BEFORE_HIVE_LOAD
)

seems like your request: Call SecondCMDFile.cmd :TestB

Re: something about batch syntax and cmd.exe
« Reply #57 on: March 31, 2019, 04:05:13 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Thanks slore,

yes I also use this indirect method  :thumbsup:

ok another question:

to transfer ALL parameters with the indirect method, what is best way.

This ?
Quote
Call %1 %*

:turtle:

Re: something about batch syntax and cmd.exe
« Reply #58 on: March 31, 2019, 06:05:20 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi slore,

*
Again updated previous post with drymode
 Reply 48 http://theoven.org/index.php?topic=2669.msg32612#msg32612

+
Call Set t=%%TargetDir:%SystemRoot%=Bla__%%
If Not "%t%" Equ "%TargetDir%" Exit
+
and to speed up using Call to execute cmd files  :wink:

:turtle:

Re: something about batch syntax and cmd.exe
« Reply #59 on: April 03, 2019, 11:10:48 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi Slore,

After some tests I believe correct header for my cmd files would be something like that :
(to be used after >= XP (NT 5.1)  :wink: )
Code: [Select]
Rem - CMD Header to be sure about Default behavior - Extensions Enabled and DelayedExpansion Disabled - Start
SetLocal EnableExtensions
Set t=%ErrorLevel%
If %t% Neq 0 Echo %t%
If %t% Neq 0 Exit /b %t%
SetLocal DisableDelayedExpansion
Set t=%ErrorLevel%
If %t% Neq 0 Echo %t%
If %t% Neq 0 Exit /b %t%
If %Comspec%==!Comspec! Exit
Set t=
Rem - CMD Header to be sure about Default behavior - Extensions Enabled and DelayedExpansion Disabled - Finish


pause
exit

+
test EnableExtensions first (wrong Reply 48  :embarrassed: ... ps: check notes at Reply 48 I will not update that anymore  ... )
+
using t variable temporarily and remove t variable in the end with Set t=
--->
(
Still not sure about that, maybe not required and a better way exist...
Is there a case "Set" or "If" produce %ErrorLevel% ? If not no need %t%  :smile: ??

I notice "If" and "Set" do not produce ErrorLevel , when failure cmd close,
 but maybe I am missing something, let me know ???
)


**
Learning and slowly moving to cmd ...

maybe a cross-platform open-source distributable cmd equivalent (to get same .cmd files work) 
 might be better for the future.
  If you have practiced such a thing before let me know?

:turtle:

 

Powered by EzPortal