Jump to content











Photo
- - - - -

Please help me to go ahead ?

cmd winpe boot.wim usb booting multibooting

  • Please log in to reply
146 replies to this topic

#51 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 July 2017 - 09:15 AM

Can we set two variable (Partition and Removable) containing Drive Letters in order of Volume Number with status 'Healthy' ?
 
    Partition :  C H F G D I J     ->>  MostFreePart : I
Removable :  K E L                  ->> MostFreeRem : E
 
Then we can get %MostFreePartMB% out of %Partition% and %MostFreeRemMB% out of %Removable% ?

Why not?

The issue might be the volume(s) which is/are "Healthy" AND "NTFS" BUT do not have a drive letter assigned.
I guess we can use "fixed size fields" instead of tokens and delims. :unsure:
 

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET Removable=
SET Partition=

FOR /F "tokens=*" %%A IN ('ECHO LIST VOLUME ^| DISKPART ^|FIND "Healthy" ^|FIND "NTFS"') DO CALL :parse_volumes %%A

SET Removable
SET Partition
GOTO :EOF

:parse_volumes
SET Line=%*
IF NOT "%Line:~13,1%"==" " SET %Line:~37,9%=!%Line:~37,9%! %Line:~13,1%:
GOTO :EOF

:duff:

Wonko


  • devdevadev likes this

#52 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 26 July 2017 - 10:56 AM

Here's a slightly different approach.

What do you think about this one?

 

Tries to overcome localisation issues.

Expression "NTFS" as well as "Partition" should stay the same.?

Drives are sorted by drive letter.

For German locale Healthy is "Fehlerfrei"

One possible "disadvantage" is usage of findstr instead of find.

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

SET "Searchmask=Fehlerfr Healthy"
FOR /F "tokens=3* delims= " %%a IN ('ECHO LIST VOL^|DISKPART^|SORT /+12 ^|FINDSTR /I "%Searchmask%"^|FIND "NTFS"') DO (
SET V=%%a& IF "!V:~2,1!"=="" (ECHO "%%b"|FIND "Part" 1>NUL&& SET _Partition=!_Partition! %%a||SET "_Removable=!_Removable! %%a"))
SET _Partition=%_Partition:* =%
SET _Removable=%_Removable:* =%
pause

If you try to avoid findstr you've to enter the localised expressions:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

FOR /F "tokens=3* delims= " %%a IN ('ECHO LIST VOL^|DISKPART^|SORT /+12 ^|FINDSTR /I "Healthy"^|FIND "NTFS"') DO (
SET V=%%a& IF "!V:~2,1!"=="" (ECHO "%%b"|FIND "Part" 1>NUL&& SET _Partition=!_Partition! %%a||SET "_Removable=!_Removable! %%a"))
SET _Partition=%_Partition:* =%
SET _Removable=%_Removable:* =%
pause


#53 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 July 2017 - 12:56 PM

I don't know, in Italian "Healthy" is "Integro", it is not much handy to avoid the localization by adding each and every language.

And no, Italian "Partition" is "Partizione" and "Removable" is "Removibile".

It is more likely (but it should be checked) that the fields are "fixed length". in all languages (because after all the 80 columns are a "fixed" default).

Even the (nice idea BTW) of |SORT /+12 somehow assumes that the first token is less than 12 chars (which is plausible, but not necessarily "given").

The only "fixed" string is probably "NTFS" in all languages, and possibly "Volume" :unsure:.

I am not sure to understand the IF "!V:~2,1!"=="" :dubbio:

:duff:
Wonko

#54 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 26 July 2017 - 01:49 PM

Let me try to explain.
Starting at token 3 gets you started with the drive letter inside the column view.
But, assume a drive has two partition from which one is hidden.
In this case the starting token (here token 3=drive letter) becomes the entry of the next column in the column view of diskpart (an alpha-numeric Label string).
The logic for "IF "!V:~2,1!"==" is, that a token which is not longer than one char must be the drive letter.
I know, this must not be generally true but it is really uncertain that someone labels a volume (hidden or not) with only one char.

