SDJ_1
asked on
Batch File
Hello could you please take a look at the batch file below and let me know why it's not working? First part is suppose to create directories under all users and the second part is just copying the link to all users. Does not seem to be working for me.
@echo off
md "%USERPROFILE%\AppData\Loc alLow" > nul 2>&1
md "%USERPROFILE%\AppData\Roa ming\Micro soft\Windo ws\Start Menu\Programs" > nul 2>&1
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" "%USERPROFILE%\AppData\Roa ming\Micro soft\Windo ws\Start Menu\Programs\" > nul 2>&1
@echo off
md "%USERPROFILE%\AppData\Loc
md "%USERPROFILE%\AppData\Roa
copy /y "D:\Program Files\ClearJavaCache\Clear
%USERPROFILE% refers to the currently logged on user and therefore will only apply the commands to that user's profile.
ASKER
Thanks for response. This is how I set it up and it's doing what I need.
@echo off
cd C:\Users
md "%USERPROFILE%\AppData\Loc alLow" > nul 2>&1
md ""%USERPROFILE%\AppData\Ro aming\Micr osoft\Wind ows\Start Menu\Programs" > nul 2>&1
md ""%USERPROFILE%\AppData\Lo calLow" > nul 2>&1
md ""%USERPROFILE%\AppData\Ro aming\Micr osoft\Wind ows\Start Menu\Programs" > nul 2>&1
md ""%USERPROFILE%\AppData\Lo calLow" > nul 2>&1
md ""%USERPROFILE%\AppData\Ro aming\Micr osoft\Wind ows\Start Menu\Programs" > nul 2>&1
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Ro aming\Micr osoft\Wind ows\Start Menu\Programs\" > nul 2>&1
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Ro aming\Micr osoft\Wind ows\Start Menu\Programs\" > nul 2>&1
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Ro aming\Micr osoft\Wind ows\Start Menu\Programs\" > nul 2>&1
Exit
Can you give me a suggestion on how I can 'echo' the results to a .txt flle in another directory?
@echo off
cd C:\Users
md "%USERPROFILE%\AppData\Loc
md ""%USERPROFILE%\AppData\Ro
md ""%USERPROFILE%\AppData\Lo
md ""%USERPROFILE%\AppData\Ro
md ""%USERPROFILE%\AppData\Lo
md ""%USERPROFILE%\AppData\Ro
copy /y "D:\Program Files\ClearJavaCache\Clear
copy /y "D:\Program Files\ClearJavaCache\Clear
copy /y "D:\Program Files\ClearJavaCache\Clear
Exit
Can you give me a suggestion on how I can 'echo' the results to a .txt flle in another directory?
Create a folder in the root of C: (for example) called results. If you want the program to do it for you I would suggest doing an IF EXISTS, I can help with that if you need.
Anywhere you have:
> nul 2>&1
change to:
>> c:\updates\results.txt
Except for the first time it appears. Change that one to:
> c:\updates\results.txt
Anywhere you have:
> nul 2>&1
change to:
>> c:\updates\results.txt
Except for the first time it appears. Change that one to:
> c:\updates\results.txt
ASKER
Thanks. Can you help me with the 'IF EXISTS' option?
The name of the the file I need the program to create is ClearJavaCache.txt and the location will be C:\XXXLogs\
The name of the the file I need the program to create is ClearJavaCache.txt and the location will be C:\XXXLogs\
Untested:
I provided some code to keep versions of the C:\XXXLogs\ClearJavaCache. txt by appending the date at the end of the file name. prior to creating a new one.
This code makes some assumptions:
1. The program only runs once per day
2. You realize that the date appended would be the day AFTER the file was created.
3. The XXX in the folder is not a variable
4. You will manually police the C:\XXXLogs folder and remove older files no longer needed
All of this can be handled however.
Always test in a non production environment and as usual, there are probably cleaner ways to accomplish what I have done. :)
@echo off
@For /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do @(
Set Day=%%A
Set Month=%%B
Set Year=%%C
Set All=%%C%%B%%A
)
REM *** Check for existance of folder - assumption that XXX is not a variable ***
if not exist C:\XXXLogs\ mkdir C:\XXXLogs\
REM *** If the file ClearJavaCache.txt exists rename it so that it appends the date at the end. ***
if exist C:\XXXLogs\ClearJavaCache.txt ren C:\XXXLogs\ClearJavaCache.txt C:\XXXLogs\ClearJavaCache%All%.txt
cd C:\Users
md "%USERPROFILE%\AppData\LocalLow" > C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\LocalLow" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\LocalLow" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" >> C:\XXXLogs\ClearJavaCache.txt
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\" >> C:\XXXLogs\ClearJavaCache.txt
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\" >> C:\XXXLogs\ClearJavaCache.txt
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\" >> C:\XXXLogs\ClearJavaCache.txt
Exit
I provided some code to keep versions of the C:\XXXLogs\ClearJavaCache.
This code makes some assumptions:
1. The program only runs once per day
2. You realize that the date appended would be the day AFTER the file was created.
3. The XXX in the folder is not a variable
4. You will manually police the C:\XXXLogs folder and remove older files no longer needed
All of this can be handled however.
Always test in a non production environment and as usual, there are probably cleaner ways to accomplish what I have done. :)
ASKER
ok thanks. is there a way to change the wording in the .txt file to something like. "Script Complete? And\or can it show date & time script started and ended? Think I'm making this to complicated for myself.
Try this:
Added the two "echo" lines to provide date/time start/end
@echo off
@For /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do @(
Set Day=%%A
Set Month=%%B
Set Year=%%C
Set All=%%C%%B%%A
)
REM *** Check for existance of folder - assumption that XXX is not a variable ***
if not exist C:\XXXLogs\ mkdir C:\XXXLogs\
REM *** If the file ClearJavaCache.txt exists rename it so that it appends the date at the end. ***
if exist C:\XXXLogs\ClearJavaCache.txt ren C:\XXXLogs\ClearJavaCache.txt C:\XXXLogs\ClearJavaCache%All%.txt
cd C:\Users
echo Started: %date% %time% > C:\XXXLogs\ClearJavaCache.txt
md "%USERPROFILE%\AppData\LocalLow" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\LocalLow" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\LocalLow" >> C:\XXXLogs\ClearJavaCache.txt
md ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" >> C:\XXXLogs\ClearJavaCache.txt
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\" >> C:\XXXLogs\ClearJavaCache.txt
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\" >> C:\XXXLogs\ClearJavaCache.txt
copy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" ""%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\" >> C:\XXXLogs\ClearJavaCache.txt
echo Ended: %date% %time% >> C:\XXXLogs\ClearJavaCache.txt
Exit
Added the two "echo" lines to provide date/time start/end
ASKER
Good aftenoon, thanks for all your help with this!
You are doing the same operations three times? And using "" (doubled double quote) doesn't make sense.
You are also creating the LocalLow folder (why), but create and use Roaming (which is correct).
If you just use
You are also creating the LocalLow folder (why), but create and use Roaming (which is correct).
If you just use
xcopy /y "D:\Program Files\ClearJavaCache\Clear Java Cache.lnk" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\" >> C:\XXXLogs\ClearJavaCache.txt
the Start Menu folder (and the whole path) will be created if necessary, so no MD needed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.