Windows CMD does not see Desktop when I move it around

Page 3 of 4 FirstFirst 1234 LastLast

  1. Posts : 16,927
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #21

    KeithM said:
    Many of the user-specific system folders don't have an entry under:
    HKCU\...\User Shell Folders unless they've been relocated. Better to "ask the shell". This PowerShell demonstrates.
    ...
    Keith,

    That is not the problem here.
    UserShellFolders for a brand new user
    Windows CMD does not see Desktop when I move it around-brandnewuser-usershellfolders.png

    Denis
    Last edited by Try3; 19 Sep 2020 at 07:34.
      My Computer


  2. Posts : 989
    Microsoft Windows 10 Home
       #22

    In scanning, I thought he was looking for a way to determine the paths of other folders as well. Sorry. Still good general info though. Much more complete than wcript.shell.SpecialFolders.
      My Computer


  3. Posts : 16,927
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #23

    Keith,

    Yes, still good. And, as with many of your PS scripts, I've copied it into my PS notes ready for the day week month quarter when I eventually get around to studying PS properly. So, thanks yet again.

    We'll only know more if dorkious responds.

    Denis
      My Computer


  4. Posts : 4
    Windows 10 Home Edition
       #24

    Sorry for any confusion


    Try3 said:
    I never claimed that other user folders could just be substituted into that code without any adjustment being made.

    Examine the contents of the Command window when you run it and you will probably spot the problem.

    If not, just run the Reg command on its own in a Command window
    Code:
    Reg Query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Music"
    or run RegEdit & go to that Registry key to have a look
    and you will probably then be able to see what's happening and what to change.

    and/or, in a Command window, enter
    Code:
    For /?
    and study its guidance.

    Denis
    I know that you never claimed that you could substitute other user folders and I'm sorry if that was implied.

    What I'm trying to figure out is why it's not returning the path of the music folder ("E:\Music") and video folder ("E:\Videos") when trying to find those using your batch command. I have found that I can find the "Documents" folder using your batch script as it returns the path rather than the "REG_EXPAND_SZ" that the music batch and video batch is returning.

    The only difference that I can see is that the query is using a two word search term in quotes instead of a single word.

    Below is the Reg Queries I ran to see what it returns and to confirm what values I can see from the registry editor:
    Windows CMD does not see Desktop when I move it around-untitled-1.jpg

    Below is a modified version of your script looking for the "Documents" folder to which it can successfully find the path for:
    Windows CMD does not see Desktop when I move it around-untitled-2.jpg

    This final image I tried to find the path to the "Music" folder and I can see that during or after the "For" command is where the problem arises:
    Windows CMD does not see Desktop when I move it around-untitled-3.jpg

    From what I can gather, being somewhat new to fully custom batch scripts, is it the "usebackq tokens=3" that is causing the issue I am running into? Or is there something else I'm missing when trying to find these two paths?
      My Computer


  5. Posts : 16,927
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #25

    GetMusicFolder


    dorkious said:
    is it the "usebackq tokens=3" that is causing the issue I am running into?
    Yes. tokens=3 tells it to get the third word and you want tokens=4 to get the forth.

    GetMusicFolder.bat

    Code:
    :: Purpose - Get the user's Music path even if it has been relocated and even if the path contains spaces or ampersands
    
    :: Extract the Music folder path from the Registry
    set UseExpresssion=Reg Query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Music"
    For /F "usebackq tokens=4 " %%X in (` %UseExpresssion% `) Do Set MusicFolder=%%X
    
    :: Resolve a result that contains a variable such as %UserProfile%
    For /F "usebackq delims=" %%X in (`Echo "%MusicFolder%"`) Do Set "MusicFolder=%%X"
    
    :: Strip quotation marks from start and end of MusicFolder
    Set "MusicFolder=%MusicFolder:~1,-1%"
    
    :: Always protect use of MusicFolder with quotation marks unless and until it is proven to contain no spaces or special characters such as ampersand
    echo MusicFolder - "%MusicFolder%"
    
    Pause to review results during testing

    Notice that you did not need to change the pause command at the end. It works as it is.
    - You will often find it useful to include explanatory remarks after Pause so that you can find your place within scripts when you are testing them.

    Why do you want the Music folder?
    - Does this form part of a larger script?
    - Finding the Desktop folder is often used within larger scripts but I've never seen anybody ask about the Music folder before.
    - Or is this purely a training exercise? Nothing wrong with that.

    Try3 said:
    ... in a Command window, enter
    Code:
    For /?
    and study its guidance.
    and study
    For - SS64

    For is such a sophisticated & powerful command that it takes a lot of studying and a lot of getting used to.

    Denis
      My Computer


  6. Posts : 4
    Windows 10 Home Edition
       #26

    Try3 said:
    Why do you want the Music folder?
    - Does this form part of a larger script?
    - Finding the Desktop folder is often used within larger scripts but I've never seen anybody ask about the Music folder before.
    - Or is this purely a training exercise? Nothing wrong with that.

    Denis
    I was wanting to get all of the User folders for a larger script I'm working on and as a training exercise.

    The plan was to make a "clean install" set of batch scripts to setup most of my normal folder paths on a new install of windows and then use another set of batch scripts to network transfer files from my old computer to my server or directly to a new computer.

    The music folder is one that I have a lot of files in and was wanting to make sure I can cleanly move files to it using batch with the help of the code you provided. I'm also tinkering with how to update my music server with new .mp3 files from my local machine and using batch scripts to copy the files and folder structure over.
      My Computer


  7. Posts : 16,927
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #27

    I also have scripts to copy various files between my own computers. I simplify things by having the same user names, carrying out the same user folder relocations and having exactly the same drive & folder structures on all my computers [including the same shared folder names].

    Note that the batch script can only capture the Music folder of the computer it's running on. But the reg query part of the script can be altered to interogate a remote computer so you would probably find that best.
    https://docs.microsoft.com/en-us/win...ands/reg-query
    Reg - Edit Registry - Windows CMD - SS64.com
    [This particular command is one of the very few examples of MS guides being better than SS64 guides]

    I suppose that your requirements would differ significantly from mine if you only intended to transfer your files once across to the other computer [rather than the regular transfers that I do].

    I imagine your music server updating might well be regular tasks.


    Batch file, PowerShell guides - post #13 - TenForums
    my ditty and demo for Standard passable variables [post #47] - TenForums
    Manipulating variables in batch files - post #14 - TenForums


    Denis
      My Computer


  8. Posts : 4
    Windows 10 Home Edition
       #28

    As far as the folder finding batch files go, they would be used on the computer I'm transferring files from but the reg query to find out things from a remote computer is something I didn't think about so I'll be saving that for later.

    I try to have the same user names and user folder relocations as well but on a clean install you have to do that from the properties window, unless I can find out how to relocate them using batch instead.

    The music server updating will be a regular task at some point once the server itself is stable [consumer desktop parts running a server, wanting to get a refurbished enterprise server at some point]

    In any case thanks for the help and useful links :)
      My Computer


  9. Posts : 7,606
    Windows 10 Home 20H2
       #29

    I found that usebackq is unnecessary for finding the relocated Desktop folder.
    Code:
    Set "+=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
    For /F "tokens=3" %%# in ('Reg Query "%+%" /V Desktop') Do (Set #=%%#)
    For /F "delims=" %%# in ('Echo "%#%"') Do (Set "#=%%#")
    Set "#=%#:~1,-1%"
    Echo The current desktop is %#% & Pause
      My Computer


  10. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #30

    Hello @Matthew Wai,

    Matthew Wai said:
    I found that usebackq is unnecessary for finding the relocated Desktop folder.
    Code:
    Set "+=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
    For /F "tokens=3" %%# in ('Reg Query "%+%" /V Desktop') Do (Set #=%%#)
    For /F "delims=" %%# in ('Echo "%#%"') Do (Set "#=%%#")
    Set "#=%#:~1,-1%"
    Echo The current desktop is %#% & Pause
    Works for me on a Non-Relocated Desktop.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:08.
Find Us




Windows 10 Forums