ZTree.com  | ZEN  | About...  

 Index   Back

it is not quite so, still not working, still suspicious.   [Q]

By: Ryan       
Date: Sep 19,2017 at 12:11
In Response to: The batch anomalies are to do with your code, I'm afraid (Nick Williams)

it is a batch file

SET SID1=WMIC useraccount where name="%USERNAME%" get sid
FOR /F "DELIMS=" %%V IN ('"%SID1%"') DO SET SID2=%%V

it must have '', SID1 is similar like DIR /p, it is a command.

the expected %SID2% would be something like S-1-5-21-746137067-1417001333-682574330-1003, is different from every other users from every other pc's

AA=is still not working in a batch, it doesnt find the SID.

(ECHO:1)>>m:\aa.txt works
(ECHO:11)>>m:\aa.txt works

ECHO 1>>m:\aa.txt doesnt work
ECHO 11>>m:\aa.txt works
ECHO a>>m:\aa.txt works
ECHO ab>>m:\aa.txt works

i think it doesnt like one number, there must be something special about this 1>> or 2>>.... etc, or this may be an OS bug. this is a trouble if a filename is simply 1 or 2 or 3..... or some variable is simply 1 or 2.... etc

i need ECHO thing without : because when i see "echo is on", i know that it tells me something is wrong with the upper line, it usually happens, when i need to use this
SetLocal EnableExtensions EnableDelayedExpansion, or when i use a wrong command or syntax etc.

if somehow i start to use more parenthesis like this (ECHO:%HH%) in nested loops, which i am already having a trouble with, OS might interpret them wrongly. but (ECHO:%HH%) is a new thing i didnt know, i will have to keep trying to use until i build my confidence. thanks for the line.

i have to make sure SID must not be a null string or a half finished string because
i have to import a lot of [-HKEY_CURREN...] to delete the registries before i write the new ones, yes it is a very dangerous operation.

> >
> FOR /F "TOKENS=1" %%K IN ("1 23") DO SET D1=%%K
> FOR /F "TOKENS=2" %%K IN ("1 23") DO SET D2=%%K
> ECHO:%D1%
> ECHO:%D2%
> ECHO:%D1%>>%OUT%
> ECHO:%D2%>>%OUT%
> Note that FOR-loops are computationally "expensive". There's an
> opportunity here to condense your two FOR-loops into one, as follows:-
> :: FOR /F "TOKENS=1" %%K IN ("1 23") DO SET D1=%%K
> :: FOR /F "TOKENS=2" %%K IN ("1 23") DO SET D2=%%K
> FOR /F "TOKENS=1,2" %%K IN ("1 23") DO (
> SET D1=%%K
> SET D2=%%L
> )
> Also your two ECHO-to-%OUT% statements could be grouped together, like
> this:-
> :: ECHO:%D1%>>%OUT%
> :: ECHO:%D2%>>%OUT%
> (
> ECHO:%D1%
> ECHO:%D2%
> ) >>%OUT%
> If you want to ensure that no trailing spaces appear in your %OUT%
> file, you can wrap your ECHO commands with parentheses, as follows:-
> (ECHO:%D1%) >>%OUT%
> (ECHO:%D2%) >>%OUT%
> -or-
> (
> (ECHO:%D1%)
> (ECHO:%D2%)
> ) >>%OUT%
> Hope all this helps.

Thread locked

Messages in this Thread

95,067 Postings in 11,984 Threads, 350 registered users, 82 users online (1 registered, 81 guests)
Index | Admin contact |   Forum Time: Aug 8, 2020 - 10:40 pm EDT  |  Hits:32,969,942  (24,772 Today )
RSS Feed