ZTree.com  | ZEN  | About...  

 Index   Back

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

By: Nick Williams     West Sussex, England (forum time +5 hrs)  
Date: Sep 20,2017 at 16:17
In Response to: i think i found the anomaly, looks like an XP's bug (Ryan)

> i think i found the anomaly
> i think it is an XP's bug and not a new OS's problem
>
> WMIC useraccount where name="%USERNAME%" get sid
> makes 3 lines below, but the 3rd line was a null string.
> SID
> S-1-5-21-1200038644-3393777314-17737942256-500
> (null string)
>
> XP treats a null string not as an input so SID2 takes the final value
> as
> S-1-5-21-1200038644-3393777314-17737942256-500
>
> on the other hand,
> win8.1 or win10 takes the null string as an input value as well, so
> they take the 3rd value as a final, i think i have to read 1 variable by
> 1 variable from FOR /F loop to take the 2nd one that both XP and new
> OS's agree on
>
> this kind of subtlety is too much

I think I understand the problem you're facing -- it comes down to a difference in the way XP handles the WMIC output compared to that of later Windows OSes. But it's not really a bug as such.

We can cope with that. Here's is an updated version of your script, which -- if I've done it right -- will produce the correct results in XP and later versions.

I should point out that I haven't been able to test this because I don't want to run WMIC on my computer -- I've coded it "blind", if you know what I mean.

Let us know if it works (or not).


@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%]
::
PAUSE
::
ENDLOCAL
::


Kind regards
Nick

296 views      
Thread locked
 

Messages in this Thread

 
94,580 Postings in 11,930 Threads, 348 registered users, 18 users online (1 registered, 17 guests)
Index | Admin contact |   Forum Time: Nov 17, 2019 - 11:37 am EST  |  Hits:29,151,448  (11,409 Today )
RSS Feed