home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,002 of 68,980   
   Tim Rude to Tim Rude   
   Re: Expand a variable within a variable   
   13 Aug 17 23:20:51   
   
   From: timrude.nospam@nospam.hotmail.com   
      
   On 8/13/2017 9:58 PM, Tim Rude wrote:   
   > I'm trying to obtain the current user's desktop path to pass as a   
   > command-line parameter to an old DOS app that will be running under   
   > Win7/8/10.   
   >   
   > I can get the path from the registry using:   
   >   
   > for /f "usebackq tokens=1,2,*" %%B IN (`reg query   
   > "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User   
   > Shell Folders" /v Desktop`) do set DT=%%D   
   >   
   > On a default install of Win7, that sets the %DT% environment variable to   
   > '%USERPROFILE%\Desktop' since that's what's stored in the registry.   
   >   
   > However, I need the '%USERPROFILE%' part expanded to the actual path, so   
   > that I end up with %DT% being (for example) 'C:\Users\Tim\Desktop'.   
   >   
   > How can I get my batch file to expand the %USERPROFILE% variable that's   
   > within the %DT% environment variable?   
      
   OK, some more digging and experimenting and I've come up with this:   
      
   @echo off   
      
   setlocal enableextensions   
      
   for /f "usebackq tokens=1,2,*" %%B IN (`reg query   
   "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User   
   Shell Folders" /v Desktop`) do set DT=%%D   
      
   for /f "usebackq tokens=*" %%I in (`echo %DT%`) do set DESKTOP=%%~sI   
      
   set DT=   
      
   echo %DESKTOP%   
      
   pause   
      
   endlocal   
      
   This seems to work fine in testing so far. I've also made it return the   
   SFN rather than LFN of the desktop path since the old DOS app only works   
   with 8.3 SFN's.   
      
   See any issues here?   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca