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

something about batch syntax and cmd.exe
« on: December 15, 2018, 01:49:25 AM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
something about batch syntax and cmd.exe discussed in other topics, leave topic tidy, I started a new topic here.
« Last Edit: December 16, 2018, 05:22:38 AM by slore »

Re: something about batch syntax and cmd.exe
« Reply #1 on: December 15, 2018, 01:51:08 AM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Re: Win10PESE cannot build in no internet/connect to internet with proxy environment
« Reply #17 on: December 13, 2018, 01:27:33 PM »

Hi slore,

Here is an out of topic cmd question If you are interested :

I try to escape from cmd Autorun and mostly escape so far
 but I figure out Autorun always executes with For /F loop having a command with In.

Reproduce:
Code: [Select]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"Autorun"="Echo UserName = %UserName%&Title UserName = %UserName%"


Test.cmd
Code: [Select]
For /f %%A In ( 'Echo Test' ) Do Echo Result: "%%A"
For /f %%A In ( 'cmd.exe /D /C Echo Test' ) Do Echo Result: "%%A"
For /f usebackq %%A In ( `Echo Test` ) Do Echo Result: "%%A"
For /f usebackq %%A In ( `cmd.exe /D /C Echo Test` ) Do Echo Result: "%%A"
pause

Above test.cmd are things I tried that did not work.
There is always
Code: [Select]
Result: "UserName"
That comes from Autorun

As promised slowly learning cmd, I hope you can help.

:turtle:

Edit:
add last pause line to Test.cmd
« Last Edit: December 15, 2018, 01:52:43 AM by slore »

Re: something about batch syntax and cmd.exe
« Reply #2 on: December 15, 2018, 01:52:04 AM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Re: Win10PESE cannot build in no internet/connect to internet with proxy environment
« Reply #18 on: December 13, 2018, 01:33:28 PM »

+
I test test.cmd with /D
Code: [Select]
cmd.exe /C /D test.cmd

so far Autorun not exists till it goes inside For /F In with a command.

:turtle:
« Last Edit: December 15, 2018, 01:52:30 AM by slore »

Re: something about batch syntax and cmd.exe
« Reply #3 on: December 15, 2018, 01:53:17 AM »

slore

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

I never use AutoRun so far.
After running your test.cmd, I find out the reason is:
/F 'commandset' => cmd.exe /c "commandset", so even commandset = 'cmd /d /c echo test',

start this cmd's parent cmd.exe will call the AutoRun because this without '/D' option for it.


Code: [Select]
For /f "delims=" %%A In ( 'Echo Test' ) Do Echo Result: "%%A"
echo is not a exe command, so how this work? because  this => cmd /d 'Echo Test'

Quote
For /f "delims=" %%A In ( 'cmd.exe /C Echo Test' ) Do Echo Result: "%%A"
This will output:
Code: [Select]
Result: "UserName = XXXXXXXX"
Result: "UserName = XXXXXXXX"
Echo Result: "Test"

Quote
For /f "delims=" %%A In ( 'notepad.exe' ) Do Echo Result: "%%A"

See what is in proexp.exe:
cmd.exe <---  test.cmd
   cmd.exe <--- cmd.exe /c "notepad.exe"
        notepad.exe

and output Result: "UserName = XXXXXXXX"


Question:So, how to escape from cmd Autorun in /F?
1. temporary file
Code: [Select]
cmd.exe /D /C Echo Test>"%temp%\cmd_tmp.txt"
echo For command
For /f "usebackq delims=" %%A In ("%temp%\cmd_tmp.txt") Do Echo Result: "%%A"

2. skip the AutoRun output lines

Quote
For /f "skip=1 delims=" %%A In ( 'cmd.exe /D /C Echo Test' ) Do Echo Result: "%%A"
(You need to know what print in AutoRun first...)


System settings for this it is hard to conjecture.
Like if set IFEO(Image File Execution Options) to aria2.exe, wget.exe to print a WARNNING about downloading files,
then I can't update the WIN10PESE with/without proxy :embarrassed:


Good question, I learn new stuff about cmd.exe  :great:

Re: something about batch syntax and cmd.exe
« Reply #4 on: December 15, 2018, 01:54:38 AM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Re: Win10PESE cannot build in no internet/connect to internet with proxy environment
« Reply #20 on: Today at 02:56:44 PM »

Hi slore,

It is getting harder and a bit uglier ^1 to use cmd.exe  :wink:
I would like to have a stable use of cmd that will result same with all windows (Priority 1)
 At least result same with all PE.... (Priority 2)
  (I mean All Windows or ALL PE >= XP)

