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

392 views      
Thread locked
 

Messages in this Thread

 
95,065 Postings in 11,983 Threads, 350 registered users, 98 users online (0 registered, 98 guests)
Index | Admin contact |   Forum Time: Aug 5, 2020 - 4:07 am EDT  |  Hits:32,860,090  (5,092 Today )
RSS Feed