I am uploading a running a simple batch script which downloads a file from one server and uploads it to another. The file name is based on the previous day ie. 20111124.zip (YYYYMMDD). The script works fine on all the boxes I have tried it on, however when it is run on a colleagues windows 7 box it fails. The DATE command returns a zero. I have already tried setting the UAC to off but that did not resolve the issue. Any help would be greatly appreciated.
SETLOCAL
SET dwMONTH=%DATE:~4,2%
SET /A dwDAY=%DATE:~7,2%-1
IF %dwDAY% LSS 10 (SET dwDay=0%dwDay%)
SET dwYEAR=%DATE:~10,4%
SET dwDate=%dwYEAR%-%dwMONTH%-%dwDAY%
SET mydate=%dwYEAR%%dwMONTH%%dwDAY%
echo %mydate%
Windows 7 doesnt include a day name,
e.g. on windows XP %date% contains "Di 25.10.2011" (im on a german computer system)
and Win7 only "25.10.2011",
so your offset (7) is pointing to the wrong spot
Related
I had recently upgrade from W7 to W10 and everything seems to work but this basic batch command. Whenever I launch the file, the cmd keeps outputting "The system cannot accept the date entered"
There were no modifications to my knowledge, but perhaps there were some shifting files that happened during the upgrade, I'm not so sure.
So essentially, I need to have the batch file modify the current date since the application in question does not open correctly with the current date and reverting back to the current date a few seconds after the batch executes.
This is the batch file:
set curdate=%date%
date %date:~0,-4%2014
cd "C:\Program Files (x86)\HK-Software\IBExpert"
start ibexpert.exe
#TIMEOUT /NOBREAK /T 10
date %curdate%
The problem is that the code in that script is not compatible with the %DATE% your machine is outputting.
The following offers a quick fix as long as your machine also accepts the two digit year when setting date.
set curdate=%date%
date %date:~0,-2%14
cd "C:\Program Files (x86)\HK-Software\IBExpert"
start ibexpert.exe
TIMEOUT /NOBREAK /T 10
date %curdate%
I need start all folders in a the Windows "Start/Programs/Startup folder" of an XP machine, explorer is disabled to stop top people playing and remove the Start and Task-bar.
I can run a batch file at start-up but how do I write the batch to run ALL programs in the "Start/Programs/Startup folder" the programs in the folder may change but the batch needs to remain the same
I am able to open each file individually using the below code but I really need to be able to open everything in the folder to avoid problems in the future
start "" /b "C:\Documents and Settings\User\Start Menu\Programs\Startup\PROG.appref-ms"
I have tried the code below, that batch starts but nothing starts
%DIR%=C:\Documents and Settings\Pete\Start Menu\Programs\Startup
for %%a in (%DIR%\*) do "%%a"
Running the batch from the desktop also doesn't run the programs in the start folder, the DIR address is taken from windows explorer when I navigated to the folder with the short cuts in
This is an interesting request--one that I would question the motive behind, but since you asked, here's a way you could accomplish it:
#echo off
set DIR=C:\Your\Directory
for %%a in ("%DIR%\*") do "%%a"
I am writing a batch script to use USMT to update computers from XP to 7. Because USMT has a scanstate component that needs to be run before the OS upgrade and a loadstate computer that has to be run after the OS upgrade I am trying to use an if statement to check what the operating system is and then run the proper commands. I am new to batch files but from everything I have been reading it seems like I am writing it properly but I am obviously messing up somewhere. I am getting a "Windows is unexpected at this time error." I also know that the variables are being set properly because of the pause commands that I included. I also tried using IF %WINVERSION% == %XP% goto XPTRUE/WIN7TRUE and enclosing everything within the brackets under a :XPTRUE/WIN7TRUE but that gives the same error.
::Don't have commands print...only outputs are printed
#echo off
:: Set constants
SET XP=Microsoft Windows XP [Version 5.1.2600]
SET WIN7=Microsoft Windows [Version 6.1.7601]
SET XPUSMTLOCATION=C:\Program Files\USMT\Binaries\v4\x86
SET 7USMTLOCATION=C:\Program Files (x86)\USMT\Binaries\v4\amd64
SET BACKUPLOACTION=\\[SERVER IP]\z$\UserAccountBackUps\Backups
SET LOCALBACKUPLOCATION=C:\Backup\USMT
SET NASBACKUPLOCATION=S:\UserAccountBackUps\Backups
#PAUSE
::Get the current version of Windows batch file is running on and store it in WINVERSION
FOR /f "delims=" %%A IN ('ver') DO #SET WINVERSION=%%A
echo %WINVERSION%
PAUSE
::Get the MAC address of the computer and store it in MACA
FOR /F %%A IN ('getmac') DO #SET MACA=%%A
echo The MAC Address is: %MACA%
:: Tell user about script
echo This is a script designed to migrate computers with one network card from Windows XP to Windows 7 using USMT, this script should not be used with computers that have multiple network cards
echo Xp is %XP%
echo 7 is %WIN7%
::Check to see if the current version is XP
PAUSE
IF %WINVERSION% == %XP% (
echo This is windows XP
::Change directory to the location of USMT files
cd %XPUSMTLOCATION%
::Run scanstate to create backup
scanstate.exe C:\Backup /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigApp.xml" /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigDocs.xml" /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigUser.xml" /o /v:2
::Change directory to the location of where the USMT backup is
cd %LOCALBACKUPLOCATION%
::Rename the backup to the MAC Address
rename USMT.MIG %MACA%.MIG
::Map the NAS to a drive because xcopy can not take IP addresses
echo Mapping NAS to drive
::NAS is mapped to drive S, if S is used for something else change s below to different letter
net use s: \\[SERVER IP]\z$
echo Prepairing to copy backup to NAS
::Use xcopy to transfer backup file the /v ensures the files are identical
::This must be done this way because if USMT tries to backup directly to the NAS it tries to overwrite all existing files
xcopy %LOCALBACKUPLOCATION%\%MACA%.MIG %NASBACKUPLOCATION% /v
echo The copy has completed, run this batch file again after OS Upgrade
)
IF %WINVERSION% == %WIN7% (
echo This is Windows 7
PAUSE
)
When I run this on my Windows 7 computer I get this:
I get the same output on my XP computer except it tells me the current version is xp instead. Help would be greatly appreciated.
The line below:
FOR /f "delims=" %%A IN ('ver') DO #SET WINVERSION=%%A
stores in WINVERSION variable a string that contain several words separated by spaces, for example:
SET WINVERSION=Microsoft Windows [Version 6.2.9200]
This way, the line below:
IF %WINVERSION% == %XP% (
is expanded to:
IF Microsoft Windows [Version 6.2.9200] == Microsoft Windows XP [Version 5.1.2600] (
that, of course, cause a syntax error! Type: IF /? for further details.
The way to compare two strings that may contains spaces, is enclosing they in quotes:
IF "%WINVERSION%" == "%XP%" (
I'm helping one of my friends with his QA work. A lot of the time ctfmon.exe is always running in the background and he says it takes up memory on the computer for when he's testing. My friends work machine is using Windows XP
He already tried what was said in this article but it didn't help.
http://www.howtogeek.com/howto/windows-vista/what-is-ctfmonexe-and-why-is-it-running/
We then tried to create a simple batch file that would stop the process for him.
Here are the two files that we have
delete_cftmon.reg:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
"ctfmon.exe"=
Novoice.bat
taskkill /F /IM ctfmon.exe /T
regedit.exe /s delete_cftmon.reg
reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run C:\WINDOWS\system32\ctfmon.exe
rem reg delete [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run] "ctfmon.exe"
I get the following errors "invalid command line parameters" and "Invalid key name"
When we enter the commands via the command line it works fine.
I believe it has to do with HKEY_CURRENT_USER but I'm not entirely sure why.
Any help would be greatly appreciated.
I've seen a related question on this website regarding a Linux system. I have the same question on a Windows XP OS. I bought a Winchester USB external HD, and found out from technical support that the sleep feature is in the firmware and cannot be turned off. I'm looking for an application that will automatically read/write to that drive periodically to keep that timer resetting (every 5 minutes?). Is anyone aware of a small application for Windows XP that will do that?
Thanks for your help.
I have tried nearly everything to fix this problem on my external which is shared out containing my movies. Nothing ever worked. I have a WD Mybook, and I think the sleep is occurring internally in the drive.
I have a solution that works for me, and should for anyone else. The key is to keep the USB drive doing something. Not a lot, but something simple, causes some type of change on the drive.
Windows XP does not have a SLEEP command, but you can download one and add it to the SYSTEM32 folder. Then all you need to do is make a simple batch file, and put it in your startup folder so it executes when you log in.
Make sure you have write access to the drive. Change the drive letter to yours...
Make a batch file.
:start
#echo off
#cls
#echo Keeping USB Drive Awake. Do not close this window!
#sleep 60
#dir E: /S /B >E:\keepawake.txt
#echo Drive Accessed %date% at %time% >keepawake.txt
goto start
This will write the full directory structure to a file on the E: drive in a file called keepawake.txt. Then it will overwrite it with a simple note containing the date and time. This will always be different. It will do it every 60 seconds.
Problem solved...
-Krehator
Make batch (.BAT) file something like this:
#echo off
:start
copy c:\windows\notepad.exe g:\ (Or whatever your external drive is)
choice /N /D Y /T 120 (The 120 is the delay in seconds)
goto :start
You could try NoSleepHD.
http://nosleephd.codeplex.com/
It writes an empty text file to your chosen drive every few minutes (you can choose the minutes) to stop the drive going to auto-sleep mode.
google: nosleephd
Ashx
I'm using the free/open source Windows program KeepAliveHD (http://keepalivehd.codeplex.com/) to accomplish this. Works well.
Any text editor with an autosave function would do it.
You could also write a batch file to get a directory listing, and have it act recursively (call itself) after a set time period. Or use windows scheduler to execute it.
use this batch file
change the 1st two lines letter t: to your drive letter.
it works in all versions of windows
#echo off
:start
REM --- Change the drive letter below to match your HDDs. To add another drive replicate the copy and del lines ---
copy NUL t:\HDDActive.txt
del t:\HDDActive.txt
TIMEOUT /T 30 /NOBREAK
goto start