Which would be more tidy without temp files.

+
Such a nice command "For /F" using ( ) with an additional cmd.exe !!!! Looks like a really bad design of cmd.exe...
(from a point of view of a new bie learning cmd.exe with For)

*
Thanks for info, It seems only workaround is using a temp file (this makes it ugly)

**
Anyway, It is what it is,
  since you are The Expert saying temp file is the only way,
    path is using a temp file.  :thumbsup:

As a result:
I feel I have to use temp file a lot on my cmd development.
I will post here above cmd when it is full ready.


****
Only IFEO (Image File Execution Options) I use on my computer is Notepad2:

http://www.flos-freeware.ch/doc/notepad2-Replacement.html

+
As far as I remember IFEO was not working with PE.
(need to be retested to be sure - I remember SYSTEM disable IFEO but did not test with Administrator with PE)

+
Does aria2 have a special adjustment for IFEO ? (like notepad2)
https://aria2.github.io/manual/en/html/

As far as I can remember, It is expected failures with IFEO if 3rd party application not designed for IFEO.

Still It is a little expected but still funny (give a smile to my face) you using aria2 cause wget fail !
 Interesting, something to keep in mind. Thanks.

ps: I updated Wget plugin yesterday to use latest 1.20. Still the first trial with Aria2 If failure Wget....

*
then I can't update the WIN10PESE with/without proxy :embarrassed:
I guess when you do not play with IFEO,
you can download plugins with a proxy now using download button ?
If yes I can provide you a way do download only updated files (=plugins+files) from server behind proxy.

As I wrote before, I am waiting for news to give more feedback to test proxy.  :great:

:turtle:

Re: something about batch syntax and cmd.exe
« Reply #5 on: December 15, 2018, 01:55:45 AM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Quote
**
Anyway, It is what it is,
  since you are The Expert saying temp file is the only way,
    path is using a temp file.  :thumbsup:

I'm not The Expert  :embarrassed: , I didn't know AutoRun yet :)
Just because batch is simple (line by line execution, and easy to access system files/reg),
python, js, ruby, powershell has more efficiency design, but powerfull things need more learn-time.

Using temp file is ONE easy way, but not the only one.

WAY2:
Code: [Select]
@echo off
rem calculate the skip line(s) of AutoRun output
set /a SKIP_N=-1
For /f "delims=" %%A In ( 'Echo Test' ) Do set /a SKIP_N+=1
if %SKIP_N% NEQ 0 (set SKIP_OPT=skip=%SKIP_N%)

For /f "%SKIP_OPT% delims=" %%A In ( 'Echo Test' ) Do Echo Result: "%%A"
For /f "%SKIP_OPT% delims=" %%A In ( 'cmd.exe /D /C Echo Test' ) Do Echo Result: "%%A"
For /f "%SKIP_OPT% usebackq delims=" %%A In ( `Echo Test` ) Do Echo Result: "%%A"
For /f "%SKIP_OPT% usebackq delims=" %%A In ( `cmd.exe /D /C Echo Test` ) Do Echo Result: "%%A"

rem when you need skip=[num], calculate it with SKIP_N first
set /a n=2+%SKIP_N%
For /f "skip=%n% tokens=1,3 delims= " %%A In ('REG QUERY HKLM\SOFTWARE /ve') do echo Value=%%A, Data=%%B
pause


WAY3:
Code: [Select]
@echo off

rem USE modified CMD.exe(without loading AutoRun command)

set ComSpec=C:\Windows\Temp\mod_cmd\cmd.exe

if exist "%windir%\Temp\mod_cmd\cmd.exe" goto :main
mkdir "%windir%\Temp\mod_cmd\"

rem TODO locale language
mkdir "%windir%\Temp\mod_cmd\en-US"
copy /y "%windir%\system32\en-US\cmd.exe.mui"  "%windir%\Temp\mod_cmd\en-US\"

rem modify "AutoRun" to "ButoRun"
copy /y "%windir%\system32\cmd.exe" "%windir%\Temp\mod_cmd\cmd_org.exe"
binmay.exe -i "%windir%\Temp\mod_cmd\cmd_org.exe" -o "%windir%\Temp\mod_cmd\cmd.exe" -s "4100750074006F00520075006E00" -r "4200750074006F00520075006E00"
fc /b "%windir%\system32\cmd.exe" "%windir%\Temp\mod_cmd\cmd.exe"