About sorting:
I may be wrong, but I'm really sure that the starting position of the drive letter won't change in the column view.
The first entry should always be "Volume" followed by a space and the VolNr (8-9 chars using space padding x1 on the RHS of VolNr.).

A fixed space is following.
Then the drive letters are shown (spacepadding x1 LHS and RHS from the drive letter).
Therefore the driveletter should always be at Pos 12.

About localisation in general.
It's a real pain to take care about this. Thank you for your clarifications.
I wonder if the used short-form in my code ("Part" for the engl. expression "Partition") should do the trick in general.
BTW, a removable drive in German is labeled as "Wechseldatenträger" whereas an internal drive is labeled as "Partition".
If so, we only need the localised expression for engl. "Healthy"

The whole thing grows even harder if you use the FSUTIL FSINFO DRIVETYPE command (avail. under XP also).
An internal disk is labeld there as "Eingebautes Laufwerk" whereas a removable disk is "Austauschbares Laufwerk".
Anyway, most interesting issues here that are worth to play with.
 



#55 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 July 2017 - 02:43 PM

Well this is still not "correct" IMHO:  IF "!V:~2,1!"=="", as well as the "FIND "Part" (and you are also assuming that at least one volume is "Removable").

 

They are only partial solutions, you need an "act of faith" that a number of possibilities do not happen  

 

I mean ;) :

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

SET Line1=Volume 0 C  My label NTFS Partition
SET Line2=Volume 1 D  Another label NTFS Partition
SET LIne3=Volume 2 E  NTFS Partition
SET Line4=Volume 3  NTFS Partition
SET Line5=Volume 4  A different label NTFS Partition
SET Line6=Volume 5 X  Yet another NTFS Partition
SET Line7=Volume 6 F  Ext Part NTFS Removable
SET Line8=Volume 7 G  Parthenon NTFS Removable

FOR /F "tokens=4* delims== " %%a IN ('SET Line') DO (
SET V=%%a
IF "!V:~2,1!"=="" (
ECHO "%%b"|FIND "Part" 1>NUL&& SET _Partition=!_Partition! %%a||SET "_Removable=!_Removable! %%a"
)
)
SET _Partition=%_Partition:* =%
SET _Removable=%_Removable:* =%
SET _

This one is "better" (as it considers a double space after the - probable - drive letter) still it is slow as it cycles through possible letters. :(

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET Line1=Volume 0 C  My label NTFS Partition
SET Line2=Volume 1 D  Another label NTFS Partition
SET LIne3=Volume 2 E  NTFS Partition
SET Line4=Volume 3  NTFS Partition
SET Line5=Volume 4  A different label NTFS Partition
SET Line6=Volume 5 X  Yet another NTFS Partition
SET Line7=Volume 6 F  Ext Part NTFS Removable
SET Line8=Volume 7 G  Parthenon NTFS Removable

FOR /F "tokens=3* delims== " %%A IN ('SET Line') DO (
CALL :parse_volumes %%A %%B
)



SET my_

GOTO :EOF

:parse_volumes
SET Line=%*
FOR %%C IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
SET Line=!Line: %%C  = %%C: !
)
ECHO %Line%|FIND ":"&& CALL :parse_dl %Line%

GOTO :EOF

:parse_dl
SET ThisDL=%2
:loop_NTFS
IF NOT "%1"=="NTFS" SHIFT&&GOTO :loop_NTFS
SET VarName=my_%2
SET %VarName%=!%VarName%! %ThisDL%
GOTO :EOF

:duff:

Wonko



#56 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 26 July 2017 - 02:50 PM

Wonko,

I suppose you're right with the fixed length assumption.

Output of this diskpart command in German is truncated.

This is true for the last and forelast column in German locale.

OS: Win10Pro v.1703.

Forelast column: "Fehlerfrei" becomes "Fehlerfre"

Last column: "Versteckt" becomes "Versteck" and  "Startpartition" becomes "Startpar".



#57 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 26 July 2017 - 02:58 PM

What in particular is not correct? Sorry I can't follow.



#58 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 26 July 2017 - 04:09 PM

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

CALL :START_BACKUP
PAUSE
EXIT

