i am looking into making a simple bath file that will loop through few simple commands about 1200 times (length of text file). My caveat comes in where those commands need a variable read in from a text file
Lets see if this pseudo code makes sense to anyone
start loop (for # of lines in txt file)
net use \\"IP from txt file" /user:Username *
robocopy \\server\share\path \\"IP from txt file"\c$\Folder
robocopy \\server\share\path \\"IP from txt file"\c$\AnotherFolder
net use \\"IP from txt file" /delete
loop
because of the environment and transferring of files from a domain server to a workgroup pc, this is about the only way i have found i can make this work. For reasons entirely too long to type here i am unable to use psexec and its list function for this unfortunately.
Any help you might be able to provide would be greatly appreciated
Check this batch file and if the output is correct remove each echo before your commands :
#echo off
set "File=List.txt"
for /f "delims=" %%A in ('Type "%File%"') do (
echo net use \\%%A /user:Username *
echo robocopy \\server\share\path \\%%A\c$\Folder
echo robocopy \\server\share\path \\%%A\c$\AnotherFolder
echo net use \\%%A /delete
)
pause
EDIT : To save the result into a LogFile
#echo off
set "File=List.txt"
set "LogFile=LogFile.txt"
If Exist "%LogFile%" Del "%LogFile%"
for /f "delims=" %%A in ('Type "%File%"') do (
echo net use \\%%A /user:Username *
echo robocopy \\server\share\path \\%%A\c$\Folder
echo robocopy \\server\share\path \\%%A\c$\AnotherFolder
echo net use \\%%A /delete
)>>"%LogFile%"
Start "" "%LogFile%" 2>&1
Related
I am trying to copy a file to a folder using the following batch script
echo xcopy \\path1\file.txt \\path2\backup
However, I get the following error:
UNC paths are not supported. Defaulting to the windows directory.
Is there a simple solution for this?
For Single file copying, simply use copy
copy /Y \\path1\file.txt \\path2\backup
Other ways to create a network share:
for /f "tokens=2" %i in ('net use * \\server1\folder\') do set src=%%i & goto :continue
:continue
for /f "tokens=2" %i in ('net use * \\server2\backup\') do set dest=%%i & goto :cp
:cp
copy %src%\file.txt %dest% /Y
net use /d %src%
net use /d %dest%
The above will only work if you have credentials setup already.. if not, you can do it as:
net use \\server1\IPC$ /user:username password
I recently took interest in batch file coding and now i have a project i am working on.
in the project, i have created a basic program that require users to input their Licence code which i have stored in a text file(about 50 lines of licenses) and embeded it in my batch file with a third pary application that convert my batch file to .exe(about 50 lines of licenses). i have about 42 computers in my organization branch where i want to deploy the program.
My challenge however is that since the batch file and the Licence file are all in one .exe, One key would work on all 42 computers. which is very bad.
i have tried using wmic csproduct get uuid to compare computers but i just could not find my way.
Please i really need help with this.
here are my work so far:
SETLOCAL
:startup
SET "Password_File=%UserProfile%\Desktop\Password_File.txt"
set "fail="
set "Activation_Code="
set /p "Activation_Code=Your Activation Code Here: "
REM cls
IF NOT DEFINED Activation_Code ( GOTO :startup
)
findstr /X /l /c:"%Activation_Code%" <"%Password_File%" >nul || set fail=1
if defined fail (
echo Invalid Activation Code!
"%UserProfile%\Desktop\Msgbox Failed.vbs"
GOTO :startup
)
:yes
REM cls
echo Success, you have access!
REm >> %Password_File% echo %Activation_Code%
"%UserProfile%\Desktop\MsgboxSuccess.vbs"
"C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe"
:: This line remove the already entered activation code from the licence file copied to the computer
type %Password_File% | find /V "%Activation_Code%" >XXFile.txt
del "%UserProfile%\Desktop\Password_File.txt"
ren %UserProfile%\Desktop\XXFile.txt Password_File.txt
goto :eof
:nope
REM cls
echo Activation Code has already been used or Invalid!
"%UserProfile%\Desktop\Msgbox Failed.vbs"
:: ping locahost -n 3 >nul
GOTO :startup
i want my batch file to log the following to a destkop file
where LOG_FILE = %Userprofile%\Desktop\LogFolder\LOG_FILE.txt
wmic csproduct get name >>%LOG_FILE%
wmic csproduct get UUID>>%LOG_FILE%
then compare the UUID log in %LOG_FILE is the same as the current computer's UUID
if so then it should verify the same for the Computer name.
the whole idea
#echo off
if wmic csproduct get UUID == "DAC2D186-1AB9-E111-A120-B888E34233CEE" (echo Done! ) else ( echo Not Done!) pause
The future as stated by Microsoft is PowerShell and CIM. I have not yet found a CIM class that includes UUID, but this will work.
FOR /F %%u IN ('powershell -NoLogo -NoProfile -Command "(Get-CimInstance -ClassName Win32_ComputerSystemProduct).UUID"') DO (SET "UUID=%%u")
ECHO UUID is set to %UUID%
use a for /f loop to get the output of a command:
for /f "delims=" %%a in ('wmic csproduct get UUID^, name /format:list ^|find "="') do set "%%a"
echo "%uuid%"
echo "%name%"
I am creating a batch file to open remote Computer Management console by taking User ID as input and computer name from 2nd column from file data.csv. it works fine on first attempt. When it goes back to :start label. and ask for other input. it gives error. System cannot find file ./data.csv
My code is
:start
set /p Input="Enter User-ID:"
for /f "usebackq tokens=1-4 delims=," %%a in (".\data.csv") do (
if %input% ==%%a ("cmd /c Start /B /wait compmgmt.msc –a /computer=%%b")
)
cls
GOTO start
Good practice to use %~dp0 for paths in batch files (instead of relative paths like .) that way if the current working folder changes the file will always be located.
So change to %~dp0data.csv
:start
set /p Input="Enter User-ID:"
PUSHD
for /f "usebackq tokens=1-4 delims=," %%a in (".\data.csv") do (
if %input% ==%%a ("cmd /c Start /B /wait compmgmt.msc –a /computer=%%b")
)
POPD
cls
GOTO start
should restore sanity, pushing the directory then restoring it before the next cycle.
I'm trying to create a combination of batch files, with ftp commands to get and delete a specific number of files from a FTP directory.
Now I'm stuck and I get all the files but ofter, when there are more than 250 files in the directory, the batch stops and it's not possible to continue.
This is my actual situation, I have these 3 files:
FILE 01_FTP_GetFileList.bat
cd C:\folder
ftp -s:02_FTP_GetFileList.txt
C:\folder\03_FTP_MoveFiles.bat
FILE 02_FTP_GetFileList.txt
open xxx.xxx.xxx.xxx
user
password
hash
prompt off
cd folder
lcd folder
ls *.gz filelist.txt
bye
FILE 03_FTP_MoveFiles.bat
#echo off
setlocal enableextensions
setlocal enabledelayedexpansion
echo open xxx.xxx.xxx.xxx>>myscript
echo user user password>>myscript
echo prompt n>>myscript
echo ascii>>myscript
echo cd folder>>myscript
echo lcd C:\folder>>myscript
for /F "usebackq tokens=1,2* delims=," %%G IN ("C:\folder\filelist.txt") DO echo mget %%G>>myscript
for /F "usebackq tokens=1,2* delims=," %%G IN ("C:\folder\filelist.txt") DO echo mdelete %%G>>myscript
echo bye>>myscript
ftp -n -s:myscript
del filelist.txt
del myscript
To resume, the first file recall the 2nd and the 3rd and, as you can see in the code, I get and delete all the *.gz files in a specific directory after listing the files in that directory (this to avoid to delete file added after the copy).
Now I would like to copy only the first file of the list or... to list only 100 files in the folder, is the same by my point of view.
Thanks in advance!!
I do not see any counter variable in the post. The code below uses FILE_COUNT as the counter. It is incremented by the SET /A FILE_COUNTER+=1 statement. The FILE_COUNT is tested for being less than 100. See SET /?.
SETLOCAL ENABLEDELAYEDEXPANSION
SET MAX_FILES=100
SET /S FILE_COUNT=0
FOR /F "usebackq tokens=1,2 delims=," %%a IN (`TYPE "C:\folder\filelist.txt"`) DO (
IF !FILE_COUNT! LSS %MAX_FILES% (
echo mget %%a>>myscript
echo mdelete %%a>>myscript
)
SET /A FILE_COUNT+=1
)
I am writing a batch file which will identify the names of all .jak files in a directory (location specified) and convert them to .java files using AHEAD composer.
The batch file code:
#echo off
set PATH=%PATH%;C:\AHEAD\ahead-v2013.03.20\build\bin;
set PATH=%PATH%;C:\Program Files\Java\jdk1.7.0\bin;
set PATH=%PATH%;C:\Program Files\apache-ant-1.9.3\bin;
set PATH=%PATH%;C:\AHEAD\ahead-v2013.03.20\miscellaneous\javacc\bin;
set PATH=%PATH%;C:\Cygwin\bin;
dir C:\AHEAD\JAK\*.jak /b >> list.txt
for /F "tokens=*" %%a in (list.txt) do call :Foo %%a
goto End
:Foo
set z=%1
echo %z%
jak2java %z%
goto :eof
:End
PAUSE;
cmd
With this i am getting the error System cannot find batch label specified -Foo
But the same program works well for javac command and .java files
Not possible; I tried a simplified version of your code (as below) and it worked fine.
Most probably it's a file format issue. Make sure that the file is in DOS format. Best is; copy the above posted code to a new editor (say, notepad) and save it with *.bat extension and then try running it.
Check out this threads as well
Why "The system cannot find the batch label specified" is thrown even if label exists?
http://help.wugnet.com/windows/system-find-batch-label-ftopict615555.html
#echo off
dir D:\Songs-mp3\English\*.mp3 /b >> list.txt
for /F "tokens=*" %%a in (list.txt) do call :Foo %%a
goto End
:Foo
set z=%1
echo %z%
goto :eof
:End
PAUSE;
cmd