:main
For /f "delims=" %%A In ( 'Echo Test' ) Do Echo Result: "%%A"
For /f "delims=" %%A In ( 'cmd.exe /D /C Echo Test' ) Do Echo Result: "%%A"
For /f "usebackq delims=" %%A In ( `Echo Test` ) Do Echo Result: "%%A"
For /f "usebackq delims=" %%A In ( `cmd.exe /D /C Echo Test` ) Do Echo Result: "%%A"
For /f "skip=2 tokens=1,3 delims= " %%A In ('REG QUERY HKLM\SOFTWARE /ve') do echo Value=%%A, Data=%%B
pause

ofcause you can make a cmdwapper.exe that execute cmd.exe /d /c %*

* cmd_for_with_d.zip (14.16 kB - downloaded 73 times.)
« Last Edit: December 15, 2018, 06:29:21 AM by slore »

Re: something about batch syntax and cmd.exe
« Reply #6 on: December 15, 2018, 02:39:01 AM »

bob.omb

  • Code Baker
  • Grand Chef
  • *****
  • Location: USA
  • Date Registered: Jul 2017
  • Posts: 1261
For is cmd most powerful statement in my view..

also you can use tokens to parse through the delimiters

This is a very good short article regarding tokens and delimiters..

https://www.robvanderwoude.com/ntfortokens.php
« Last Edit: December 15, 2018, 02:44:10 AM by bob.omb »

Re: something about batch syntax and cmd.exe
« Reply #7 on: December 15, 2018, 07:23:22 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi Bob.Omb

I love robvanderwoude pages for years now,
But you can not see any info (or warning) about For behaviour discussed here recently.

Well there is no info (or warning) I have noticed anywhere about this For behavior yet ....


Edit:
Following only a backup of old posts on other topic, slore already keep them in line on current topic :

Following moved from Lancelot Reply 17 http://theoven.org/index.php?topic=2660.msg29887#msg29887
A copy exists at current topic Slore Reply 1 : http://theoven.org/index.php?topic=2669.msg29912#msg29912

Hi slore,

Here is an out of topic cmd question If you are interested :

I try to escape from cmd Autorun and mostly escape so far
 but I figure out Autorun always executes with For /F loop having a command with In.

Reproduce:
Code: [Select]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"Autorun"="Echo UserName = %UserName%&Title UserName = %UserName%"


Test.cmd
Code: [Select]
For /f %%A In ( 'Echo Test' ) Do Echo Result: "%%A"
For /f %%A In ( 'cmd.exe /D /C Echo Test' ) Do Echo Result: "%%A"
For /f usebackq %%A In ( `Echo Test` ) Do Echo Result: "%%A"
For /f usebackq %%A In ( `cmd.exe /D /C Echo Test` ) Do Echo Result: "%%A"
pause

Above test.cmd are things I tried that did not work.
There is always
Code: [Select]
Result: "UserName"
That comes from Autorun

As promised slowly learning cmd, I hope you can help.

:turtle:

Edit:
add last pause line to Test.cmd




Following moved from Lancelot Reply 18 http://theoven.org/index.php?topic=2660.msg29888#msg29888
A copy exists at current topic Slore Reply 2 : http://theoven.org/index.php?topic=2669.msg29913#msg29913

+
I test test.cmd with /D
Code: [Select]
cmd.exe /C /D test.cmd

so far Autorun not exists till it goes inside For /F In with a command.

:turtle:

Following moved from Lancelot Reply 20 http://theoven.org/index.php?topic=2660.msg29904#msg29904
A copy exists at current topic Slore Reply 4 : http://theoven.org/index.php?topic=2669.msg29915#msg29915

Hi slore,

It is getting harder and a bit uglier ^1 to use cmd.exe  :wink:
I would like to have a stable use of cmd that will result same with all windows (Priority 1)
 At least result same with all PE.... (Priority 2)
  (I mean All Windows or ALL PE >= XP)

Which would be more tidy without temp files.

+
Such a nice command "For /F" using ( ) with an additional cmd.exe !!!! Looks like a really bad design of cmd.exe...
(from a point of view of a new bie learning cmd.exe with For)

*
Thanks for info, It seems only workaround is using a temp file (this makes it ugly)

**
Anyway, It is what it is,
  since you are The Expert saying temp file is the only way,
    path is using a temp file.  :thumbsup:

As a result:
I feel I have to use temp file a lot on my cmd development.
I will post here above cmd when it is full ready.


****
Only IFEO (Image File Execution Options) I use on my computer is Notepad2:

http://www.flos-freeware.ch/doc/notepad2-Replacement.html

+
As far as I remember IFEO was not working with PE.
(need to be retested to be sure - I remember SYSTEM disable IFEO but did not test with Administrator with PE)

