Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file Help  (Read 14366 times)

0 Members and 1 Guest are viewing this topic.

ITuser07

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Unknown
    Batch file Help
    « on: May 22, 2014, 10:10:58 AM »
    we have folder redirect turned on so want to pull the registry value for HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" Personal

    Once we find that value in the script which should point to the documents folder we want to copy a file up to that folder from a network share.

    I want to be able to put that batch script into the startup folder on our TS so that all users that login get this file in there documents folder.

    Here is what I have:

    ::@ECHO OFF

    :: Find where My Docs has been redirected to
    FOR /F "skip=4 tokens=2*" %%I in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') DO SET KEY=%%J

    :: Copy test file up to redirected store, if they dont exist
    FOR %%K in ("%USERPROFILE%\My Documents\peIIR.Client.exe.config") DO (
     IF NOT EXIST "\\Server-file1\fs1\PEfile\peIIR.Client.exe.config %%~nxK" XCOPY "%%K" "%KEY%\"
    )

    end

    I pieced bits and pieces together from research on Google.  Not sure if this will work or not wanted to run it by you guys?

    Salmon Trout

    • Guest
    Re: Batch file Help
    « Reply #1 on: May 22, 2014, 10:52:54 AM »
    @ECHO OFF
    REM Find where My Docs has been redirected to
    REM Why are you using double colons for remarks? They are unofficial and break FOR loops
    REM needs skip=2 on my Windows 7 machine to produce this: SET KEY=%USERPROFILE%\Documents
    FOR /F "skip=2 tokens=2*" %%I in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') DO echo SET KEY=%%J

    REM I don't have peIIRClient.exe.config on my machine, so I can't test this bit
    REM Copy test file up to redirected store, if they dont exist
    REM FOR %%K in ("%USERPROFILE%\My Documents\peIIR.Client.exe.config") DO (
    REM IF NOT EXIST "\\Server-file1\fs1\PEfile\peIIR.Client.exe.config %%~nxK" XCOPY "%%K" "%KEY%\"
    REM )

    REM 'end' is not a legal batch command
    REM end



    ITuser07

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Unknown
      Re: Batch file Help
      « Reply #2 on: May 22, 2014, 01:41:20 PM »
      @ECHO OFF
      REM Find where My Docs has been redirected to
      REM Why are you using double colons for remarks? They are unofficial and break FOR loops
      REM needs skip=2 on my Windows 7 machine to produce this: SET KEY=%USERPROFILE%\Documents
      FOR /F "skip=2 tokens=2*" %%I in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') DO echo SET KEY=%%J

      REM I don't have peIIRClient.exe.config on my machine, so I can't test this bit
      REM Copy test file up to redirected store, if they dont exist
      REM FOR %%K in ("%USERPROFILE%\My Documents\peIIR.Client.exe.config") DO (
      REM IF NOT EXIST "\\Server-file1\fs1\PEfile\peIIR.Client.exe.config %%~nxK" XCOPY "%%K" "%KEY%\"
      REM )

      REM 'end' is not a legal batch command
      REM end


      OK I got it to half way work like this:

      @ECHO OFF

      REM Find where My Docs has been redirected to

      FOR /F "skip=2 tokens=2*" %%I in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') DO echo SET KEY=%%J

      REM Copy test file up to redirected store, if they dont exist

      FOR %%K in ("%USERPROFILE%\Documents\peIIR.Client.exe.config") DO (
      IF NOT EXIST "\\Server-file1\fs1\PEfile\peIIR.Client.exe.config %%~nxK" XCOPY "%%K" "%KEY%\"
      )

      The problem I am encountering is that its copying the file to the C:\ and not to the Documents folder.  Any ideas?

      Salmon Trout

      • Guest
      Re: Batch file Help
      « Reply #3 on: May 22, 2014, 01:45:14 PM »
      Take out the echo which I put in for demo purposes, then %KEY% should be set properly

      FOR /F "skip=2 tokens=2*" %%I in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') DO echo SET KEY=%%J

      ITuser07

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Unknown
        Re: Batch file Help
        « Reply #4 on: May 22, 2014, 02:42:19 PM »
        Take out the echo which I put in for demo purposes, then %KEY% should be set properly

        FOR /F "skip=2 tokens=2*" %%I in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') DO echo SET KEY=%%J

        Your awesome, I really appreciate your help.

        Last question and I think we just might have it :-)

        When I run it now it places a file on my desktop called %Userprofile% when I click on it there is a folder inside called documents with the filed copied correctly in there.  But why is it creating a %Userprofile% Folder on my desktop instead of just copying the file to the Documents folder from shell folders /personal?

        Salmon Trout

        • Guest
        Re: Batch file Help
        « Reply #5 on: May 22, 2014, 03:43:31 PM »
        What happens if you open a command prompt and type echo %userprofile%   ?

        Is there some kind of IT professional or system admin you could bring in to this?