Announcement

Collapse
No announcement yet.

Batch

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch

    I need to copy a single XLS file to a place in verybody users folder.

    I thought it would be simple, but guess again.

    copy "C:\Documents and Settings\username\application data\Microsoft\Excel\Fix.xls" "C:\Documents and settings\%username%\application data\Microsoft\excel\" copies the file to my userprofile only, and not to all user folders. How can i solve this?
    [Powershell]
    Start-DayDream
    Set-Location Malibu Beach
    Get-Drink
    Lay-Back
    Start-Sleep
    ....
    Wake-Up!
    Resume-Service
    Write-Warning
    [/Powershell]

    BLOG: Therealshrimp.blogspot.com

  • #2
    Re: Batch

    Try the following:

    for /f %%2 in (users.txt) do copy "C:\Documents and Settings\username\application data\Microsoft\Excel\Fix.xls" C:\Documents and settings\%%2\application data\Microsoft\excel\"
    Just make sure you have a file called users.txt with list of the SAMID's that you want the file to be copied from / to.

    Hope this helps

    Michael
    Last edited by m80arm; 18th February 2008, 15:19.
    Michael Armstrong
    www.m80arm.co.uk
    MCITP: EA, MCTS, MCSE 2003, MCSA 2003: Messaging, CCA, VCP 3.5, 4, 5, VCAP5-DCD, VCAP5-DCA, ITIL, MCP, PGP Certified Technician

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    Comment


    • #3
      Re: Batch

      I have a single file which has to be copied to every profile on that server.
      Specifying a text file give me work to create that file, so can it be done without specifying a text file?

      Its one single file that has to be copied to every user folder on two terminal servers.
      [Powershell]
      Start-DayDream
      Set-Location Malibu Beach
      Get-Drink
      Lay-Back
      Start-Sleep
      ....
      Wake-Up!
      Resume-Service
      Write-Warning
      [/Powershell]

      BLOG: Therealshrimp.blogspot.com

      Comment


      • #4
        Re: Batch

        Code:
        @echo off
        :: batch to run on the local computer
        :: It will copy one file from one path to all user profiles, if the same subfolder exist.
        :: can only be executed by a member of the local administrators group
        ::       (or.. by the systemaccount during startup)
        
        Set "Source=C:\Documents and Settings\Rems" ||:change this root in your case to your user path
        Set "Subfolder=Application Data\Microsoft\Excel\XLSTART"
        Set "File=ToolbarFix.xls"
        
        Set "Target=%AllUsersProfile:~0,-10%" ||:change this in your case to a static path; Set "Target=U:\Documents and Settings"
        If EXIST "%Target%",(
          For /f "Tokens=*" %%* in ('dir "%Target%" /B /Ad 2^>nul') Do (
          If EXIST "%Target%\%%*\%Subfolder%",(
            xCopy "%Source%\%Subfolder%\%File%" "%Target%\%%*\%Subfolder%\" /I /C /Q /y
            )
           )
          )
        
        
        ::-------------------------check-------------------------
        echo.&Dir "%Target%\%File%" /s /b /ogn
        echo.&pause

        \Rems
        Last edited by Rems; 19th February 2008, 17:08. Reason: added: 2^>nul to "Dir", and removed /D from "xCopy"

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Batch

          Thx Rems, but it doesn't work.
          The script is understandable for a script illiterate like me, but nothing happens?!
          And i can't see where it goes wrong.

          @echo off
          :: batch to run on the local computer
          :: It will copy one file from one path to all user profiles, if the same subfolder exist.
          :: can only be executed by a member of the local administrators group
          :: (or.. by the systemaccount during startup)

          Set "Source=U:\Documents and Settings\u123456"
          Set "Subfolder=Application Data\Microsoft\Excel\XLSTART"
          Set "File=ToolbarFix.xls"

          Set "Target=%AllUsersProfile:~0,-10%"
          If EXIST "%Target%",(
          For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
          If EXIST "%Target%\%%*\%Subfolder%",(
          xCopy "%Source%\%Subfolder%\%File%" "%Target%\%%*\%Subfolder%\" /I /C /Q /D /y
          )
          )
          )

          :EOF
          [Powershell]
          Start-DayDream
          Set-Location Malibu Beach
          Get-Drink
          Lay-Back
          Start-Sleep
          ....
          Wake-Up!
          Resume-Service
          Write-Warning
          [/Powershell]

          BLOG: Therealshrimp.blogspot.com

          Comment


          • #6
            Re: Batch

            If you execute just the part below on the computer, does it show all the users folders that are under "U:\documents and Settings"?

            Code:
            @echo off
            Set "Target=%AllUsersProfile:~0,-10%"
            echo.
            echo.subfolders in...
            echo.------------------------------------
            echo.%Target%
            echo.------------------------------------
                         
            If EXIST "%Target%",(
               dir "%Target%" /B /Ad /On
             ) Else (echo. - Noting found)
            
            echo.&pause >Nul
            \Rems


            What could be the case is, that the path of the default environment variable: %AllUsersProfile% on the server, is on the systemdrive, while the user profile local folders are on drive U: (?)
            In that case just replace the line
            Set "Target=%AllUsersProfile:~0,-10%"
            To
            Set "Target=U:\Documents and Settings"

            .
            Last edited by Rems; 18th February 2008, 17:20.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Batch

              Using the static path seems more robust, so i modified the script to:

              @echo off
              :: batch to run on the local computer
              :: It will copy one file from one path to all user profiles, if the same subfolder exist.
              :: can only be executed by a member of the local administrators group
              :: (or.. by the systemaccount during startup)

              Set "Source=U:\Documents and Settings\u123456"
              Set "Subfolder=Application Data\Microsoft\Excel\XLSTART"
              Set "File=ToolbarFix.xls"

              Set "Target=U:\Documents and Settings"
              If EXIST "%Target%",(
              For /f "Tokens=*" %%* in ('dir "%Target%" /B') Do (
              If EXIST "%Target%\%%*\%Subfolder%",(
              xCopy "%Source%\%Subfolder%\%File%" "%Target%\%%*\%Subfolder%\" /I /C /Q /D /y
              )
              )
              )

              :EOF

              But still no luck
              [Powershell]
              Start-DayDream
              Set-Location Malibu Beach
              Get-Drink
              Lay-Back
              Start-Sleep
              ....
              Wake-Up!
              Resume-Service
              Write-Warning
              [/Powershell]

              BLOG: Therealshrimp.blogspot.com

              Comment


              • #8
                Re: Batch

                Does this batch shows all the user folders?

                Code:
                @echo off
                Set "Target=U:\Documents and Settings"
                echo.
                echo.subfolders in...
                echo.------------------------------------
                echo.%Target%
                echo.------------------------------------
                             
                If EXIST "%Target%",(
                   dir "%Target%" /B /Ad /On
                 ) Else (echo. - Noting found)
                
                echo.&pause >Nul
                Does your account have the permission to wite into each of these subfolders?

                End the batch with a Pause, so you be able to see if there were errors.

                \Rems

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment


                • #9
                  Re: Batch

                  It shows the user profile folders
                  Last edited by Killerbe; 19th February 2008, 14:16.
                  [Powershell]
                  Start-DayDream
                  Set-Location Malibu Beach
                  Get-Drink
                  Lay-Back
                  Start-Sleep
                  ....
                  Wake-Up!
                  Resume-Service
                  Write-Warning
                  [/Powershell]

                  BLOG: Therealshrimp.blogspot.com

                  Comment


                  • #10
                    Re: Batch

                    And does this batch show the users where the submap 'Excel' exist;

                    Code:
                     @echo off
                    Set "Target=U:\documents and settings"
                    Set "Subfolder=Application Data\Microsoft"
                    echo.
                    echo.Find subfolder '\Excel' in...
                    echo.-------------------------------------------------------------
                    echo.%Target%\username\%Subfolder%
                    echo.-------------------------------------------------------------
                    
                    If EXIST "%Target%",(
                      For /f "Tokens=*" %%* In ('dir "%Target%" /B /Ad /ogn 2^>nul') Do (
                        If EXIST "%Target%\%%*\%Subfolder%",(
                         For /f "Tokens=*" %%! In (
                                 'dir "%Target%\%%*\%Subfolder%\E*." /B /Ad 2^>nul') Do (
                           echo *\%%! ^<= user: %%*)
                        )
                       )
                      )
                    
                    echo.&pause >Nul
                    Does your account have the permissions to wite into each one of these subfolders?
                    End the original batch with a Pause, so you be able to see if there were errors (note: I have made some modifications to the original batch).

                    \Rems
                    Last edited by Rems; 19th February 2008, 16:53.

                    This posting is provided "AS IS" with no warranties, and confers no rights.

                    __________________

                    ** Remember to give credit where credit's due **
                    and leave Reputation Points for meaningful posts

                    Comment


                    • #11
                      Re: Batch

                      I modified the script and it works.
                      Great Thx!
                      [Powershell]
                      Start-DayDream
                      Set-Location Malibu Beach
                      Get-Drink
                      Lay-Back
                      Start-Sleep
                      ....
                      Wake-Up!
                      Resume-Service
                      Write-Warning
                      [/Powershell]

                      BLOG: Therealshrimp.blogspot.com

                      Comment


                      • #12
                        Re: Batch

                        My guess is that it had something to do with the /D switch used with xcopy in the previous version of the batch. This causes 'ToolbarFix.xls' only being copied if the lastmodified date in the tartrget is older.

                        Glad it works.

                        \Rems

                        This posting is provided "AS IS" with no warranties, and confers no rights.

                        __________________

                        ** Remember to give credit where credit's due **
                        and leave Reputation Points for meaningful posts

                        Comment

                        Working...
                        X