+
Does aria2 have a special adjustment for IFEO ? (like notepad2)
https://aria2.github.io/manual/en/html/

As far as I can remember, It is expected failures with IFEO if 3rd party application not designed for IFEO.

Still It is a little expected but still funny (give a smile to my face) you using aria2 cause wget fail !
 Interesting, something to keep in mind. Thanks.

ps: I updated Wget plugin yesterday to use latest 1.20. Still the first trial with Aria2 If failure Wget....

*
then I can't update the WIN10PESE with/without proxy :embarrassed:
I guess when you do not play with IFEO,
you can download plugins with a proxy now using download button ?
If yes I can provide you a way do download only updated files (=plugins+files) from server behind proxy.

As I wrote before, I am waiting for news to give more feedback to test proxy.  :great:

:turtle:
« Last Edit: December 15, 2018, 08:20:02 PM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #8 on: December 15, 2018, 07:46:55 PM »

Lancelot

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

Good idea to split topics,
I removed my unrelated posts on the other topic following your way. :thumbsup:

I only make a backup on my previous post with an edit.

Re: something about batch syntax and cmd.exe
« Reply #9 on: December 15, 2018, 08:17:16 PM »

Lancelot

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

Both WAY2: and WAY3: looks cool.  :great:
Big Thanks for them.
I like Way2 more...

I need more time to test & study more....

+
A 3rd party "For" (eg. ForParty.exe ) that do same with For is just another idea.
(only difference would be not using cmd.exe /c inside ( ) ....  :wink: )

----> Well life not easy with cmd.exe  :lol:

ps:
rem TODO locale language
check
Call,HostMuiLang

Test-inside CodeBox, see log....

eg Codebox:
Code: [Select]
[Process]
If,ExistFile,%api%,AddVariables,%api%,ApiVar,GLOBAL
//-
Call,HostMuiLang
Echo,%HostMuiLang%


ps:
%SystemRoot% is always available since I guess Win95 to Win10 (out of box)
%Windir% only exists after Vista (out of box)
I always use %SystemRoot% on my cmd files when required.

:turtle:

Re: something about batch syntax and cmd.exe
« Reply #10 on: December 16, 2018, 06:11:40 AM »

slore

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

Both WAY2: and WAY3: looks cool.  :great:
Big Thanks for them.
I like Way2 more...

I need more time to test & study more....

I think WAY3 is good(better WAY3.5 cmdWrapper.exe).

just put
Code: [Select]
set ComSpec=C:\Windows\System32\cmdWrapper.exe
in head,
the rest is simple, like no AutoRun entry.

Need update every "FOR" command by the WAY2.

and the ComSpec path will cache in first FOR /f command.

Code: [Select]
set ComSpec=C:\Windows\System32\cmdWrapper.exe
For /f %%A In ( 'Echo Test' ) Do Echo Result: "%%A"

set ComSpec=C:\WINDOWS\system32\cmd.exe
For /f %%A In ( 'Echo Test' ) Do Echo Result: "%%A"


Code: [Select]
check
Call,HostMuiLang

Test-inside CodeBox, see log....
WimBuilder2 can directly use %LocaleID%, %I18N_LCID%, %WB_UI_LANG% for host language name,
%WB_PE_LANG%, %xx-XX% for boot.wim/winre.wim language.  :cool:


Code: [Select]
ps:
%SystemRoot% is always available since I guess Win95 to Win10 (out of box)
%Windir% only exists after Vista (out of box)
I always use %SystemRoot% on my cmd files when required.

 :thumbsup:
Keep compatibilities need more work/test.
well the sample is show how to +"/d" to for command, I missed this detail.
« Last Edit: December 16, 2018, 12:39:45 PM by slore »

Re: something about batch syntax and cmd.exe
« Reply #11 on: December 16, 2018, 09:40:00 AM »

Lancelot

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

Yes I agree with your WAY3.5 comments.
It looks like best way for WimBuilderGUI  :thumbsup:
I will respond after I get something ready about this....

*
Keep compatibilities need more work/test.
well the sample is show how to +"/d" to for command, I missed this detail.
Compatibility starting with NT5.1 (XP) is enough to me with cmd.exe  :wink:
(lower that point It seems not possible or very hard....)

There are still many 2k3 servers along with XP users around....


*
(I updated PESE plugins with 1 hour. download the ZIP toke 20 minutes.)
Reason behind I guess you are too advanced user......  :wink:

Anyway, here is a cmd file to extract zip distribution.

Most important difference is, It extracts zip to a second special folder.

