ZTree.com  | ZEN  | About...  

 Index   Back

i think i found the anomaly, looks like an XP's bug   [Q]

By: Ryan       
Date: Sep 20,2017 at 21:56
In Response to: i think i found the anomaly, looks like an XP's bug (Nick Williams)

AA=
@ECHO OFF
SetLocal EnableExtensions EnableDelayedExpansion
:: ------
SET SID1=WMIC useraccount where name="%USERNAME%" get sid
SET SID2=
ECHO:%%%%SID1%%%%=[%SID1%]

FOR /F "DELIMS=" %%%%V IN ('"%SID1%"') DO (
(SET tempWorkVar=%%%%V) & (IF /I "!tempWorkVar:~0,4!"=="S-1-" (SET SID2=%%%%V))
)

ECHO:%%%%SID2%%%%=[%SID2%]
.
.
.
{a main program to use SID2}
.
.

ENDLOCAL
pause


i didnt want to use EnableDelayed from the beginning. because of ! thing that ruins the variables. and i dont know how to handle this well. sometimes you have to use call : thing to make an output in a completely different batch file (i would call it an external subroutine)


BB=
@ECHO OFF

SET SID1=DIR /B
SET SID2=
ECHO:%%%%SID1%%%%=[%SID1%]

SetLocal EnableExtensions EnableDelayedExpansion
FOR /F "DELIMS=" %%%%V IN ('"%SID1%"') DO (

SET tempWorkVar=%%%%V
IF /I "!tempWorkVar:~0,1!"=="A" (

SetLocal DisableExtensions DisableDelayedExpansion
SET SID2=%%%%V
)
)

ECHO:%%%%SID2%%%%=[%SID2%]
pause


BB= could be my invention or something, i couldnt find anyone doing this way in website. BB= works even with !'s in variables as in file names or data strings with !'s in them

so i concluded that
"SetLocal DisableExtensions DisableDelayedExpansion" is "EndLocal"

you can tell me about BB= what is wrong or why it works, because it seems logical to me that it must work but sometimes it says "too many set locals" in a loop because i turn it on and off whenever i need to get away from ! corruptions.

----------------------------------------------------

CC=
::get SID as an evironment variable
@ECHO OFF

REM WMIC MAKES
REM SID
REM S-1-5-21-746137067-1417001333-682003330-1003
REM (NULL STRING)

REM XP HAS A BUG THAT NULL IS NOT A LINE WHILE WIN10 TREATS AS A LINE
REM SO WE NEED TO GET THE 2ND LINE. THIS IS MASSIVELY DIFFICULT.

SET SID1=WMIC USERACCOUNT WHERE NAME="%USERNAME%" GET SID
SET PREVLINE=

FOR /F "DELIMS=" %%%%V IN ('"%SID1%"') DO (

IF DEFINED PREVLINE (

FOR /F "TOKENS=1-2" %%%%A IN ('ECHO %%%%PREVLINE%%%% %%%%V') DO (
SET LINE1=%%%%A
SET SID2=%%%%B
)
SET PREVLINE=

) ELSE (SET PREVLINE=%%%%V)

)

FOR /F "TOKENS=1 DELIMS= " %%%%K IN ("%%SID2%%") DO SET SID=%%%%K

REM WMIC makes a SID with 2 trailing spaces at the end, must remove
REM BUT THE NESTED LOOP REMOVES THE SPACES, WHICH IS ALSO WRONG.
REM EX) SET SID=S-1-5-21-746137067-1417001333-682003330-1003


ECHO %SID%
ECHO %SID%>>M:\SS1
PAUSE



i chose to use CC=, but the nested loop is insanely difficult to comprehend or trace the variables for a novice.

288 views      
Thread locked
 

Messages in this Thread

 
94,581 Postings in 11,930 Threads, 348 registered users, 11 users online (1 registered, 10 guests)
Index | Admin contact |   Forum Time: Nov 17, 2019 - 1:12 pm EST  |  Hits:29,151,823  (11,784 Today )
RSS Feed