:START_BACKUP
SET USER=
SET USERDIR=
FOR /F %%A IN ('DIR "C:\Users\" /B 2^>nul') DO (
if /i not "%%A"=="Public" FOR /F %%B IN ('DIR "C:\Users\%%A\" /B 2^>nul ^|FIND /I "Desktop" ') DO (
IF EXIST "C:\Users\%%A\Desktop" (
SET USER=%%A& SET USERDIR=C:\Users\%%A
ECHO USER is !USER! and USER DIRECTORY is !USERDIR!
CALL :BACKUP_SIZE
SET BACKUP_SIZE
ECHO %BACKUP_SIZE%
ECHO !BACKUP_SIZE!
)
)
)
GOTO :EOF

:BACKUP_SIZE
SET BACKUP_SIZE=
FOR /F "tokens=1 delims=. " %%A in ('DIRUSE /M "%USERDIR%\Music" "%USERDIR%\Videos" "%USERDIR%\Desktop" "%USERDIR%\Documents" "%USERDIR%\Downloads"') DO SET BACKUP_SIZE=%%A
ECHO ACTUAL BACKUP SIZE=%BACKUP_SIZE% MB
SET /a BACKUP_SIZE+=1024
ECHO ESTIMATED BACKUP SIZE=%BACKUP_SIZE% MB
GOTO :EOF
Why following command is not running in above batch file ?
ECHO %BACKUP_SIZE%
while following command work ?
ECHO !BACKUP_SIZE!
Does %VARIABLE% not work within FOR Loops ?
 
OUTPUT -
USER is Anand and USER DIRECTORY is C:\Users\Anand
ACTUAL BACKUP SIZE=245 MB
ESTIMATED BACKUP SIZE=1269 MB
BACKUP_SIZE=1269
ECHO is off.
1269
USER is Kdeva and USER DIRECTORY is C:\Users\Kdeva
ACTUAL BACKUP SIZE=16059 MB
ESTIMATED BACKUP SIZE=17083 MB
BACKUP_SIZE=17083
ECHO is off.
17083
Press any key to continue . . .

Am I doing something wrong ? Please explain about this ODD behavior of %VARIABLE% ....How !Variable! is different from %Variable% ?



#59 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 July 2017 - 04:58 PM

@devdevadev
No, it is the "normal" behaviour, by design, go study a little bit about DELAYEDEXPANSION, like here:
https://ss64.com/nt/...dexpansion.html
https://ss64.org/viewtopic.php?id=985
 
 
@zharif
Try running the two sample batches I posted on #55 (first one is basically  "your" one) they both come with some "embedded" rigorously "fake" DISKPART output:
http://reboot.pro/to...e-3#entry204275
 
On XP I get (respectively):

_Partition=C D E A X F G
_Removable=* =
and:

0 C: My label NTFS Partition
1 D: Another label NTFS Partition
2 E: NTFS Partition
5 X: Yet another NTFS Partition
6 F: Ext Part NTFS Removable
7 G: Parthenon NTFS Removable
my_Partition= C: D: E: X:
my_Removable= F: G:
One of the two (guess which one ;)) seemingly doesn't work as expected :whistling:.
 
BTW of course I am playing Devil's Advocate, using specially crafted "edge cases", but in the immortal words of Douglas Adams:
https://www.brainyqu...sada109728.html 
 

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.


:duff:
Wonko

P.S.: BTW - as a side note only - "Forelast" in English is seemingly "Penultimate":
https://forum.wordre...relast.2742722/

#60 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 27 July 2017 - 03:39 AM

Thanks 'Wonko' for your great help and support...Now 'Backup_New.cmd'  works as per requirements...But why I have to 'Run as Admin' ? while in previous script *(where we was using fsutil) is working without running as admin ? AFAIK, DISKPART is a native tool ? Then why it require 'Run as Admin ?

 

Backup_New.cmd-

@echo off
pushd "%~dp0"
setlocal EnableDelayedExpansion

set SYSPART=
set SYSPART1=
FOR %%w IN (C D E F G H I J K L N M O P Q R S T U V W Y Z) DO (
if not defined SYSPART IF EXIST %%w:\Windows\explorer.exe set SYSPART=%%w:
if defined SYSPART IF EXIST %%w:\Windows\explorer.exe set SYSPART1=%%w:
)
set DATETIME=%DATE:~7,2%-%DATE:~4,2%-%DATE:~-4%_%TIME:~0,2%-%TIME:~3,2%-%TIME:~6,2%
set DATETIME=%DATETIME: =0%