Update_with_zip.cmd
+ requires 7z.exe working with cmd
+ drop .zip to Update_with_zip.cmd with parameter 1
Code: [Select]
::Lancelot Reply 11: http://TheOven.org/index.php?topic=2669.msg29944#msg29944
::Current cmd can be used to update packed distributions of SE and Gena
::for now Do not use with basefolder having space
::
::Close Builder before using current cmd file (or restart builder after using current cmd file)
::Manual Settings:
::Set BaseFolder=.\Oven
::Set ProjectFolderName=Win10PESE
::Set BuilderExecutable=BuilderSE.exe
::Set BuilderConfiguration=BuilderSE.ini
::
::You can manually add package or drop file to cmd (par1)
::Set package=Win10PE_SE_2015-09-11.zip
::
::TODO
::- Follow package path for BaseFolder
::- Autodetect %ProjectFolderName% by following zip name (or %1) first 5 letters.
::- Autoname BuilderExecutable and BuilderConfiguration
::- AutoRestart Builder (Detect If builder running If yes restart If not do not start (or start optional) ...)
::- Check with folder with space and file with space
::
::
cd /d %~dp0
Set BaseFolder=.\Oven
::Parameter 1 optional for zip file
Set package=Win10PE_SE_2015-09-11.zip
If Not [%1]==[] Set package=%1
If Not Exist %package% Call :PackageFileNotFOund

::Set BaseFolder=D:\Oven
::
::
::
Set ProjectFolderName=Win10PESE
Set BuilderExecutable=BuilderSE.exe
Set BuilderConfiguration=BuilderSE.ini

::
Call :Test7zOperational
::
If Not Exist "%BaseFolder%\Temp\%ProjectFolderName%" (
Md "%BaseFolder%\Temp\%ProjectFolderName%"
If %ErrorLevel% NEQ 0 Call :MD_ERROR "%BaseFolder%\Temp\%ProjectFolderName%"
)
::
Call :BuilderUpdateCheck
::
::Step1 Start
::Update 1:1 copy of Project to a special folder to have Exact copy of files with Project.
::-
::We can update this folder with downloading updated plugins from server (not implemented - Exists at Utils\Update XXX Exact and Secure)
::Or
::we can use distributed package
::
::Step1 Update folder with Distributed package - Start
::First Extract Project to a temp folder - To see Extractor works fine and zip file is ok
Md "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
If %ErrorLevel% NEQ 0 Call :RD_ERROR "%BaseFolder%\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
::-
7z.exe x %package% -y -o"%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
If %ErrorLevel% NEQ 0 Call :Extract_Error "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract" %ErrorLevel%
::-
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Projects"
If %ErrorLevel% NEQ 0 Call :RD_ERROR "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Projects"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Projects"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Projects"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Projects"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Projects"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Projects"
Move "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract\Projects" "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%"
If %ErrorLevel% NEQ 0 Call :Move_ERROR "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract" "Projects"
::-
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
If %ErrorLevel% NEQ 0 Call :RD_ERROR "%BaseFolder%\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
Rd /s /q "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Temp_Extract"
::Step1 Update folder with Distributed package - Start
::Step1 Finish
::-
::-
::Step2 Update BaseFolder
::We should use Xcopy (from "%BaseFolder%\Workbench\Common\Download_%ProjectFolderName%\Projects" ) when downloading updated plugins from server
::If updating with packed file using 7z would be faster...
::-
::Step2a1 - Before updating BaseFolder Save Plugin settings of project (not implemented - Exists at Utils\Update XXX Exact and Secure)
::-
::Step2b Update BaseFolder with packed file:
Md "%BaseFolder%\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\%ProjectFolderName%"
If %ErrorLevel% NEQ 0 Call :RD_ERROR "%BaseFolder%\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\%ProjectFolderName%"
Md "%BaseFolder%\Tools\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\Tools\%ProjectFolderName%"
If %ErrorLevel% NEQ 0 Call :RD_ERROR "%BaseFolder%\Tools\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\Tools\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\Tools\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\Tools\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\Tools\%ProjectFolderName%"
Rd /s /q "%BaseFolder%\Tools\%ProjectFolderName%"
::Extract Project
7z.exe x %package% -y -o"%BaseFolder%"
If %ErrorLevel% NEQ 0 Call :Extract_Error "%BaseFolder%" %ErrorLevel%
::-
::Step2a2 - After updating BaseFolder Restore Plugin settings of project (not implemented - Exists at Utils\Update XXX Exact and Secure)
::
::
::cmd
::pause
exit

:BuilderUpdateCheck
If Exist "%BaseFolder%\%BuilderExecutable%" Call :BuilderUpdatePre
GOTO:EOF

