ZTree.com  | ZEN  | About...  

 Index   Back

An even simpler solution without using SETLOCAL or GOTO   [Q]

By: Nick Williams     West Sussex, England (forum time +5 hrs)  
Date: Sep 21,2017 at 14:31
In Response to: Another approach that doesn't use SETLOCAL (Nick Williams)

Hi Ryan,

Here's an even simpler solution, which I prefer because it doesn't use GOTO. (I'm not a fan of the GOTO command because it can (potentially) lead to very messy code.)


@ECHO OFF
SET "SID1=WMIC useraccount where name="%USERNAME%" get sid"
SET "SID2="
::
ECHO:%%SID1%%=[%SID1%]
::
FOR /F "SKIP=1 DELIMS=" %%V IN ('"%SID1%"') DO (IF NOT DEFINED SID2 (SET "SID2=%%V"))
::
ECHO:%%SID2%%=[%SID2%]
::
PAUSE

Note that it relies on SID2 not being previously DEFINED, so make sure to keep the double-quotes around SET "SID2=".


Kind regards
Nick

279 views      
Thread locked
 

Messages in this Thread

 
94,578 Postings in 11,930 Threads, 348 registered users, 16 users online (1 registered, 15 guests)
Index | Admin contact |   Forum Time: Nov 12, 2019 - 6:12 pm EST  |  Hits:29,077,231  (6,406 Today )
RSS Feed