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

268 views      
Thread locked
 

Messages in this Thread

 
94,426 Postings in 11,918 Threads, 348 registered users, 12 users online (2 registered, 10 guests)
Index | Admin contact |   Forum Time: Sep 18, 2019 - 11:26 am EDT  |  Hits:28,648,565  (1,312 Today )
RSS Feed