:BuilderUpdatePre
Move "%BaseFolder%\%BuilderExecutable%" "%BaseFolder%\Temp\%ProjectFolderName%"
If %ErrorLevel% NEQ 0 Call :BuilderOpen_ERROR
Move "%BaseFolder%\%BuilderConfiguration%" "%BaseFolder%\Temp\%ProjectFolderName%"
GOTO:EOF

:BuilderOpen_ERROR
@Echo Off
cls
Echo.
Echo.
Echo.
Echo Close Builder and Start current cmd again
Echo.
Echo.
Echo.
Echo.
Echo.
Echo.
Echo CMD screen will exit now.
Echo.
Echo.
pause
exit
GOTO:EOF

:Test7zOperational
::It seems 7z.exe without 7z.dll can extract .zip files (need to be better tested) for now no test to check 7z.dll Operational
cls
7z.exe
If %ErrorLevel% NEQ 0 Call :Test7zOperationalFailure %ErrorLevel%
GOTO:EOF

:Test7zOperationalFailure
@Echo Off
cls
Echo.
Echo.
Echo.
Echo Can not get 7z.exe work properly
Echo.
Echo 7z.exe ErrorLevel=%~1
Echo.
Echo.
If %~1 EQU 9009 (
Echo 7z.exe not operational
Echo eg. Put 7z.exe and 7z.dll to same folder with current cmd file
)
Echo.
Echo.
Echo.
Echo CMD screen will exit now.
Echo.
Echo.
pause
exit
GOTO:EOF

:PackageFileNotFOund
@Echo Off
cls
Echo.
Echo.
Echo.
Echo Can not Find Package:
Echo %package%
Echo.
Echo.
Echo.
Echo.
Echo.
Echo.
Echo CMD screen will exit now.
Echo.
Echo.
pause
exit
GOTO:EOF

:RD_Error
@Echo Off
cls
Echo.
Echo.
Echo.
Echo Can not delete folder:
Echo %~1
Echo.
Echo.
Echo Fix related things and Restart current CMD file again
Echo.
Echo Tip: You may forget an application (eg. 7z Explorer)
Echo       running under this folder
Echo.
Echo.
Echo.
Echo CMD screen will exit now.
Echo.
Echo.
pause
exit
GOTO:EOF

:Extract_Error
@Echo Off
::cls
Echo.
Echo.
Echo.
Echo Extractor fails with an ErrorLevel:
Echo ErrorLevel=%~2
Echo.
Echo.
Echo Fix related things and Restart current CMD file again
Echo.
Echo Tips:
Echo 1) Check Extractor error line above
Echo 2) Check ErrorLevel used by Extractor
Echo       (See Extractor Help file or Check Extractor help pages)
Echo 3) Be sure you have Enough Space to extract on disk
Echo.
Echo.
Echo.
Echo CMD screen will exit now.
Echo.
Echo.
pause
exit
GOTO:EOF


:Ren_ERROR
@Echo Off
cls
Echo.
Echo.
Echo.
Echo Can not Rename folder:
Echo From %~1
Echo To %~2
Echo.
Echo Fix related things and Restart current CMD file again
Echo.
Echo.
Echo.
Echo.
Echo CMD screen will exit now.
Echo.
Echo.
pause
exit
GOTO:EOF

:Move_ERROR
@Echo Off
cls
Echo.
Echo.
Echo.
Echo Can not Move:
Echo From %~1
Echo To %~2
Echo.
Echo Fix related things and Restart current CMD file again
Echo.
Echo.
Echo.
Echo.
Echo CMD screen will exit now.
Echo.
Echo.
pause
exit
GOTO:EOF

:MD_ERROR
@Echo Off
cls
Echo.
Echo.
Echo.
Echo Can not Create Folder:
Echo %~1
Echo.
Echo.
Echo Fix related things and Restart current CMD file again
Echo.
Echo.
Echo.
Echo.
Echo CMD screen will exit now.
Echo.
Echo.
pause
exit
GOTO:EOF

+
Above cmd also prevent things that may miss from end-user eyes (eg. removed plugins) by removing old project folder :
Quote
Apps\Network\Mozilla Firefox ESR (P) download failed with/without proxy(unexpected)
This is my mistake. I forgot to update the plugins.

+
above cmd can be improved more, some ideas left in my mind:
eg.
- Autodetect %ProjectFolderName% by following zip name (or %1) first 5 letters.
- check if file exists (%1 check)
- Check 7z operational or not before rd
etc.

Feel free to fix, update, use, rewrite etc.  :great:


