Announcement

Collapse
No announcement yet.

bat script for copying files

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

  • bat script for copying files

    I have this .bat script
    Code:
    @echo off
    if not exist "fajl.dll" goto error:
    if not exist "fajl.ini" goto error:
    set xdir=%windir%\system32
    if exist %windir%\sysWOW64 set xdir=%windir%\sysWOW64
    if not exist %xdir%\folder goto error:
    cls
    
    net stop service
    copy /Y "fajl.dll" %xdir%\folder
    copy /Y "fajl.ini" %xdir%\folder
    %xdir%\regsvr32.exe /s %xdir%\folder\fajl.dll
    echo.
    net start service
    
    echo.
    pause
    goto end:
    I tried starting this script over Active Directory: i choosed some user-properties-profile-logon script and put this script. When the user login again, it isn't happen nothing. Beside this script there are more 3 files: .dll,.ini and .bat. These files i inserted in windows/sysvol/sysvol/mojdomen/scripts. From this code i see: the service stoped, next two files are copied in system32/folder, next the .dll file is registered and as a result the service is started. It seems all is ok, but this script don't work. Where i maked mistakes.Maybe i don't have administrator right. I also tried to use gpo in domain logon or startup script but nothing. Plz help me
    Thank's

  • #2
    Re: bat script for copying files

    Originally posted by gogi100 View Post
    I tried starting this script over Active Directory: i choosed some user-properties-profile-logon script and put this script. When the user login again, it isn't happen nothing. Beside this script there are more 3 files: .dll,.ini and .bat. These files i inserted in windows/sysvol/sysvol/mojdomen/scripts. From this code i see: the service stoped, next two files are copied in system32/folder, next the .dll file is registered and as a result the service is started. It seems all is ok, but this script don't work. Where i maked mistakes.Maybe i don't have administrator right. I also tried to use gpo in domain logon or startup script but nothing. Plz help me
    Thank's
    You cannot run the batch as a logon script because users normally don't have permisions to write in %windir% or edit in most of the registry keys.

    Run it as Computer Startup script. In that case make sure the 'computer' can READ and EXECUTE the files in the netlogon share. Also note that the batch then will "runas" and therefore cannot use any of the existing mapped drives. Futhermore, because of the fact that the files you like to copy to the computer are on the network you should specify the full unc-path of the files since a batch cannot set its own folder as the active folder when the path of that folder is an unc-path.

    I've made some quick modifications to your script (not tested it) see if it helps:
    Code:
    @echo off &  Setlocal
    
    SET "xdir=%windir%\system32"
    IF NOT "%ProgramFiles(x86)%"=="" SET "xdir=%windir%\sysWOW64"
    
    Set "DestinationFolder=%xdir%\folder"
    Set "SourcePath=%~0\.."
    
    IF NOT exist "%DestinationFolder%" goto :error
    IF NOT exist "%SourcePath%\fajl.dll" goto :error
    IF NOT exist "%SourcePath%\fajl.ini" goto :error
    
    Net.exe stop service
    
    IF exist "%DestinationFolder%\fajl.dll" (
       regsvr32.exe /u /s "%DestinationFolder%\fajl.dll"
    )
    
    xcopy /Y "%SourcePath%\fajl.dll" "%DestinationFolder%"
    xcopy /Y "%SourcePath%\fajl.ini" "%DestinationFolder%"
    
    regsvr32.exe /s "%DestinationFolder%\fajl.dll"
    
    net.exe start service
    
    :error
    goto:eof
    \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


    • #3
      Re: bat script for copying files

      You said
      Futhermore, because of the fact that the files you like to copy to the computer are on the network you should specify the full unc-path of the files since a batch cannot set its own folder as the active folder when the path of that folder is an unc-path.
      Code:
      Set "SourcePath=%~0\.."
      What tihs code sign? My source path is \\mydomain\SysVol\mydomain\Policies\{05E9D416-AD75-4C39-A304-8B5899F9CBF5}\Machine\Scripts\Startup, Can i insert my path instead of SourcePath=%~0\..?

      Comment


      • #4
        Re: bat script for copying files

        Originally posted by gogi100 View Post
        My source path is \\mydomain\SysVol\mydomain\Policies\{05E9D416-AD75-4C39-A304-8B5899F9CBF5}\Machine\Scripts\Startup
        , Can i insert my path instead of SourcePath=%~0\..?
        Hi gogi100,

        The variable "SourcePath" should point to the networkfolder where the fajl.* files are located.
        Because in your first batch you didn't provide a path at all to the two fajl.* files it was assumably that the files were in the same folder as the batch.


        It is now clear to me that the batch is in this folder:
        \\mydomain.local\SysVol\mydomain.local\Policies\{0 5E9D416-AD75-4C39-A304-8B5899F9CBF5}\Machine\Scripts\Startup

        And the fajl.* files are stored in:
        \\mydomain.local\SysVol\mydomain.local\scripts
        if i am correct?


        this "%~0\..\" will point to the networkfolder where the batch file is. However, the files to copy are on a different path so you cannot use:
        Set "SourcePath=%~0\.."

        The source for the copy statement should be on this path:
        Set "SourcePath=\\mydomain.local\SysVol\mydomain.local \scripts"
        or,
        Set "SourcePath=\\mydomain.local\netlogon"


        \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


        • #5
          Re: bat script for copying files

          i don't understand. All my files: and .bat and dll and ini are in this path:

          \\mydomain\SysVol\mydomain\Policies\{05E9D416-AD75-4C39-A304-8B5899F9CBF5}\Machine\Scripts\Startup
          because of i use gpo:computersetting-windowssettings-scripts-startup. I don't know where's error? I use your source script but nothing. Workstation in domain on startup show start script but nothing happen.

          Comment


          • #6
            Re: bat script for copying files

            Originally posted by gogi100 View Post
            i don't understand. All my files: and .bat and dll and ini are in this path:
            Code:
            \\mydomain\SysVol\mydomain\Policies\{05E9D416-AD75-4C39-A304-8B5899F9CBF5}\Machine\Scripts\Startup
            because of i use gpo:computersetting-windowssettings-scripts-startup. I don't know where's error? I use your source script but nothing. Workstation in domain on startup show start script but nothing happen.
            Then this text caused my confusion because it was irrelevant at that time.
            Originally posted by gogi100 View Post
            Beside this script there are more 3 files: .dll,.ini and .bat. These files i inserted in windows/sysvol/sysvol/mojdomen/scripts.
            If the two files "fajl.dll" and "fajl.ini" are in the same folder as the batch.bat then:
            Set "SourcePath=%~0\.."


            \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


            • #7
              Re: bat script for copying files

              i tried with your script but nothing. The script doesn't work. What i do?

              Comment


              • #8
                Re: bat script for copying files

                Lets find out were errors occour.

                I don't know the name of the batch - so lets say that the name is TEST.bat
                You wrote that the batch is located in the GPO folder:
                \\mydomain.com\SysVol\mydomain.com\Policies\{05E9D 416-AD75-4C39-A304-8B5899F9CBF5}\Machine\Scripts\Startup\TEST.bat

                Run the batch manualy from a client when logged-on as a member of the local Administrators group,
                launch the bat like:
                Start | Run: type the command below and hit the Enter key
                Code:
                AT.exe hh:mm /interactive CMD.exe /k "\\mydomain.com\SysVol\mydomain.com\Policies\{05E9D416-AD75-4C39-A304-8B5899F9CBF5}\Machine\Scripts\Startup\TEST.bat"
                For hh:mm you type the local computer clock time added with 2 MINUTES.
                (Then after you hit the enter key wait for one to two minutes)

                Any errors in the box while finally the script is running?


                For this test you best can use this modified batch:
                Code:
                @echo off &cls &Setlocal
                
                SET "xdir=%windir%\system32"
                IF NOT "%ProgramFiles(x86)%"=="" SET "xdir=%windir%\sysWOW64"
                
                Set "DestinationFolder=%xdir%\folder"
                Set "SourcePath=%~0\.."
                
                IF NOT exist "%DestinationFolder%" call:error "%DestinationFolder%" &goto:end
                IF NOT exist "%SourcePath%\fajl.*" call:error "%SourcePath%\fajl.*" &goto:end
                
                echo\*** DestinationFolder: %DestinationFolder%\
                echo\*** SourcePath: %~dp0
                echo.
                Net.exe stop service
                
                IF exist "%DestinationFolder%\fajl.dll" (
                   regsvr32.exe /u /s "%DestinationFolder%\fajl.dll"
                   echo\)
                
                xcopy /y /c /r /h /V "%SourcePath%\fajl.*" "%DestinationFolder%\"
                echo.
                
                regsvr32.exe /s "%DestinationFolder%\fajl.dll"
                
                net.exe start service
                
                echo - DONE -
                :end
                
                goto:eof --------------------
                :error
                color 6A
                echo *** ERROR: Path NOT EXIST to: %1
                goto:eof --------------------
                \Rems
                Last edited by Rems; 9th July 2009, 20:38.

                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: bat script for copying files

                  i ran
                  AT.exe hh:mm /interactive CMD.exe /k "\\mydomain.com\SysVol\mydomain.com\Policies\{C706ECFE-5A43-4A8A-8CA6-39B8D61D5074}\Machine\Scripts\Startup\TEST.bat"
                  but i received error:
                  Code:
                  ***ERROR: Path NOT EXIST to: "\\mydomain\SysVol\mydomain\Polic
                  ies\{C706ECFE-5A43-4A8A-8CA6-39B8D61D5074}\Machine\Scripts\Startup\install.bat\.
                  .\\\mydomain\SysVol\mydomain\Policies\{C706ECFE-5A43-4A8A-8CA6
                  -39B8D61D5074}\Machine\Scripts\Startup\newtstop.*"
                  The system cannot find the batch label specified - eof----------------
                  The system cannot find the batch label specified - eof----------------
                  C:\WINDOWS\system32>
                  my script install.bat is on this location with 2 files: .dll and .ini \\mydomain\SysVol\mydomain\Polic
                  ies\{C706ECFE-5A43-4A8A-8CA6-39B8D61D5074}\Machine\Scripts\Startup\install.bat\ .

                  Where i make the mistake?

                  Comment


                  • #10
                    Re: bat script for copying files

                    OK the batch seems to execute fine.
                    But I think you must have made some changes to the sample batch ???

                    The batch now use a SourcePath where the path string is doubled (How come?)
                    e.g
                    assuming the source was "\\server\share\sample...\Startup"
                    your batch is checking for the exsistence of the files in:
                    \\server\share\sample...\Startup\\\server\share\sa mple...\Startup\newtstop.*"

                    very strange.

                    It also seems you have removed spaces from both of the same command lines below:
                    goto:eof --------------------
                    There should be a space between eof and the line of dashes

                    (btw what Operating System is on the clients?)
                    Try this, replace the similer 3 lines in my previous batch sample with:

                    Set "SourcePath=%~dp0"
                    <...>
                    IF NOT exist "%SourcePath%fajl.*" call:error "%SourcePath%fajl.*" &goto:end
                    (no backslashes in the source anymore!)
                    <...>
                    xcopy /y /c /r /h /V "%SourcePath%fajl.*" "%DestinationFolder%\"
                    (no backslashes in the source anymore!)

                    And ensure you keep all spaces that should be there in the statements.


                    \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


                    • #11
                      Re: bat script for copying files

                      OS on client computers is Windows XP Pro.
                      I made changes in script with yours

                      It also seems you have removed spaces from both of the same command lines below:
                      goto:eof --------------------
                      There should be a space between eof and the line of dashes

                      (btw what Operating System is on the clients?)
                      Try this, replace the similer 3 lines in my previous batch sample with:

                      Set "SourcePath=%~dp0"
                      <...>
                      IF NOT exist "%SourcePath%fajl.*" call:error "%SourcePath%fajl.*" &goto:end
                      (no backslashes in the source anymore!)
                      <...>
                      xcopy /y /c /r /h /V "%SourcePath%fajl.*" "%DestinationFolder%\"
                      (no backslashes in the source anymore!)
                      but again i received
                      Code:
                      ***ERROR: Path NOT EXIST to: \\mydomain\SysVol\mydomain\Policies\{C706ECFE-5A43-4A8A-8CA6-39B8D61D5074}\Machine\Scripts\Startup~fajl.*"
                      C:\Windows\system32>
                      Where is now error?
                      Last edited by gogi100; 10th July 2009, 12:59. Reason: error

                      Comment


                      • #12
                        Re: bat script for copying files

                        The error is different now.
                        But still it must be a typo or something in your version of the code, please recheck.


                        \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


                        • #13
                          Re: bat script for copying files

                          My code in .bat script is

                          Code:
                          @echo off &  Setlocal
                          
                          SET "xdir=%windir%\system32"
                          IF NOT "%ProgramFiles(x86)%"=="" SET "xdir=%windir%\sysWOW64"
                          
                          Set "DestinationFolder=%xdir%\folder"
                          Set "SourcePath=%~0"
                          
                          IF NOT exist "%DestinationFolder%" call:error "%DestinationFolder%" &goto:end
                          IF NOT exist "%SourcePath%fajl.*" call:error "%SourcePath%fajl.*" &goto:end
                          
                          echo \ *** DestinationFolder: %DestinationFolder%\
                          echo \ *** SourcePath: %~dp0
                          echo.
                          Net.exe stop service
                          
                          IF exist "%DestinationFolder%\%fajl.dll" (
                             regsvr32.exe /u /s "%DestinationFolder%\%fajl.dll"
                             echo\)
                          
                          xcopy /y /c /r /h /V "%SourcePath%fajl.*" "%DestinationFolder%\"
                          echo.
                          
                          regsvr32.exe /s "%DestinationFolder%\%fajl.dll"
                          
                          net.exe start service
                          echo - DONE -
                          :end
                          goto:eof ----------------
                          :error
                          color 6A
                          echo ***ERROR: Path NOT EXIST to: %1
                          goto:eof ----------------
                          where si error now?

                          Comment


                          • #14
                            Re: bat script for copying files

                            Originally posted by gogi100 View Post
                            where si error now?
                            Well here,
                            Set "SourcePath=%~0"

                            please read my sample code again.

                            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


                            • #15
                              Re: bat script for copying files

                              i made errors when i typed name of files .dll and .ini. Script works ok.
                              thank's

                              Comment

                              Working...
                              X