CALL :START_BACKUP
PAUSE
EXIT

:START_BACKUP
SET USER=
SET USERDIR=
FOR /F %%A IN ('DIR "%SYSPART%\Users\" /B 2^>nul') DO (
if /i not "%%A"=="Public" FOR /F %%B IN ('DIR "%SYSPART%\Users\%%A\" /B 2^>nul ^|FIND /I "Desktop" ') DO (
IF EXIST "%SYSPART%\Users\%%A\Desktop" (
SET USER=%%A& SET USERDIR=%SYSPART%\Users\%%A
ECHO USER is !USER! and USER DIRECTORY is !USERDIR!
CALL :BACKUP_SIZE
CALL :FREEDRIVE
)
)
)
ECHO SMART BACKUP HAS BEEN DONE !!!
GOTO :EOF

:BACKUP_SIZE
SET BACKUP_SIZE=
FOR /F "tokens=1 delims=. " %%A in ('DIRUSE /M "%USERDIR%\Music" "%USERDIR%\Videos" "%USERDIR%\Desktop" "%USERDIR%\Documents" "%USERDIR%\Downloads"') DO SET BACKUP_SIZE=%%A
ECHO ACTUAL BACKUP SIZE=%BACKUP_SIZE% MB
SET /a BACKUP_SIZE+=1024
ECHO ESTIMATED BACKUP SIZE=%BACKUP_SIZE% MB
GOTO :EOF

:FREEDRIVE
SET Partition=
SET Removable=
FOR /F "tokens=*" %%A IN ('ECHO LIST VOLUME ^| DISKPART ^|FIND "Healthy" ^|FIND "NTFS"') DO CALL :parse_volumes %%A
SET EXCLUDEDRIVES=%SYSPART%  %SYSPART11% %SystemDrive%
FOR %%A in (%EXCLUDEDRIVES%) DO SET Partition=!Partition:%%A =!
SET Partition
SET Removable

FOR %%A IN (%Partition% %Removable%) DO (
FOR /F "skip=2 tokens=2 delims=:" %%B IN ('fsutil volume diskfree %%A') DO (
ECHO %%A %%B
SET Vol_%%A=%%B
)
)

FOR %%A IN (%Partition%) DO CALL :Sort_Pval %%A !VOL_%%A!
FOR /F "tokens=2 Delims==" %%A IN ('SET PFree_') DO SET MostFreePart=%%A
SET MostFreePartMB=!VOL_%MostFreePart%!
SET MostFreePartMB=%MostFreePartMB: =%
SET MostFreePartMB=%MostFreePartMB:~0,-6%
SET MostFreePart

FOR %%A IN (%Removable%) DO CALL :Sort_Rval %%A !VOL_%%A!
FOR /F "tokens=2 Delims==" %%A IN ('SET RFree_') DO SET MostFreeRem=%%A
SET MostFreeRemMB=!VOL_%MostFreeRem%!
SET MostFreeRemMB=%MostFreeRemMB: =%
SET MostFreeRemMB=%MostFreeRemMB:~0,-6%
SET MostFreeRem

IF %MostFreePartMB% GEQ %BACKUP_SIZE% (
SET FREEDRIVE=%MostFreePart%
) ELSE (
IF %MostFreeRemMB% GEQ %BACKUP_SIZE%  (
SET FREEDRIVE=%MostFreeRem%
)
)
IF DEFINED FREEDRIVE (GOTO :DO_BACKUP) ELSE (Explorer ,)
GOTO :EOF

:Sort_Pval
SET Num=0000000000000%2
SET Num=%Num:~-14,14%
SET PFree_%Num%=%1
GOTO :EOF 

:Sort_Rval
SET Num=0000000000000%2
SET Num=%Num:~-14,14%
SET RFree_%Num%=%1
GOTO :EOF