====>
Having second special folder same with zip project folder will get you to update projects from server much faster compared to downloading zip.
and
you can download plugins with a proxy now using download button ?
If yes I can provide you a way do download only updated files (=plugins+files) from server behind proxy.
after you have test results on real proxy environment, related thigns further on other topic.

:turtle:
« Last Edit: December 17, 2018, 08:20:42 AM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #12 on: December 16, 2018, 12:07:59 PM »

APT

  • Grand Chef
  • *****
  • winpe enthusiast
  • Location: UK
  • Date Registered: Nov 2012
  • Posts: 1150
Hi Guys

trying to follow this thread, hard enough as it is, can I just clarify
are
cmdwarper.exe
cmdwarpper.exe
cmdwapper.exe

typo's for
cmdWrapper.exe

Re: something about batch syntax and cmd.exe
« Reply #13 on: December 16, 2018, 12:57:48 PM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Hi, APT
Thanks to notice it. fixed the typo.

cmdWrapper.exe is not real command now, the name doesn't matter.

Quote
Aoccdrnig to rscheearch at Cmabrigde uinervtisy, it deosn’t mttaer waht oredr the ltteers in a wrod are,
the olny iprmoetnt tihng is taht the frist and lsat ltteres are at the rghit pclae. The rset can be a tatol mses
and you can sitll raed it wouthit a porbelm. Tihs is bcuseae we do not raed ervey lteter by it slef but the wrod as a wlohe.
:lol:
« Last Edit: December 16, 2018, 01:07:05 PM by slore »

Re: something about batch syntax and cmd.exe
« Reply #14 on: December 16, 2018, 01:23:57 PM »

Lancelot

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

Summary is:
I thought there should be a syntax on cmd I miss to workaround failure with cmd Autorun feature and decide to ask slore.
(which I thought It will  be solved with first slore reply)

It turns out to be an undocumented behavior.
(
Documented behavior for only backquoted commands but without re warning about registry cmd Autorun usage can cause token failure,
 See sandy reply 15 http://theoven.org/index.php?topic=2669.msg29953#msg29953
Same behavior also exists with normal quoted commands
 See Lancelot reply 17 http://theoven.org/index.php?topic=2669.msg29955#msg29955
)

(even no warning at the great  :worship: robvanderwoude pages https://www.robvanderwoude.com/ntfortokens.php)

cmd.exe has a bad "thing" with For /F In
to test use this:

Code: [Select]
For /F %%A In ( 'pause' ) Do Rem Test

check with Process Explorer.... you will notice 2nd.  cmd.exe under first cmd.exe which use "cmd.exe /c"

=>
It seems cmd.exe developers forget to add /d -> cmd.exe /c --> cmd.exe /c /d

*
Better say cmd.exe developers did:
hiderun.exe /wait cmd.exe /c

http://theoven.org/index.php?topic=2040.0

hiderun.exe codes embedded inside For /F ( ' .... ' )


=>
This cause failure on some cases where one use tokens and or delims with windows having a registry autorun entry
See Registry at Lancelot reply inside quote: http://theoven.org/index.php?topic=2669.msg29912#msg29912



****
Further is about how to workaround.
slore provide nice workarounds with Way1 Way2 Way3 Way3.5

Way1 using temp file with Type (when Type used... see See Lancelot reply inside quote: http://theoven.org/index.php?topic=2669.msg29912#msg29912 )
Way2 Way3 Way3.5 : slore reply 5 http://theoven.org/index.php?topic=2669.msg29916#msg29916

Way1:
Temp file ...  to get .cmd out of box and standalone It is always better to avoid Temp file where possible....

Way2:
Advantage:
It will work out of the box for everybody, but It is bad on development...
Good for small cmd files when you distribute on the net, bad for developing big cmd files, bad for human readability.

Way3:
Advantage:
All cmd examples you see on the internet or you prepare will work out of the box as expected to avoid Autorun Effect
Request: cmd patch or cmdWrapper.exe

I believe Way3 good for WimBuilderUI

I will probably have a mixed usage, on some cases Way2 on other cases Way3.


@slore
It seems Update_with_zip.cmd on my previous post is an old version. (without %1 etc.)
I will prepare another one and post....
Edit: I am sure you already figure out what I mean with above .cmd  :wink:

:turtle:
« Last Edit: December 16, 2018, 03:38:27 PM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #15 on: December 16, 2018, 02:12:21 PM »

sandy

  • Jr. Chef
  • **
  • Date Registered: Oct 2018
  • Posts: 49
Microsoft does document that a child cmd is called. See:

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/for

Parsing output

You can use the for /f command to parse the output of a command by placing a back-quoted <command> between the parentheses. It is treated as a command line, which is passed to a child Cmd.exe. The output is captured into memory and parsed as if it is a file.

Re: something about batch syntax and cmd.exe
« Reply #16 on: December 16, 2018, 02:29:52 PM »

Lancelot

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

updated my previous post.  :xmas-beer:

I still believe It is a bad design of cmd.exe executing a 2nd hidden cmd.exe.......  :wink:
At least they could create child cmd.exe following current cmd.exe instead of executing new one.......
Or better, parse hidden output without creating a 2nd hidden cmd.exe...

Remind me "Some People" complain me about too much .exe header cause build slow down in very past.....

Anyway, It is what it is....

There should be always a reminder (warning) on documents where For with Tokens used
 having back-quoted <command> may cause failure with registry Autorun....    :whistling:

:turtle:

Re: something about batch syntax and cmd.exe
« Reply #17 on: December 16, 2018, 03:34:59 PM »

Lancelot

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

a little thing I notice:

Code: [Select]
For /F %%A In ( 'pause' ) Do Rem Test

Defination at ms is a bit wrong, this thing is not limited to "back-quoted <command>"
above is an example with normal quoted <command>
following is an example with back quoted <command>
Code: [Select]
For /f usebackq %%A In ( `Pause` ) Do Rem Test


Summary:
1) All commands with For creates child cmd.exe process.
2) Back quoted or not, do not change the result
3) There is no way to control the behavior of child cmd.exe process, It always use "cmd.exe /c" + hidden.
(3) -> If we could control the behavior of child cmd.exe process, we could add /d and solve autorun trouble)

