I have a .bat file using Xcopy to copy a folder.
I'm using this bat to run as startup script via Group Policy Editor
The .bat file contains:
xcopy "D:\temp\Temporary Firefox Files\*.*" "r:\TEMP\Temporary Firefox Files\" /E /I /H /Y /C /Q
If I run it after logon it takes about 5 seconds to complete.
But when run at startup (before logon) it runs for about 2 minutes. (after logon I start task manager and see Xcopy process still running for 2 minutes).
As a hint, if I run the same .bat as shutdown script (also via GPO) it takes only 5 seconds to complete.
I'm testing this on Windows 7 Ultimate X64 and on Windows XP Professional X86. The result is the same.
Any ideas?
Related
I am currently creating an improvised installer for a cople software packages. To do this I have to install a couple MSI packages first before doing a couple file operations.
To install an MSI package I am using the following command:
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
This command works and installs the package instantly and witout any problems via CMD.
But when I put this command in my batch file and execute it as an administrator, I get the following error:
This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package
What cold be the problem? Using the same command via the console works flawlessly, only the batch file throws the error...
EDIT: I have also tried the /a parameter in order to install it as an administrator and it does not work either. Full command in batch file:
start /wait msiexec /qn /a "Myinstaller V2.1.msi"
EDIT2: I just realized that it only does not work when I start the batch file with Right click > Run as administrator
When I open a console with administrative rights and start my batch file it works for some reason...
Is there a way to make it work with the Right click > Run as administrator method?
SOLUTION: Thanks to RGuggisberg's answer I now know that the directory changes once the file is executed as an administrator. With a small change the installer gets fired up as an admin and works perfectly starting the installer from a relative path in the same directory:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
pause
I've now also implemented a feature to detect wether or not the installation fails or not:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
if %ERRORLEVEL% EQU 0 echo SUCCESSFULL
if NOT %ERRORLEVEL% EQU 0 echo MyProgram installation FAILED
pause
The current directory changes when you run as administrator. If you want to prove that to yourself, see this post
Difference between "%~dp0" and ".\"?
Include the full path to your filename and it will work.
I am not good at windows scripting. (I am linux guy)
I have to delete files which they are older than n days in two directories.
I am using 2 forfiles command in script. When I run the script manually there is no problem so it's running and finishing its job properly and it takes about 30 seconds to finish
So I created a task to run this batch file everyday in task scheduler
When Task Scheduler executes the script, the script could not end and I could see a running forfiles command in task manager and following day task manager creates a log the script/command is already running. So I am terminating script and run "manually" again, it successfully run and finishes its job in 30-35 seconds again
My script is like that
y:
cd \<path1>
forfiles /s /d -120 /m *.* /c "cmd /c del #path"
cd \<path2>
forfiles /s /d -120 /m *.* /c "cmd /c del #path"
EXIT
How can I run this batch file from task manager properly ?
Thanks
To me it sounds like rights issue. How do you execute your script (directly via start a program or via batch file)? Which windows you are running?
On Windows 7 and Task Scheduler:
Have correct user filled out - who has the rights to run the task and access the files.
Try running your script with checkbox Run with highest privileges checked.
Edit
Stefan is right. If you are running it from within batch file you have to map the network drive with correct credentials:
net use <driver letter> "\\<servername>\<sharename>" /user:<username> <password>
You could do it the following way:
IF NOT EXIST y:\ (
ECHO "The y: drive does not exist. Mapping"
net use y: "\\<servername>\<sharename>" /user:<username>
)
Setup:
I have two linux server and on both I shared a folder.
Server 1 is for saving and editing files and the second is for the backup.
Then I have a Windows 10 workstation on which I mounted both of the shared folders.
Goal:
I would like to run a batch file on my Windows 10 Workstation with which I can copy a folder (it‘s content) from one linux server to the other.
I've been trying hard since days but it didn't want to work.
Folder structure:
Server 1:
/data/ictproject/[here are the files and folders I want to copy]
The folder "ictproject" is shared.
Server 2:
/backup/[here is the destination]
The folder "backup" is shared.
D:\ on Windows 10
D:\backup[temporary destination]
First try:
#echo off
Xcopy "\\[IP-Adress-Server-1]\data\ictproject" "\\[IP-Adress-Server-2]\backup\ict_%data%" /E
pause 0
Second try:
#echo off
Xcopy "\\[IP-Adress-Server-1]\data\ictproject" "D:\backup\ict_%date%\" /E
Xcopy "D:\backup\ict_%date%\" "\\[IP-Adress-Server-2]\backup\ict_%data%\" /E
pause 0
I also tried the hole thing with copy and plenty other things instead of Xcopy but I didn't try robocopy which actualy is the newer version.(I just got to know that seconds ago)
I have two scripts run by the task scheduler.
First batch file makes a file on network shared folder for each computer in network
and it works ok
%SystemRoot%\system32\cmd.exe /c "copy /y nul \\mysrv\test\%computername%\pcon.txt"
Second script must delete that file, but doesn't delete it, how to solve that.
It runs only if I double click on it
Task is run by user SYSTEM in task scheduler
%SystemRoot%\system32\cmd.exe /c "del /Q \\mysrv\test\%computername%\pcon.txt"
I have created a batch file with the following line:
forfiles /p L:\percepsrvr\SQL /s /m *.bak /d -4 /c "cmd /c del /q #PATH "
This deletes any files older than 3 days and works when I run the batch file.
However, when I try to run this batch file as part of a scheduled task the line of code fails to execute. I think it might be because of the mapped network drive (L:) but don't know for sure.
I have the scheduled task running as myself to make sure it has the same permissions as when I run it manually. The scheduled task is running on a Win2008r2 server box and L:\ is on a Win2003 SP2 server box.
Anyone know what might be keeping this from working properly or how to debug a scheduled task?
TIA
Brian
In case anyone comes across this post I found a solution as follows:
ROBOCOPY "D:\Backup Data\percepsrvr\SQL" "\\belgrade\v$\percepsrvr\SQL"
ROBOCOPY "\\belgrade\v$\percepsrvr\SQL" "\\belgrade\v$\percepsrvr\SQL\Old" *.* /move /minage:10
DEL "\\belgrade\v$\percepsrvr\SQL\Old\*.*" /Q
Basically, move the files to delete to another directory and then delete that directory (which can be done with RoboCopy).