:parse_volumes
SET Line=%*
IF NOT "%Line:~13,1%"==" " SET %Line:~37,9%=!%Line:~37,9%! %Line:~13,1%:
GOTO :EOF

:DO_BACKUP
ECHO BACKUP DRIVE is %FREEDRIVE%
mkdir "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%" & Explorer.exe "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%"
robocopy "%USERDIR%\Music" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Music" /E /MT:1
robocopy "%USERDIR%\Videos" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Videos" /E /MT:1
robocopy "%USERDIR%\Desktop" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Desktop" /E /MT:1
robocopy "%USERDIR%\Pictures" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Pictures" /E /MT:1
robocopy "%USERDIR%\Documents" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Documents" /E /MT:1
robocopy "%USERDIR%\Downloads" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Downloads" /E /MT:1
GOTO :EOF

Does above script require any fixes or Improvements ? Am I still using any wrong procedures ?



#61 paraglider

paraglider

    Gold Member

  • .script developer
  • 1716 posts
  • Location:NC,USA
  •  
    United States

Posted 27 July 2017 - 08:50 AM

MS marks diskpart as requiring elevation ( run as administrator ). It does things that quite reasonably require an administrator - mount drives / change / assign drive letters / format drives etc.



#62 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 27 July 2017 - 12:36 PM

Wonko, a good demonstration.
I'm able to face the problem without running your scripts.
It didn't come into my mind that someone would add spaces and/or the word Partition/Part into the volume label.
Thanks for pointing this out.

In the meanwhile (no access to this forum due to a long lasting internal server error 500), I tried the fixed length approach of max 80 chars.
I fiddled around with each column width (in chars) to get max. CharLen.
As far as I've seen in the forum these do not change.?

Script has been tested under XP, 7 and 10.
Localised strings must be set prior here.
BTW, the diskpart INFO column differs between XP and 7 (upwards).
For me, in German XPPro SP3 it's not "Fehlerfrei/Healthy" but simply "OK". :-(
In hope I didn't miss something I'm still awaiting your appreciated comments.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
NET FILE >NUL 2>&1  || ECHO Command prompt does not run elevated ...exit here&&PAUSE>NUL&&GOTO:_End

VER|FIND " XP " 1>NUL && SET "SMask=OK"||SET "SMask=Fehlerfr"
SET "FSMask=NTFS"
SET "TMask=Part"

FOR /F "tokens=* delims=  " %%a IN ('ECHO LIST VOL^|DISKPART^|SORT /+15') DO (
  SET "Line=%%a" & SET "Name=!Line:~14,3!" & SET "FSys=!Line:~32,5!" & SET "Type=!Line:~39,10!" & SET "Stat=!Line:~60,9!"
  CALL :Test "!STAT!" "!TYPE!" "!FSYS!" "!Name!"
)
SET _

:_End
cmd /k&exit

:test
SET "S=%~1" & SET "T=%~2"
SET "F=%~3" & SET "N=%~4"
SET "N=%N: =%"

SET VAR=& ECHO "%S%"|FIND "%SMASK%" 1>NUL && ECHO "%F%"|FIND "%FSMask%" 1>NUL && SET "Var=1"
IF DEFINED VAR echo "%T%"|FIND "%TMask%" 1>NUL && SET _Vol%FSMask%=!_Vol%FSMask%! %N%||SET "_Vol%FSMask%Rem=!_Vol%FSMask%Rem! %N%"
IF "!_Vol%FSMask%:~0,1!"==" " SET "_Vol%FSMask%=!_Vol%FSMask%: =!"
IF "!_Vol%FSMask%Rem:~0,1!"==" " SET "_Vol%FSMask%Rem=!_Vol%FSMask%Rem: =!"
GOTO:EOF



#63 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 27 July 2017 - 01:08 PM

if %MostFreePartMB% GEQ %BACKUP_SIZE% set FREEDRIVE=%MostFreePart%& GOTO :DO_BACKUPif %MostFreeRemMB% GEQ %BACKUP_SIZE% set FREEDRIVE=%MostFreeRem%& GOTO :DO_BACKUP else Explorer ,
Hmmm.

https://ss64.com/nt/if.html

I doubt that the "else" will ever be executed.