**
Sorry today (Sunday) become my house cleaning day, I come and go to computer....

ps:

another idea maybe using cls to clean token(s) that come from Registry Autorun but I could not:
Here are my failures:
For /f %%A In ( 'cmd.exe /D /C cls ^| Echo Test' ) Do Echo Result: "%%A"
For /f %%A In ( 'cls ^| Echo Test' ) Do Echo Result: "%%A"
I can not use & inside single quote:
For /f %%A In ( 'cls&Echo Test' ) Do Echo Result: "%%A"
For /f %%A In ( 'cls&&Echo Test' ) Do Echo Result: "%%A"
For /f %%A In ( 'cls&&&Echo Test' ) Do Echo Result: "%%A"
For /f %%A In ( 'cls&&&&Echo Test' ) Do Echo Result: "%%A"
For /f usebackq %%A In ( `cls&Echo Test` ) Do Rem Test
For /f usebackq %%A In ( `cls&&Echo Test` ) Do Rem Test
For /f usebackq %%A In ( `cls&&&Echo Test` ) Do Rem Test


Back to house cleaning.... :turtle:


Edit:
Using cls Bad idea
For /f start capturing immediately whatever inside....
eg.
For /f %%A In ( 'cls' ) Do Echo "%%A"

**
cls may have an interesting feature to transfer what is inside 2nd cmd window to 1st window:
eg.
Start "" cmd.exe /c cls&echo test
-->
This get Echo test on first cmd window


Start "" cmd.exe /c echo test
-->
This get Echo test on second window

very similar with For /F command only difference 2nd cmd.exe not hidden (popup)

Or maybe I made a mistake again, only drinking coffee with a house clean break.  :cool:
« Last Edit: December 16, 2018, 06:22:46 PM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #18 on: December 17, 2018, 07:31:36 AM »

Lancelot

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

just updated cmd at
Lancelot Reply 11: http://TheOven.org/index.php?topic=2669.msg29944#msg29944

Requires more work to get it more tidy (I am new on cmd world)
It is just a begining, I tested with none space folder and file with a set of combinations, all worked fine so far...

+
cmd will give you information what "Utils\Update XXX Exact and Secure" do. Step order is same.
+
And I hope will give you a quick way to update packed project and easier to follow updates after pack.

:turtle:
« Last Edit: December 17, 2018, 07:40:20 AM by Lancelot »

Re: something about batch syntax and cmd.exe
« Reply #19 on: December 17, 2018, 03:07:52 PM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
Quote
just updated cmd at
Lancelot Reply 11

I tested it, and it just remove Temp dirs, and use 7z extract the file.

Update_with_zip.cmd OLD_PESE.zip  :confused:
I didn't see any DOWNLOAD action... how do it update?  :confused:

as you Updated Win10PE_SE_2018-12-16 - ZIP and Project servers, I downloaded with my smartphone in 5 minutes. this is good to me.

 

Powered by EzPortal