3 Replies Latest reply on Nov 9, 2015 9:26 PM by JoeDrwiega

    Batch file that copies to "C:\Windows\System32"

    TxDMV-IT Apprentice

      I have a batch file that copies files from the current directory to C:\Windows\System32\ and creates a shortcut on the Public Desktop. It works on my computer if I right-click the batch file and run as administrator. But when I create a LANDesk Package using "New batch file package" option it will push to other computers and creates the desktop shortcut; but will not copy any the files to C:\Windows\System32\.


      Here is the portion that will not work when pushed through LANDesk:


      ----------------------------------------------------------------------------


      @echo off

       

      @cd /d "%~dp0"

      REM *** This will change the current directory to the location of the .bat file.

       

      copy /Y *.exe C:\Windows\System32\

      copy /Y *.cmd C:\Windows\System32\

      copy /Y *.ico C:\Windows\System32\

       

      ----------------------------------------------------------------------------


      Any assistance will be greatly appreciated.


      Thanks,


      Jack

        • 1. Re: Batch file that copies to "C:\Windows\System32"
          JoeDrwiega SupportEmployee

          Well there are two ways you can mitigate this: 1. use SDCLIENT.EXE in batch to /runasuser or /uacelevation SDCLIENT.EXE Command Line Switches OR 2. Can copy to C:\temp directory and then from C:\TEMP to C:\Windows\system32, I know is sounds weird but it worked for me numerous times.

          • 2. Re: Batch file that copies to "C:\Windows\System32"
            TxDMV-IT Apprentice

            Joe,

             

            Using option 2, the files copied to C:\TEMP, but did not copy from C:\TEMP to C:\Windows\System32\

             

            Here is what I changed:

            ----------------------------------------------------------------------------

             

            @echo off

             

            @setlocal enableextensions

            @cd /d "%~dp0"

             

            if not exist c:\TEMP MD C:\TEMP

             

            copy /Y *.* C:\TEMP

            copy /Y "C:\TEMP\*.exe" "C:\Windows\System32\"

            copy /Y "C:\TEMP\*.cmd" "C:\Windows\System32\"

            copy /Y "C:\TEMP\*.ico" "C:\Windows\System32\"

             

            ----------------------------------------------------------------------------


            Thanks,


            Jack

            • 3. Re: Batch file that copies to "C:\Windows\System32"
              JoeDrwiega SupportEmployee

              Try to use this script:

               

              @ECHO ON
              set CWD=%~d0%~p0
              cls
              C:

               

              if not exist c:\TEMP MD C:\TEMP
              ECHO %ERRORLEVEL%
              sdclient.exe /msg=MDTEMP_ERRORLEVEL_is_%ERRORLEVEL%

               

              CD %CWD%

              copy /Y *.* C:\TEMP
              ECHO %ERRORLEVEL%
              sdclient.exe /msg=COPYTEMP_ERRORLEVEL_is_%ERRORLEVEL%

               

              copy /Y "C:\TEMP\*.exe" "C:\Windows\System32\"
              ECHO %ERRORLEVEL%
              sdclient.exe /msg=EXE_ERRORLEVEL_is_%ERRORLEVEL%

               

              copy /Y "C:\TEMP\*.cmd" "C:\Windows\System32\"
              ECHO %ERRORLEVEL%
              sdclient.exe /msg=CMD_ERRORLEVEL_is_%ERRORLEVEL%

               

              copy /Y "C:\TEMP\*.ico" "C:\Windows\System32\"
              ECHO %ERRORLEVEL%
              sdclient.exe /msg=ICO_ERRORLEVEL_is_%ERRORLEVEL%

               

              EXIT /B %ERRORLEVEL%

               

              Be sure to also reset the package hash. This is how LANDESK wants the batch scripts to look like, this will allow software distribution to show the errors and log thru scheduled task console. About Batch File Distribution Packages

               

              Lets see if the console can give us an error to help or it just works.