@zharif
It seems to me like the possibly most "neutral" way is to count the -'s.
I.e.:



---------1---------2---------3---------4---------5---------6---------7---------8
12345678901234567890123456789012345678901234567890123456789012345678901234567890
  Volume n.  Lett. Etichetta    Fs     Tipo        Dim.     Stato      Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------

So, we can have fields *like*:
 

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET /A Field=0
SET /A ProgrOffset=0
FOR /F "skip=7 tokens=* delims=" %%A IN ('ECHO LIST VOLUME^|DISKPART') DO SET TitleLine=%%A&&GOTO :OutOfFor
:OutOfFor
FOR /F "tokens=* delims=" %%A IN ('ECHO LIST VOLUME^|DISKPART^|FIND "---------"') DO CALL :parse_hyphens %%A
GOTO :EOF

:parse_hyphens
SET /A Field+=1

SET /A ProgrOffset+=2

SET Field_%Field%=%1

FOR /L %%B IN (12,-1,1) DO (
SET string=!Field_%Field%:~0,%%B!
IF !String!==!Field_%Field%! SET /A Length_%Field%=%%B
)


SET /A Offset_%Field%=%ProgrOffset%
SET /A ProgrOffset=%ProgrOffset%+!Length_%Field%!

SET Params=!Offset_%Field%!,!Length_%Field%!
SET Field_%Field%=!TitleLine:~%Params%!
SET Field_%Field%
SET Offset_%Field%
SET Length_%Field%
ECHO.
IF NOT "%2"=="" SHIFT&&GOTO :parse_hyphens

GOTO :EOF

Field #2 title is "off" since title is longer than hyphens...



:duff:
Wonko



#64 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 27 July 2017 - 01:43 PM

I doubt that the "else" will ever be executed.

is it correct ?

IF %MostFreePartMB% GEQ %BACKUP_SIZE% SET FREEDRIVE=%MostFreePart%& GOTO :DO_BACKUP
IF %MostFreeRemMB% GEQ %BACKUP_SIZE% SET FREEDRIVE=%MostFreeRem%& GOTO :DO_BACKUP
IF NOT DEFINED FREEDRIVE Explorer ,

Any other ways to do the same thing ?



#65 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 27 July 2017 - 02:09 PM

MS marks diskpart as requiring elevation ( run as administrator ). It does things that quite reasonably require an administrator - mount drives / change / assign drive letters / format drives etc.

 

startnet.cmd -

x:\windows\system32\mysetup.cmd

mysetup.cmd -

start x:\support\InstallWhim_x86.exe
cmd /q /c  "FOR %%i IN (C D E F G H I J K L N M O P Q R S T U V W X Y Z) DO IF EXIST %%i:\_ISO\WINDOWS\INSTALLS\CONFIGS\SMART_AUTO.cmd  cmd /k %%i:\_ISO\WINDOWS\INSTALLS\CONFIGS\SMART_AUTO.cmd"

I will CALL Backup_New.cmd within 'SMART_AUTO.cmd'. And Backup_New.cmd uses DISKPART commands. So what should I do so that it will automatically Run as Admin ?



#66 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 27 July 2017 - 02:48 PM

devdevadev,

 

you could use an external tool (search for elevate.exe) to run your batch with.

Or use a vbs-script via code inside our batch.

Look here: https://ss64.com/vb/...ax-elevate.html



#67 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 27 July 2017 - 03:19 PM

@zharif

Sorry didn't notice new posts, edited previous one with a suggested aproach.

 

@devdevadev

I actually gave you a reference from which you should have gathered the use of parenthesis or brackets in

IF condition (do something) ELSE (do something else)

 

One among the n possible ways:

 

IF %MostFreePartMB% GEQ %BACKUP_SIZE% (

SET FREEDRIVE=%MostFreePart%

) ELSE (
IF %MostFreeRemMB% GEQ %BACKUP_SIZE%  (

SET FREEDRIVE=%MostFreeRem%

)

)

IF DEFINED FREEDRIVE (GOTO :DO_BACKUP) ELSE (Explorer) ,

 

:duff:

Wonko



#68 cdob

cdob

    Gold Member

  • Expert
  • 1344 posts

Posted 27 July 2017 - 08:57 PM

startnet.cmd

So what should I do so that it will automatically Run as Admin ?

Do you intend to use this at running PE, automatically launched by startnet.cmd?

Then you use proper credentials by default, diskpart will run out of the box.
No need to configure this.

But the robocopy part may fail, because of low credentials: files can't be read.
Local NTFS security settings may interfere. Do a lot of testings.

#69 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 27 July 2017 - 09:13 PM

Do you intend to use this at running PE, automatically launched by startnet.cmd?

I will use 'startnet.cmd' in ChrisR Win10PESE which will autorun 'mysetup.cmd' and it will further autorun 'PTN2:\_ISO\WINDOWS\INSTALLS\CONFIGS\SMART_AUTO.cmd . And 'SMART_AUTO.cmd' will call 'SMART_BACKUP.cmd'. 

 

Should I use any other copy tool instead of 'robocopy' in Win10PESE ? Which is best and native copy tool which I use in Win10PESE project ?

 

Do you have any IDEA how I can add 'High Contrast Black' theme in Win10PESE as default theme ?



#70 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 28 July 2017 - 08:10 AM

@zharif

A slighltly enhanced batch, now it should parse correctly names of the fields, even if they are slightly longer than the number of hyphens.

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET /A Field=0
SET /A ProgrOffset=0
ECHO ---------1---------2---------3---------4---------5---------6---------7---------8
ECHO 12345678901234567890123456789012345678901234567890123456789012345678901234567890
FOR /F "skip=7 tokens=* delims=" %%A IN ('ECHO LIST VOLUME^|DISKPART') DO SET TitleLine=%%A&&GOTO :OutOfFor
:OutOfFor
ECHO %TitleLine%
FOR /F "tokens=* delims=" %%A IN ('ECHO LIST VOLUME^|DISKPART^|FIND "---------"') DO ECHO %%A&&CALL :parse_hyphens %%A
GOTO :EOF

:parse_hyphens
SET /A Field+=1

SET /A ProgrOffset+=2

SET Field_%Field%=%1

FOR /L %%B IN (12,-1,1) DO (
SET string=!Field_%Field%:~0,%%B!
IF !String!==!Field_%Field%! SET /A Length_%Field%=%%B
)


SET /A Offset_%Field%=%ProgrOffset%
SET /A ProgrOffset=%ProgrOffset%+!Length_%Field%!

SET /A Title_Offset=!Offset_%Field%!-1
SET /A Title_Length=!Length_%Field%!+2
SET Field_%Field%=§!TitleLine:~%Title_Offset%,%Title_Length%!§

::Trim excess spaces
SET Field_%Field%=!Field_%Field%:    §=§!
SET Field_%Field%=!Field_%Field%:   §=§!
SET Field_%Field%=!Field_%Field%:  §=§!
SET Field_%Field%=!Field_%Field%: §=§!
SET Field_%Field%=!Field_%Field%:§ =!
SET Field_%Field%=!Field_%Field%:§=!

SET Field_%Field%
SET Offset_%Field%
SET Length_%Field%
ECHO.
IF NOT "%2"=="" SHIFT&&GOTO :parse_hyphens

GOTO :EOF

:duff:

Wonko



#71 paraglider

paraglider

    Gold Member

  • .script developer
  • 1716 posts
  • Location:NC,USA
  •  
    United States

Posted 28 July 2017 - 08:14 AM

As you are limiting yourself to specific user folders then you should not have issues with permissions. All tools that use normal win32 api will potentially have the same problems if for example you changed file permissions on your user folders such that only the original user only had access. By default system and any user who is a member of the administrators group will have access to the user folders. You can use tools like accessgain to bypass NTFS file permissions or you can use low level tools that work at the driver level to access protected files.



#72 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 28 July 2017 - 10:31 AM

As you are limiting yourself to specific user folders then you should not have issues with permissions. All tools that use normal win32 api will potentially have the same problems if for example you changed file permissions on your user folders such that only the original user only had access. By default system and any user who is a member of the administrators group will have access to the user folders. You can use tools like accessgain to bypass NTFS file permissions or you can use low level tools that work at the driver level to access protected files.

So, from a PE, where the user is "System" there should be no issues unless those specific folders  permissions were changed from default, right? :unsure:

 

:duff:

Wonko



#73 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 28 July 2017 - 02:54 PM

Hmmm.

Post #60 script does not seems to work and exit in between if there is no Removable USB Drive connected. What code I should add so that script will run even if there is no Removable USB is connected in the WinPE at the moment when 'SMART_AUTO.cmd' is calling 'Backup_New.cmd' ? Currently It just exit if no Removable USB is connected ?

IF %MostFreePartMB% GEQ %BACKUP_SIZE% (
SET FREEDRIVE=%MostFreePart%
) ELSE (
IF %MostFreeRemMB% GEQ %BACKUP_SIZE%  (
SET FREEDRIVE=%MostFreeRem%
)
)
IF DEFINED FREEDRIVE (GOTO :DO_BACKUP) ELSE (Explorer) ,

It's looking above code causes to terminate the script if NO Removable USB is not connected ? How we can manage so that script will run even if there is no Removable USB connected ?



#74 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 28 July 2017 - 05:43 PM

Maybe (I didn't check) MostFreeRemMB  (and MostFreeRem) are not defined.

 

A good idea (always) is to initialize variables, particularly those that will be assigned a value ONLY if a given condition/scenario is true and whose values are used to change the program flow. .

 

I.e., before actually comparing with %BACKUP_SIZE%, add:

IF NOT DEFINED MostFreePartMB SET /A MostFreePartMB=0

IF NOT DEFINED MostFreeRemMB SET /A MostFreeRemMB=0

 

:duff:

Wonko



#75 Zharif

Zharif

    Frequent Member

  • .script developer
  • 153 posts
  • Location:Germany
  •  
    Germany

Posted 28 July 2017 - 08:48 PM

Wonko,
very good code in my opinion (if m opinion is worth to mention).
I so often wonder from where you get your ideas for starting points  -this is a brilliant approach, from the beginning up to the end.
What you did is determining first what my code uses as hypothesis (CharLens and distances).
I manually counted and hardcoded the hyphen length and "distances" between them, assumed that they will be right and did the actual task.

Your code output exactly confirms my "calculations" for the diskpart output.
At least this means that for Italian and German language the HyphenLen (or offset and len of a column in chars) of diskpart is the same.
Due to devdevadevs' post (post 50) I would say we can add the English output too.

Question: are these results are generalisable?
Probably "Yes" for European WinOS'es. But what about e.g. Eastern locales?
At least we don't know (although I tend to think they are).

 

It would be really clarifying if somebody here could post/confirm the following
Starting offsets and length for each of the following "columns" by executing your batch:
VolumeNr=2,10
DrvLetter=14,3
Label=19,11
FileSystem32,5
Type=39,10
Size=51,7
Status=60,9
Info=71,8

Until these values couldn't be confirmed from some special foreign locales there's
need to run your code example first before running any further code.


What I don't understand is why your code takes care about the column headers text. I don't see any interesting part in them.
At least you execute diskpart twice that slows down execution speed dramatically
(In my tests, particulary when you run the batch file the first time- before caching comes into play).
Not to mention that diskpart has to be executed a third time to do the real task of getting the filtered drive letters (as done in my code).
Aren't are the hyphens that count to get offset and len? Why not omitting the first loop of your code?

Means, starting with:
FOR /F "tokens=* delims=" %%A IN ('ECHO LIST VOLUME^|DISKPART^|FIND "---------"') DO ECHO %%A&&CALL :parse_hyphens %%A

 

...and deleting/commenting out this part:

::Trim excess spaces
SET
Field_%Field%=!Field_%Field%: §=§!
SET Field_%Field%=!Field_%Field%: §=§!
SET Field_%Field%=!Field_%Field%: §=§!
SET Field_%Field%=!Field_%Field%: §=§!
SET Field_%Field%=!Field_%Field%:§ =!
SET Field_%Field%=!Field_%Field%:§=!

SET Field_%Field%

 

Zharif
 







Also tagged with one or more of these keywords: cmd, winpe, boot.wim, usb booting, multibooting

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users