Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

3451.

Solve : .bat To .exe?

Answer» QUOTE
why? That MAKES no sense

Dude I Cant Install Two Antivirus At A Time

I Had Avast 4.8 , HENCE I Wanted The Other ONE To Check With QuickHeal For The Above Mentioned Reasons Quote from: BC_Programmer on May 09, 2010, 08:47:45 AM
Yes, look at the exciting source.

Code: [Select]@echo off
color 0e
echo.
echo This Is A Test File For Malware
echo.
pause
Oh the EXCITEMENT!




You Forgot The Exit Command At The Last LineQuote from: the_mad_joker on May 11, 2010, 02:25:40 AM
You Forgot The Exit Command At The Last Line

No I didn't.Quote
No I didn't
As You Wish ! Who Will Argue With You
3452.

Solve : Deltree a folder by creation date in a .bat file?

Answer»

So I had to create a batch file that RAN a build script and created a unique directory then copied files to that directory during each run. What I need to do now is add to the script so that it looks for all the directories in that are more that 4 days old and delete them. How would I go about doing this?

The batch is run on a local admin account on a win 2003 server.

date /t command gives: Fri 05/07/2010
format (mm/dd/yyyy)

The directory that it will search in is: Z:\IT\AD&M\CLASSMate\ESD\

So to sum it up, I need a command that I can add to my current batch file that will check the creation date of all the directories within the "ESD" folder and delete any folder (and it's contents) that are more than 4 days old.

Any help would be greatly appreciated, Thanks!

Oh, and not sure if it matters, but all the folder names in that ESD directory will also be in the format of "yyyy-mm-dd hh.mm". Every time the build script is run, it creates a directory with the date and time it was run as the folder name and places the files in there. So it's the old builds that I need to get rid of after a little time.http://www.raymond.cc/blog/archives/2007/09/24/deltree-command-replacement-in-windows-2000-or-windows-xp/


Deltree Command Replacement in Windows 2000?

"Just a short tip for today. I was required to create a batch to automatically
remove a directory as well as all of its subdirectories and contained files.
I remembered many years ago when I was using Windows 98, I could use the “deltree”
command to delete a folder and everything in it.

I launched command prompt(DOS), and typed “deltree /?”
to display all the commands for deltree because I couldn’t remember
the deltree parameters. I was QUITE embarrassed to see the error
message “deltree is not recognized as an internal or external command,
operable program or batch file.” It seems that the deltree command is no
longer used."

Reference:

http://stackoverflow.com/questions/324267/batch-file-to-delete-files-older-than-a-specified-date/1180746#1180746


I have not tested the following code:


Code: [Select]@echo off
SET OLDERTHAN=%1
IF NOT DEFINED OLDERTHAN GOTO SYNTAX

echo >> ~~~FILES_TO_KEEP.TXT~
for /f "tokens=*" %%a IN ('xcopy *.pdf /d:%1 /L /I null') do if exist %%~nxa echo %%~nxa >> ~~~FILES_TO_KEEP.TXT~
for /f "tokens=*" %%a IN ('xcopy *.pdf /L /I /EXCLUDE:~~~FILES_TO_KEEP.TXT~ null') do if exist "%%~nxa" del "%%~nxa"
del ~~~FILES_TO_KEEP.TXT~

GOTO END

:SYNTAX
ECHO.
ECHO USAGE:
ECHO DELOLD mm-dd-yyyy
ECHO Where mm-dd-yyyy is the date prior to which you want to delete files.
ECHO.
ECHO EX: "DELOLD 10-17-2008" Deletes files older than October 17, 2008.
ECHO.
ECHO This should work on any language version of Windows, but has only been
ECHO tested in English-US versions.
GOTO END

:END Quote from: marvinengland on May 07, 2010, 11:33:16 AM

http://www.raymond.cc/blog/archives/2007/09/24/deltree-command-replacement-in-windows-2000-or-windows-xp/


Deltree Command Replacement in Windows 2000?

"Just a short tip for today. I was required to create a batch to automatically
remove a directory as well as all of its subdirectories and contained files.
I remembered many years ago when I was using Windows 98, I could use the “deltree”
command to delete a folder and everything in it.

I launched command prompt(DOS), and typed “deltree /?”
to display all the commands for deltree because I couldn’t remember
the deltree parameters. I was quite embarrassed to see the error
message “deltree is not recognized as an internal or external command,
operable program or batch file.” It seems that the deltree command is no
longer used."



You can see how long it's been since i last played with DOS commands then hmm, that code wouldn't work for me. The batch will be an automated batch file so it needs to calculate the date on it's own to determine if a folder needs to be deleted or not. So regardless of what date the batch runs, it will always delete any folder that is more than 4 days old. The script above asks the user for a date value to determine what files it will delete.Hmm.... Can the forfiles command be used? I was thinking something like this, but I'm not sure if i have the rd part right or not:


forfiles /m *.* /d -4 /c "cmd /c echo @file is at least 4 days old."
forfiles /m *.* /d -4 /c "cmd /c rd @file"

is the forfiles command an external command that I can bring over to my xp box so i can test? Or can it only be run on a win server? I created this little bit of code;

evaluate.vbs contains the following code...
Code: [Select]Wscript.echo eval(WScript.Arguments(0))
main batch file contains...
Code: [Select]@echo off
del output.txt
del output2.txt
del output3.txt
del output4.txt
rem ** set to the root folder, code will check folders inside this one
set FOLDERCHK=c:\test2

rem ** get the date from 4 days ago
for /f "tokens=*" %%i in (' cscript //nologo c:\test\evaluate.vbs "date -4" ' ) do set DELDIR=%%i

rem ** export DIR result in folder
for /f "tokens=*" %%i in ('dir /A:D %FOLDERCHK%') do echo %%i >>output.txt

rem ** List folder list that contain the required date
findstr %DELDIR% < output.txt >>output2.txt

rem ** Output only the name of the folders
for /f "tokens=4 delims= " %%i in (output2.txt) do echo %FOLDERCHK%\%%i >>output3.txt

rem ** Filter out the "." & ".." lines
findstr /V /C:"." < output3.txt >>output4.txt
echo Folders to be deleted...
type output4.txt
set /P CONFIRM=Type 'y' to confirm...
if '%CONFIRM%=='y goto delfolders
goto end
:delfolders

rem ** Confirming the commands to be executed...remove "ECHO" to actually delete the folders...
for /f "tokens=*" %%i in (output4.txt) do echo rd /S /Q %FOLDERCHK%\%%i
:end

It's a little messy, but it works...
I've never heard of the forfiles command before, but it's available on my Win7 PC and MAKES my code redundant lol...Quote from: ShadyDave on May 07, 2010, 04:42:25 PM
I created this little bit of code;

evaluate.vbs contains the following code...
Code: [Select]Wscript.echo eval(WScript.Arguments(0))

Actually, I created evaluate.vbs. Just saying.
Apologies, I added that VBS code details after I posted it, and should put the "I created..." line after the VBS code and acknowledged you for the VBS code...

After all your help with me creating my DR check script I don't want to take any credit away from you.Got it, this is what I used:

Code: [Select]forfiles /m * /d -4 /c "cmd /c if @isdir==TRUE rd /s /q @file"
So this will look at the current directory I am in when the command is called and it will check all directories (and only directories) for the folder date and determine if it's more than 4 days old, if so, it will delete that folder.

Quote from: Panthers_Den on May 10, 2010, 01:18:50 PM
Got it, this is what I used:

Code: [Select]forfiles /m * /d -4 /c "cmd /c if @isdir==TRUE rd /s /q @file"
So this will look at the current directory I am in when the command is called and it will check all directories (and only directories) for the folder date and determine if it's more than 4 days old, if so, it will delete that folder.



Great "forfiles" is versatile and powerful.

Here is another example passing the date as a command line argument.


C:\test>type den.bat
Code: [Select]@echo off
forfiles /m *.txt /D %1 /c "cmd /c dir @file" | findstr ".txt"
Output:

C:\test>den.bat 05/08/2010
05/10/2010 05:04 PM 74 5810.txt
05/09/2010 12:56 PM 9 BATCH116-20100508-1701.txt
05/09/2010 12:56 PM 9 DATA256.txt
05/08/2010 05:01 PM 7 seq.txt

C:\test>den.bat 05/06/2010
05/10/2010 05:04 PM 74 5810.txt
05/09/2010 12:56 PM 9 BATCH116-20100508-1701.txt
05/09/2010 12:56 PM 9 DATA256.txt
05/08/2010 05:01 PM 7 seq.txt
05/07/2010 02:12 PM 9 test.txt

C:\test>den.bat 05/01/2010
05/10/2010 05:04 PM 74 5810.txt
05/09/2010 12:56 PM 9 BATCH116-20100508-1701.txt
05/09/2010 12:56 PM 9 DATA256.txt
05/08/2010 05:01 PM 7 seq.txt
05/07/2010 02:12 PM 9 test.txt
05/01/2010 09:11 AM 17 today.txt

C:\test>

p.s. It is a good idea to get a list before you deleteyea, i actually had an "echo" before the rd, but removed it when I posted the cmd on here.
3453.

Solve : copying file?

Answer»

Code: [Select]@ECHO off
TITLE File Copying from one name to ANOTHER!
if NOT %1=="" goto do

echo Enter Source File Name!
SET /P src="Enter Source File Name: "
echo.
echo Enter Destination File Name!
set /P dest="Enter Source File Name: "
echo.
copy %src% %dest% /Y >NUL
echo.
echo Copy Done !!!


:do
cls
echo.
echo.
echo.
echo.
echo.
echo.
copy %1.? *.inc /Y >NUL

echo.
echo copy done
echo.
pause

the above cody works without if statement

I want it to copy the INPUTED file extension to .inc


any help will be highly appreciatedif NOT "%1"=="" goto dothanks a lot

3454.

Solve : help to improve simplea batch job application?

Answer»

Hi All

I have simple batch job applicaiton which is suppose to checek network folders and generate report both on screen and to file.

Small PART of that applicaiton looks LIKE that:
===================

ECHO ------------------
echo Product Hierarchy:
echo ------------------

echo. >> %Date%.txt
echo.Files from Folder >> %Date%.txt
echo.------------------ >> %Date%.txt

echo. >> %Date%.txt
echo.Files%Date%.txt
echo. >> %Date%.txt
echo Files
echo.

dir \\ network_folder /b >> %Date%.txt
dir \\ network_folder /b
============


Is any change to improve that code as I have to repeat similar inforamtions few times as you can see(once is move to txt file, another is info on screen)?

Is POSSIBLE to add any inforamtion "if.. else" in that sence: if *.xml file found send mail to administrator?

Thank you very MUCH for help.

3455.

Solve : Batch to automatically determine available drives to write to?

Answer»

I have a script that I've written where I have hard coded an output to a PCMCIA card on a non-networked machine.

Now we are getting new MACHINES that have two PCMCIA slots and an SDHC reader, and there is talk about moving to SDHC instead of PCMCIA for the data outputs (HORAAY!).

This PRESENTS a problem to me though as the old machines only have a single PCMCIA slot so it's pretty easy to rely on the hard code. But with the new machines, a user could install the PCMCIA card in either of the two slots, or insert an SDHC card. I'd like to read the state of the three slots automagically and write to the device based on which one is available.

ETA: If there are multiple devices available, I would currently prefer the failsafe to write to any/all of the available devices, with no user input as to which to select.

The important part: I do not want to rely on user input for this if at all possible.Code: [Select]@ECHO off
set driveletter=
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X U Z) do (
if exist "%%D:\" (
echo.>%%D:\testifwritable.txt && (
del %%D:\testifwritable.txt
set driveletter=%%D
goto jumpout
)
)
)
:jumpout

REM if no writable drive found...
if "%driveletter%"=="" goto end

REM your code here

:end


The above should find the first writable drive letter of a series. It will be in the variable %driveletter%. If the variable is BLANK, no letter corresponding to a writable volume was found.

In place of the whole alphabet, PUT the drive letter(s) you want to test e.g.

Code: [Select]for %%D in (L M N) do (
note spaces



3456.

Solve : Use batch code or installer for custom configuration of 'virgin' software?

Answer»

Thanks to the great help I received in this forum previously with a batch script, I figured I'd pop back in and ask for advice once again.

I have a software package that is to be installed across a large number of client machines, but each machine's output must be uniquely identifiable. Each machine will perform an identical task, but the setup process for the HOST software is labor intensive and prone to mistakes in entry. Ideally, I'd be the one to set them all up but I can't guarantee that will be the case, so I'd like to minimize error.

So my thought is this. The host software creates a working directory in which all configuration files exist. All of the config files are either .xml, .ini, or .par, and all are TEXT readable with a text editor. There are about two dozen config files that need to be updated on each client, some of them rather extensively, but the only difference between fully configured clients is the machine name in each of the config files.

So, I propose that I do a clean install and then backup the working directories.

Then, I go through the configuration process on Machine #1.

I now have two directories I can compare. I have verified that I can manually go in to each config file and change "Machine #1" to "Machine #2", then copy the new config files and associated directory STRUCTURE over a virgin install, and the software works as intended. The PROBLEM is that this isn't much less labor intensive than just going through the configuration process manually.

So...if I could automate the process that would be super duper swell. I don't know that batch would be the best way though. Any ideas would be greatly appreciated! I have about a week to get something in place before the clients start showing up.Total Uninstall...Just FYI, I have elected to use NSIS, using the following three examples as a guide.

Reusable installer script
Installer for SUCCESSIONAL Installations
TextReplaceInFolder

3457.

Solve : path substitution??

Answer»

Hi there,

I need help with some bat files please. I've got three bats that do similar but slightly different functions and what I'd like to know is if there is a way of inserting the path (in bold below) for each one, pehaps by reading something like an INI file to personalize it for the user as the path to the database will be different for each user dependent on what OS they have, and I thought it would be cool if the path could just be read from somewhere else.

eg

cd\
cd "this is the path to a database"
this line starts SQLIte 3 and reads a different txt file in each bat

mtia
Joe


You could have the path-to-the-database as the first line in a text file, and instead of hard coding the path in the batch file, you could read it from the text file, using set /P

Hard coded

Code: [Select]set DBPath=d:\path to\The Database\folder
cd "%DBPath%"
Read from file...

Contents of x:\yourpath\yourfile.txt...
Code: [Select]d:\path to\The Database\folder
batch file
Code: [Select]set /p DBPath=&LT;"x:\yourpath\yourfile.txt"
cd "%DBPath%"thanks for the quick answer, but you've kinda confused me, have you POSTED two different options, or is it all one. I understand what you're saying about how to do it, but it's having the three different BITS in your post that are confusing me

mtia
Joe

OK is this clearer...

You could have the path-to-the-database as the first line in a text file, and instead of hard coding the path in the batch file, you could read it from the text file, using set /p

METHOD (1) The way you mentioned, that is, having the path to the database folder written into the batch file. Slight change - the path is held in a variable %DBPath% - the reason why I did this will become clear below.

Code: [Select]set DBPath=d:\path to\The Database\folder
cd "%DBPath%"
---- dividing line ----------------------------------------------------------------------------------------------------------------------------------------------------

Method (2) The method you asked for, reading the path name from a file...

This is the file that has one line only, which is the path to the database file. That path is a made-up example which you would need to change. So is the name of the file.

Contents of x:\yourpath\yourfile.txt...
Code: [Select]d:\path to\The Database\folder
THis is an example of getting the first line of a text file and putting it into a variable
Code: [Select]set /p DBPath=<"x:\yourpath\yourfile.txt"
cd "%DBPath%"
OK, got it, I think, thanks very muchlet us know if you get it working or if you have any problems

3458.

Solve : How can i scan my computer for viruses using cmd.exe??

Answer»

thanksWhat anti-virus software do you RUN normally? Some come with command-line scanners.For example(again depending UPON whatever Anti-virus your using you can modify the code to run at startup, different intervals, etc.)

AVG Once-A-Month Interval Scan at startup:

Code: [Select]@echo off
cd "C:\PROGRAM Files\AVG\AVG9"
set curday=%DATE:~7,2%
set curmonth=%DATE:~4,2%
set curyear=%DATE:~10,4%
set scanfilelog=%curmonth%%curyear%
If not exist %scanfilelog%.log (
echo Scanned > %scanfilelog%.log
start /wait "avgscanx /COMP /HEUR /ARC /TRASH /QT /BOOT /PROC /REG /COO /ADS /SHUTDOWN"
) else (
echo Continue with startup
exit
)

Note: This is just an example.

If you have a different AntiVirus just check the Help guide, It should tell you about the CMD params.Quote from: evp.tooLock on May 26, 2010, 06:59:36 AM

thanks


C:\Program Files\Malwarebytes' Anti-Malware>dir mb*.*
VOLUME in drive C has no label.
Volume Serial Number is 304E-C1B1

Directory of C:\Program Files\Malwarebytes' Anti-Malware

01/07/2010 03:57 PM 59,241 mbam.chm
01/07/2010 05:07 PM 167,760 mbam.dll
01/07/2010 05:07 PM 1,394,000 mbam.exe
01/07/2010 05:07 PM 84,816 mbamext.dll
01/07/2010 05:07 PM 429,392 mbamgui.exe
01/07/2010 05:07 PM 236,368 mbamservice.exe
6 File(s) 2,371,577 bytes
0 Dir(s) 6,751,793,152 bytes free

C:\Program Files\Malwarebytes' Anti-Malware>mbam.exe

C:\Program Files\Malwarebytes' Anti-Malware>Hmmmm....Why'd you DIR your MBAM folder?Quote from: Carbon Dudeoxide on May 30, 2010, 09:21:03 AM
Hmmmm....Why'd you DIR your MBAM folder?

To clarify the procedure for people new to CMD.

How would Carbon suggest showing how to run mbam.exe from the command prompt?
Updates mbam, runs a quickscan, and only shows the results if something is found.
Code: [Select]%programfiles%\Malwarebytes' Anti-Malware /runupdate /quickscanterminate /fullauto
Quote from: BC_Programmer on May 30, 2010, 03:11:38 PM
Updates mbam, runs a quickscan, and only shows the results if something is found.
Code: [Select]%programfiles%\Malwarebytes' Anti-Malware /runupdate /quickscanterminate /fullauto
Wouldn't you NEED to enclose the path with quotes?Quote from: marvinengland on May 30, 2010, 10:28:50 AM
To clarify the procedure for people new to CMD.

How would Carbon suggest showing how to run mbam.exe from the command prompt?

Buffalo BillQuote from: Helpmeh on May 30, 2010, 06:54:18 PM
Wouldn't you need to enclose the path with quotes?

It would be a good measure on older OS's, but It's usually not required.Quote from: Helpmeh on May 30, 2010, 06:54:18 PM
Wouldn't you need to enclose the path with quotes?
crap, and include the exe name

Code: [Select]"%programfiles%\Malwarebytes' Anti-Malware\mbam.exe" /runupdate /quickscanterminate /fullauto
3459.

Solve : Move command?

Answer»

Hello everyone. This is my first post on these forums. I have just started a networking certification program, and we are learning the command prompt system. I am having a difficult time with one of the assignments. I am being asked to copy and rename a file to a subdirectory all in 1 step. The syntax of the MOVE command is throwing me off here.

I am in the directory (a subdirectory of my DOCUMENTS) that contains the file I want to move. the file name is sales projections.xls I need to move that file to a subdirectory of the active called FY 2002. I need to rename the file 2002 sales projections.xls

I looked at this site and the help command in the cmd prompt, and I am confused.

I have tried pretty much all permutations and sytax of the below command, but it is not working

move "sales projections.xls" "fy 2002" "2002 sales projections.xls"

Any help you can offer would be appreciated.

Code: [Select]C:\>move /?
Moves files and renames files and directories.

To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination

To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2

[drive:][path]filename1 Specifies the location and name of the file
or files you want to move.
destination Specifies the new location of the file. Destination
can consist of a drive letter and colon, a
directory name, or a combination. If you are moving
only one file, you can also include a filename if
you want to rename the file when you move it.
[drive:][path]dirname1 Specifies the directory you want to rename.
dirname2 Specifies the new name of the directory.

/Y Suppresses prompting to confirm you want to
OVERWRITE an existing destination file.
/-Y Causes prompting to confirm you want to overwrite
an existing destination file.

The switch /Y may be present in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless MOVE command is being executed from
within a batch script.

Did you really read the help? Properly?

The file you want to OPERATE on is in the current folder, so just its name will do. It contains spaces so enclose it in quotes.

So the first part (MOVE filename1) will be

move "sales projections.xls"

Now we add a space. Then we build the the second part (destination) . This is the path (relative or absolute) plus, since we are moving and renaming one file, the new filename.

The folder is under the current one, so we (again) can just use its name. It has a space so again we use a quote to start, and we finish the folder name with a slash.

"FY 2002\

Now we can add the new filename and finish with another quote.

2002 sales projections.xls"

Put it all together

move "sales projections.xls" "FY 2002\2002 sales projections.xls"








Thank you for the reply. I did read the help, but apparantly not correctly. Finishing the destination folder name with a \ was throwing me off, as I did not see it in the help file anywhere, and the book for the course did not have an example showing that either. I appreciate you listing the full command for me, as I am very new to reading command syntax.

Thanks again.Quote from: psufan14 on May 29, 2010, 09:35:26 PM

Finishing the destination folder name with a \ was throwing me off

You need to study path and folder naming.

Ignoring switches, the syntax for just moving a file, while preserving the name is this

move (where the file is now) (where you want the file to go)

example

move "C:\A folder\A subfolder\example file.txt" "D:\New Folder\Sub folder"

The syntax for moving and renaming is essentially this...

move (what the file is now) (what you want the file to become)

example

move "C:\A folder\A subfolder\example file.txt" "D:\New Folder\Sub folder\different name.txt"

If you specify paths or folders then there will be a slash or slashes.





Use the copy command. When you sure you have the correct files, "del" the source files.Quote from: marvinengland on May 30, 2010, 08:30:26 AM
Use the copy command. When you sure you have the correct files, "del" the source files.

Actually, Marvin, you have a point there. The OP wrote this

Quote
I am being asked to copy and rename a file to a subdirectory all in 1 step

Copying and moving are different things. psufan14, which is it?
Quote from: psufan14 on May 29, 2010, 12:59:50 PM

I am in the directory (a subdirectory of my documents) that contains the file I want to move. the file name is sales projections.xls I need to move that file to a subdirectory of the active called FY 2002. I need to rename the file 2002 sales projections.xls

Any help you can offer would be appreciated.



We should always offer an example with the output of the example.

C:\test>copy zee.bat c:\test\sub\zoe.bat
1 file(s) copied.

C:\test>cd sub

C:\test\sub>dir
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of C:\test\sub

05/30/2010 10:35 AM .
05/30/2010 10:35 AM ..
05/13/2010 10:56 AM 87 zoe.bat
1 File(s) 87 bytes
2 Dir(s) 295,696,343,040 bytes free

C:\test\sub>


The above will copy zee.bat to a subdirectory ( called sub ) and will change the name of the file from zee.bat to zoe.bat.
The instructions said to copy the file and in the process
rename the file in the new folder. The only command I
knew that COULD rename a filewhile moving it was the move command, but I tried
a copy command to copy the contents of a directory to another
directory and changing the name and that worked as well.

I do need to LOOK at the directory and file switching commands
I am very new to that.
3460.

Solve : my computer does not boot from my dvd?

Answer»

I've been trying to INSTALL windows 98 on my father in-laws computer which is a intel-700MHz processor but for some reason it will not BOOT from the dvd and so i formatted it with ms-dos 6.0 but now the ms-dos does not detect my dvd rom i have also tried to change the auto.bat file and the config.sys file but nothing seems to work. So i formatted it again and tried to install windows xp but now it won't boot the cd.You need to change the boot order in bios so the cd / dvd drive is the first boot device.I tried that and it still dos'nt work the problem is that the computer had windows xp on it and it kept and freezing up so I throught that it WOULD run better with windows 98 so I tried to install it but the windows xp sent a message that i had to install the windows 98 through ms-dos but the problem is windows xp dos'nt have dos so i restarted the computer with a setup disk from ms-dos 6.0 everything got formatted and i put the cd in from windows 98 but dos would not recognize the d: so i know with dos you need a driver for the cd/dvd drive but i don't have a driver on the floppy disk so I throught i would put the windows xp back in the computer but now it dos'nt boot any more from the cd/dvd drive and i changed the boot sequence in bios I am kinda stuck now do you have any ideas.

boogie manGet a LEGIT Win98 CD...they're all bootable.Quote from: patio on May 29, 2010, 08:12:48 PM

Get a legit Win98 CD...they're all bootable.

Only the windows 98 SE discs are. a good portion of the "first" edition discs are not bootable- legit or otherwise.

3461.

Solve : Search for permissions .sql files from all subdirectories?

Answer»

I'm working on a script that will find all .sql files in all subdirectories and find the permissions for a specific group. I have a BATCH that will CURRENTLY check all files in the CURRENT directory, but I need it to be able to search all subdirectories as well.

Code: [Select]@echo off
color 0A

rem Created by SCOTT Dean

if exist !Grants del "!Grants"
if not exist !Grants MKDIR !Grants

for %%I in (*.sql) do (
find /n /i "user_group" %%I >> !Grants/User_Grants.txt
find /n /i "tech_group" %%I >> !Grants/Tech_Grants.txt
find /n /i "config_group" %%I >> !Grants/Config_Grants.txt
find /n /i "readonly_group" %%I >> !Grants/ReadOnly_Grants.txt
find /n /i "GRANT" %%I | find /v /i "user_group" | find /v /i "tech_group" | find /v /i "config_group" | find /v /i "readonly_group" >> !Grants/Other_Grants.txt
echo 1 >> !Grants/i.txt
)

find /c "1" !Grants/i.txt > !Grants/i2.txt

for /F "tokens=3*" %%J in (!Grants/i2.txt) do (
echo %%J files checked >> !Grants/User_Grants.txt
echo %%J files checked >> !Grants/Tech_Grants.txt
echo %%J files checked >> !Grants/Config_Grants.txt
echo %%J files checked >> !Grants/ReadOnly_Grants.txt
)
del !Grants\i.txt /q
del !Grants\i2.txt /q
del !Grants.bat
This is the current batch I use and I will be modding it to search for a different group realtime_group. But I need it to look in current directory and all subdirectories.

Thanks.C:\test>type grim.bat
Code: [Select]@echo off

cd \

echo. > c:\tmp\sql.txt
for /f "delims=" %%i in ('dir /s /b *.sql') do (
echo %%~nxi >> c:\tmp\sql.txt
)
type c:\tmp\sql.txt
find /c /i "sql" c:\tmp\sql.txt
cd c:\test
Output:

C:\test>grim.bat

InstallCommon.sql
InstallMembership.sql
InstallPersistSqlState.sql
InstallPersonalization.sql
InstallProfile.SQL
InstallRoles.sql
InstallSqlState.sql
InstallSqlStateTemplate.sql
InstallWebEventSqlProvider.sql
UninstallCommon.sql
UninstallMembership.sql
UninstallPersistSqlState.sql
UninstallPersonalization.sql
UnInstallProfile.SQL

3462.

Solve : s bos dir?

Answer» HI i have a dos question. i have been USING windows so long i DONT remember anything.. i am booted in dos A:\ and see what i wnat in the dir [ncsmal~1] How do i OPEN it up? thanks pillsnpwd CD\ ncsmal~1
3463.

Solve : Many Questions on Copy/Replacing Files?

Answer»

Before I post, I just want to say I'm NEW here. I've made some EXTREMELY BASIC batch files a long time ago, so it's safe to say that I'm practically completely new at this. Please be extremely specific with me as I'll have difficulty understanding short forms.

My girlfriend and myself play an online game called "Fiesta". Recently they've done a few updates which changed the user interface (To be known as UI for the duration of this post). They informed the players that they could change the UI to whatever they wish, and they're provide a guide on how to later. Using the guide I figured out how to edit it and I reverted it to the previous UI. The file is a .tga file.

Now I won't be able to make it over to my girlfriends for some time so I was wanting to make her a batch file so I wouldn't have to walk her through replacing it. The batch file was to simply TAKE the new skin which she would download (Named Skin.tga) and replace the old skin (Same file NAME, different directory).

The file she would download's directory would be:
C:\Users\(Unknown, does this have to be known or is there a way to bypass this?)\Downloads\Skin.tga

and the file would need to replace the Skin.tga at this directory:
C:\Program Files (x86)\Outspark\Fiesta\Skin\Skin.tga

All I'm looking for is how to replace the files, if the full directory name is needed or if I can bypass that part, and if there's a way to have it replace the second file without knowing where the first file is saved to.

Much thanks in advance.Code: [Select]@echo off
copy %userprofile%\Downloads\Skin.tga %PROGRAMFILES(x86)%\\Outspark\Fiesta\Skin\Skin.tga /Y

3464.

Solve : Batch Animation!!!?

Answer»

Hi Dudes,

Ive Attached Ascii Art Here In Which An Minotaur Rips Off An Human's Head

I Was Thinking If Experts Could Just Create An ANIM Of It By Using Time Delay , Ping , Using Various Colours

Anim :: Minotaur Waving His Hand Up And Down With Humans Head
::Minotaur Laughing (Optional)

Well Me And My Friend Are TRYING To make An Batch Movie (Extremely Short)
Hence I Need This

===============
EDIT
===============

Fixed The Text File



[recovering disk space - old attachment DELETED by admin]possible with ANSI escape codes and ansi.sys. research ANSI ART.


for batch file:

draw your ascii art in 78*24 screens to prevent a carriage return at end-of-line. then, TYPE the screens one at a time with a CLS in between.

Code: [Select]@echo off
cls
type anim01.txt
cls
type anim02.txt
cls
type anim03.txt
cls
type anim04.txt
cls
type anim05.txt
cls
::
::
type anim??.txt
cls
No. You need to study ANSI Art. Look on Face Book
Ansi ART is on FacebookSorry But I Didnt Understand Look up all the ASCII character codes to get the symbols for "writing" ASCII Art(ANSI Art)
http://www.asciitable.com/

In the code you can use the PING command as a WAIT command to time the Animation:
Code: [Select]ping -n 1 -w <Millisecond Delay> 1.1.1.1
Code: [Select]ping -n 1 -w 5000 1.1.1.1This will time delay for 5 seconds(5000 miliseconds)

Follow tikbalang's advice about the code and the screen size(78 characters wide, 24 characters tall).

You can then include the PING command between type and cls:
Code: [Select]@echo off
cls
type anim01.txt
ping -n 1 -w 5000 1.1.1.1
cls
type anim02.txt
ping -n 1 -w 5000 1.1.1.1
cls
type animNN.txt
ping -n 1 -w 5000 1.1.1.1
cls

Hope this helps,
Nick(macdad-)

3465.

Solve : Promt for user input in autoexec.bat?

Answer»

Hello!
Im trying to make an autoexec which goal is to execute and ghostinstallation of windows xp.
That part I have got working but what I need is to give the user a warning that by using this ghost cd everything will be wiped out of the c drive and want to ask them if they are sure about this.

This is my code so far, i´ve TESTED with both set /p and choice so I will put both of them up here. Maybe some can come up with an answer what I am missing.

With the choice command:

@ECHO OFF
:start
cls
ECHO Are you sure that you want to install Windows?
ECHO 1=Install
ECHO 2=Quit
choice /N /C:12 To install press 1 OTHERWISE press 2 (1, 2)%1
IF ERRORLEVEL ==2 goto quit
IF ERRORLEVEL ==1 goto install
:install
cls
choice /N /C:12 Are you sure? 1=Yes 2=No (1, 2)%1
IF ERRORLEVEL ==2 goto quit
IF ERRORLEVEL ==1 goto reinstall
:reinstall
ECHO Whoho! It works!
pause
:quit
exit


With the set /p command: (This one works fine in win xp which it should...)

@echo off
cls
:start
ECHO.
ECHO 1. Install
ECHO 2. Exit Installation
set choice=
set /p choice=Press 1 to continue installation of Windows. Press 2 to exit installation.
if '%choice%'=='1' goto install
if '%choice%'=='2' goto quit
ECHO "%choice%" is not valid please try again.
ECHO.
goto start
:install
ECHO 1. Yes
ECHO 2. No
set question=
set /p question=Are you sure? 1/2.
if '%question%'=='1' goto ghost
if '%question%'=='2' goto quit
ECHO "%question%" is not a valid please try again.
goto install
:ghost
ECHO Whoho! It works!
pause
:quit
exit


I hope SOMEONE will have the time to look at it and maybe has the answer on what im doing wrong.

Best regards/ Petermaybe the fact of this
C:\>choice
Bad Command of filenameQuote from: mat123 on May 20, 2010, 07:36:10 AM

maybe the fact of this
C:\>choice
Bad Command of filename

Sorry I probably forgot to mention that it isnt in Windows XP i want to run this, but when booting up the computer...

Didnt know by the time I was writing this thread that the "set /p" command only works in windows but not in DOS.
So the last code example is not usable.

The code part using the "choice" command is for DOS and that is the code im having problem with.try it without
(1, 2)%1
replace
IF ERRORLEVEL == 2
ERRORLEVEL 2
etc.Quote from: mat123 on May 20, 2010, 07:55:20 AM
try it without
(1, 2)%1
replace
IF ERRORLEVEL == 2
ERRORLEVEL 2
etc.

Ok thanks I will trymat123 means

IF ERRORLEVEL 2 goto quit
IF ERRORLEVEL 1 goto install

etc

Quote from: Salmon Trout on May 20, 2010, 12:34:36 PM
mat123 means

IF ERRORLEVEL 2 goto quit
IF ERRORLEVEL 1 goto install

etc



Tried it and it didnt work. :/
Okay,
So now I´ve tried all of the possibilities I know of regarding this so I´ve have started on a new idea which I would like to hear thoughts about this idea of mine.

What about if I in "autoexec.bat" write a command which executes another program on the CD which then writes out the warning about reinstalling the computer with this ghost cd and promt the user for an input? If the user answers that it wants to run the ghost installation it executes the ghost installation from that program INSTEAD?

Is it possible to do so and if it is, which programming language is the easiest to learn to write such program?

Best regards/ PeterIn my opinion, VB6 is a viable option(Although you ought to look around to C++ and other programming languages for your "Programming-Style")

But before you goto that, Can you give us details about Autoexec:
  • The version of Windows it'll be running on(Not the ghost installation of XP).
  • Location of Autoexec

Thanks,
Nick(macdad-)
3466.

Solve : simple batch question?

Answer»

a simple question about batch:

NEED to write a .bat which references another file in the same dir as the batch. Do I have to give the whole dir STRING, or is there a possibility to "pass" the dir?

Example:
the FOLLOWING bat exsist in as: d:\dir1\mystart.bat

start C:\someprogram.exe d:\dir1\sameparameter.ini


This will not work for me:

start c:\someprogram.exe sameparameter.ini


It seems I have to 'pass in' the string
Any suggestion? Huh?Make sure you have quotations around the path, quotations better define seperations when CMD is parsing.

So basically try this:

Code: [Select]start "C:\someprog.exe" "sameparameter.ini"
Or just forget the start commmand and just type in the actually program path and parameters again with the quotations(Sometimes the Start command is a bit fussy..)

Code: [Select]"C:\someprog.exe" "d:\dir1\sameparameter.ini"
Usually when passing parameters, programs WANT a full path name, you can try and cut down on the code in your bat program by using the %CD% variable since the INI file is right there with your batch program:

Code: [Select]"C:\someprog.exe" "%CD%\sameparameter.ini"

Reply back with your findings.

3467.

Solve : set /p with a timer ??

Answer»

How can i do this? , I understand using choice.com can do this but its not what im looking for Set /P will wait until the return key is pressed - what did you want it to do ?
Sorry, What i ment to ask was how can i use set /p to create a pause with a timer like choice.com has is there anyway of doing this or possibly a third party program that does this ?That very long row of question marks looks really stupid.

The sleep.exe utility which is widely available will pause for a given number of seconds (some version do milliseconds as well). Plemty of hits on Google.


Quote

That very long row of question marks looks really stupid.
he is Free in the way of expression

Quote from: dnthns87 on May 11, 2010, 10:45:21 AM
Sorry, What i ment to ask was how can i use set /p to create a pause with a timer like choice.com has is there anyway of doing this or possibly a third party program that does this ?

http://www.westmesatech.com/editv.html

choose.exe, COMES in MS-DOS, Win32 and Win64 flavours.

Code: [Select]C:\>choose64 /?
Choose64 2.0 - (C) 2006-2009 by Bill Stewart ([emailprotected])

Allows selection of a choice from a LIST of choices.

Usage: Choose64 [-c choices] [-d x] [-l] [-n] [-p prompt] [-q] [-s] [-t x,n]

-c choices Specifies valid choices (default is 'YN').
-d x Choose 'x' if Enter is pressed.
-l Use line input mode (must press Enter after MAKING a choice).
-n Do not display the list of choices.
-p prompt Prompt the user with 'prompt' (enclose in quotes if it has spaces).
-q Do not display the choice that was selected (ignored with -l).
-s Choices are case sensitive.
-t x,n Choose 'x' automatically if no choice made within 'n' seconds.

Without -c, the default choices are 'YN' (or 'yn' with -s).
The program's exit code will be the position of the choice in the list.
If Ctrl-C is pressed, the exit code will be 255.Quote from: on May 11, 2010, 11:40:32 AM


, what did that post contribute to answering the OP's question?
Thanks, But let me be more clear on what i need.. choose.exe isnt what im looking for because its to similar to choice.com , sleep.exe isnt what i need because im not looking to just create a pause, Im looking for set /p with a timeout , for example:

:TOP
set an=&echo Whats your name?&set /p /TIME:XX an=-&IF NOT"%an%"=="%an%" (Goto loop) ELSE Goto TOP Quote from: dnthns87 on May 11, 2010, 12:47:46 PM
:TOP
set an=&echo Whats your name?&set /p /TIME:XX an=-&IF NOT"%an%"=="%an%" (Goto loop) ELSE Goto TOP
There is no time switch, also, you have the set syntax wrong.
:top
cls
echo What's your name?
Set /p name=
If not "%name%"=="something else" (goto loop) else (goto top)



Just saying, the following will always do the else command, so I don't know why you put it in your code:

IF NOT"%an%"=="%an%" (Goto loop) ELSE Goto TOP
i didnt really look at it, i just WROTE it quickly.. i understand that there is no time switch but set /p /time:xx is exactly what im looking for so a way to do that or a third party program that could do that would be awesomeQuote from: dnthns87 on May 11, 2010, 01:09:42 PM
i didnt really look at it, i just wrote it quickly.. i understand that there is no time switch but set /p /time:xx is exactly what im looking for so a way to do that or a third party program that could do that would be awesome

Look again on that page I linked to, at the features of Editvar. In particular, the timeout.
3468.

Solve : Help with Batch to generate an email?

Answer»

Hello,

To cut a long story short, I'm trying to create a batch that will generate an email but when i run the batch the body of the email is blank.

The code for the email i've got is below:
START mailto:[emailprotected]?subject=test&body=Hi%%0D%%0A%%0D%%0AThis%%20is%%20a%%20test

On the command prompt it brings up an error saying 'body' is not recognised. HOWEVER, if I take the 'subject=test' out of the code, it loads up the email with the body of the email. So it appears that it can't do both for some reason?

Can ANYONE help?Try:
START mailto:[emailprotected]?"subject=test&body=Hi%%0D%%0A%%0D%%0AThis%%20is%%20a%%20test"Thank you oldun, that works like a dream!

On a similar note, do you know how to make some of the text bold within the email? I have searched AROUND the net before posting this but cant find anything. ThanksQuote from: oldun on May 18, 2010, 07:18:34 PM

Try:
START mailto:[emailprotected]?"subject=test&body=Hi%%0D%%0A%%0D%%0AThis%%20is%%20a%%20test"


If the "maillto:" command is included in a batch file that is a scheduled task to run at 2AM, how will the email be SENT automatically without interaction with the user?



Quote from: marvinengland on May 21, 2010, 07:34:07 AM

If the "maillto:" command is included in a batch file that is a scheduled task to run at 2am, how will the email be sent automatically without interaction with the user?





The same way it was with the Original POST, where the only problem was the body was blank. I imagine they must be using a real E-mail client to handle the Mailto: protocol.
3469.

Solve : Takeown Fails with Access Denied?

Answer»

Hi,
I have some backup folders and files on a local network external drive that have an incorrect owner. The files were created with a .bat file using Robocopy.
The incorrect owner is:
nobody (Unix User\nobody)
The owner should be:
administrator (EXTERNALDRIVE\admin)

I have tried the following as administrator:
PROPERTIES > Security > Advanced > Owner > Edit > change owner to
I get access denied.

And with DOS from an administrator command prompt:
takeown /f S:\BackUp-Music\Recordings\AmbroseNew
I get access denied.

I can access the directory so my path must be correct:
dir S:\BackUp-Music\Recordings\AmbroseNew

Does anyone have a suggestion for me?
Thanks
Frank C
Vista Ultimate 64 bit SP2http://social.answers.microsoft.com/Forums/en-US/w7install/thread/4ced0f3f-3dbc-4f3c-9fb8-17115689b1e5


Click Start, type: CMD, right CMD > Click Run as Administrator > at the Command
Prompt, type > regedit > hit Enter >
go down to > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion >
to change the RegisteredOwner, simply double click it and enter yours,
do the same for Registered Organization
--------------------------------------------------------------------------------
Andre Da Costa http://adacosta.spaces.live.com http://www.activewin.com
Marked As Answer byShawn - Support Engineer Thursday, December 10, 2009 7:18 PM
________________________________

http://www.howtogeek.com/howto/windows-vista/quick-tip-change-the-registered-owner-in-windows/
Thanks for the reply Marvinengland,
I don't want to change the registered owner of the computer. I only need to change the owner of five folders and their contents on my local network external disk.
Quote from: FrankGC on May 10, 2010, 08:15:18 AM

Thanks for the reply Marvinengland,
I don't want to change the registered owner of the computer. I only need to change the owner of five folders and their contents on my local network external disk.



http://support.microsoft.com/kb/304040

http://support.microsoft.com/contactus/default.aspx?ws=support


( all the following information from the above site. )

"To turn Simple File Sharing on or off in Windows, follow these steps:
Double-click My Computer on the desktop.
On the Tools menu, click Folder Options.
Click the View tab, and then select the Use Simple File Sharing (Recommended) check box to turn on Simple File Sharing. (Clear this check box to turn off this feature.)
To view a video about how to turn Simple File Sharing on or off, click the Play button (Collapse this imageExpand this IMAGE) on the following Windows Media Player viewer:"
Thanks for the reply marvinengland,
I have Vista Ultimate 64 bit SP2.
I don't have :"Use Simple File Sharing (Recommended) check box to turn on Simple File Sharing"
Instead I have "Use Sharing Wizard (recommended" Should I deselect it (untick)? Your response seems to indicate that my DIFFICULTY arises from the FACT that my network drive an it's folders and files are SHARED. This is true. I recently tried to run takeown from a command prompt at boot time. This also failed with could not find the path.
Thanks
Frank Camp
3470.

Solve : Can a prompt for set /p be placed at the end of a line of text??

Answer»

In XP, the CHOICE COMMAND no longer exists. I have set /P.

I can't add EXTERNAL commands to the computer, so I'm stuck with the default.

With choice, I can have the prompt displayed at the end of a line of text.

Example:
Code: [SELECT]choice /c:qnp /n /m "Please choose- "
Can I get the exact same functionality using set /p in XP?You can do this

Code: [Select]set /p answer="Please choose- "
but you will not get the "exact same funcionality" since choice responds to a single key press but set /p responds to a string of zero or more characters plus ENTER.



3471.

Solve : compare two folders and find which files are not in both folders?

Answer»

Hi,

I am trying to find a way to compare two folders, for example;

folder a contents
a.txt
b.txt
C.txt

folder b contents
a.txt
c.txt

i need this to copy b.txt to folder b (this will be on a much larger scale, about 40,000 files)

for now what i have is

dir /b "c:\folder a" >> a.txt
dir /b "c:\folder b" >> b.txt

which i then need to compare somehow, find what is not in both and copy from one place to the other

any help would be great, i know i can just shift click no when it asks to replace, but this is going on many different PC's and over network so it would save me an enormous amount of time.


Thank you,
Khasiarc:\test>type kiacomp.bat

Code: [Select]@echo off
rem cd c:\test
rem md folderA
rem cd folderA
rem echo hello > a.txt
rem echo hello > b.txt
rem echo hello > c.txt
rem d c:\test
rem md folderB
rem cd folderB
rem echo hello > a.txt
rem echo hello > c.txt
rem cd c:\test

comp c:\test\folderA c:\test\folderB

Output:

c:\test>kiacomp.bat
Comparing C:\test\folderA\a.txt and C:\test\folderB\a.txt...
Files compare OK

Comparing C:\test\folderA\b.txt and C:\test\folderB\b.txt...
Can't find/open file: C:\test\folderB\b.txt

Comparing C:\test\folderA\c.txt and C:\test\folderB\c.txt...
Files compare OK

Compare more files (Y/N) ? n
c:\test>

so if the files do not compare would it allow me to make them equal?Quote from: Khasiar on May 17, 2010, 02:57:16 AM

so if the files do not compare would it allow me to make them equal?

yesQuote from: marvinengland on May 17, 2010, 03:53:57 AM
yes

how?

Quote from: Khasiar on May 17, 2010, 02:57:16 AM
so if the files do not compare would it allow me to make them equal?

The comp command will not help you to make the files and folders equal

You will manually need to modify the files.


C:\test>comp /?
Compares the contents of two files or sets of files.

COMP [data1] [DATA2] [/D] [/A] [/L] [/N=NUMBER] [/C] [/OFF[LINE]]

data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/D Displays differences in decimal format.
/A Displays differences in ASCII characters.
/L Displays line numbers for differences.
/N=number Compares only the first specified number of lines in each file.
/C Disregards case of ASCII letters when comparing files.
/OFF[liNE] Do not skip files with offline attribute set.

To compare sets of files, use wildcards in data1 and data2 parameters.

C:\test>so why did you write "yes"?
Quote from: Khasiar on May 12, 2010, 05:53:18 PM
I am trying to find a way to compare two folders

I'm sorry we have received no further suggestions of how to compare files and folders with batch commands or other methods.

Good LuckOK don't answer.

I am sorry the OP got such bad advice.
Quote from: marvinengland on May 17, 2010, 01:05:54 PM
I'm sorry we have received no further suggestions of how to compare files and folders with batch commands or other methods.

Good Luck

Khasiar ,

Are no suggestions better than the suggestions I offered? My suggestions hurt no one. And many readers
benefited from this thread.

Khasiar ,
Thanks for your questions.

Please don't allow negative comments from members who have no suggestions discourage questions in the future.Quote
members who have no suggestions

Ouch!

Code: [Select]@echo off
for /f "delims=" %%F in ( ' dir /b "folder1" ' ) do (
if not exist "folder2\%%F" copy "folder1\%%F" "folder2" && echo COPIED %%F
)

Quote from: Khasiar on May 12, 2010, 05:53:18 PM
Hi,

I am trying to find a way to compare two folders, for example;

folder a contents
a.txt
b.txt
c.txt

folder b contents
a.txt
c.txt

i need this to copy b.txt to folder b (this will be on a much larger scale, about 40,000 files)

for now what i have is

dir /b "c:\folder a" >> a.txt
dir /b "c:\folder b" >> b.txt

which i then need to compare somehow, find what is not in both and copy from one place to the other

any help would be great, i know i can just shift click no when it asks to replace, but this is going on many different PC's and over network so it would save me an enormous amount of time.


Thank you,
Khasiar

I think you want both folders to have the same content.
You can do that in a rather complicated batch file.
Or just use some utilities that just do that.
One of many is the Sync Toy from Microsoft.
Or study how the XCOPY command works.
Do XCOPY /? at the command prompt.Quote from: Geek-9pm on May 17, 2010, 07:30:51 PM
I think you want both folders to have the same content.
You can do that in a rather complicated batch file.
Or just use some utilities that just do that.
One of many is the Sync Toy from Microsoft.
Or study how the XCOPY command works.
Do XCOPY /? at the command prompt.

The comp command shows where the problem is and xcopy will correct the problem.


C:\>comp /?
Compares the contents of two files or sets of files.

COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[liNE]]

data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/D Displays differences in decimal format.
/A Displays differences in ASCII characters.
/L Displays line numbers for differences.
/N=number Compares only the first specified number of lines in each file.
/C Disregards case of ASCII letters when comparing files.
/OFF[liNE] Do not skip files with offline attribute set.

To compare sets of files, use wildcards in data1 and data2 parameters.

C:\>

Thanks marvinengland and Salmon Trout,


Both your ways work but Marvinengland, Salmon Trouts way is much easier so ill stick with that thanks again guys.Quote from: marvinengland on May 17, 2010, 09:09:06 PM
The comp command shows where the problem is and xcopy will correct the problem.


And how would you use them together, exactly? and why use comp instead of fc?
3472.

Solve : Command to count number of files in directory called %username% to variable?

Answer»

Hi,

We have a directory of login logs for when users log in, part of the name being the username of the person logged on.

I'm trying to troubleshoot why certain logs are not being written.

if I use forfiles.exe and forfiles -PC:\temp\logs -d+1 -m*%username% I get a list of files for a user in the last day.

I wanted to get this as a count of number of files it finds in a variable, not just a list of them

Any ideas?

Thanks, SukhQuote from: skhudy on May 24, 2010, 07:16:20 AM



If I use forfiles.exe and forfiles -pc:\temp\logs -d+1 -m*%username% I get a list of files for a user in the last day.

I wanted to get this as a count of number of files it finds in a variable, not just a list of them


______________________________


c:\temp\logs>TYPE sk.bat
@echo off

Code: [Select]forfiles /p c:\temp\logs /m %username%* | FIND /c /v "" > filecount.txt

echo type filecount.txt

type filecount.txt
Output:c:\temp\logs>sk.bat
type filecount.txt
3

c:\temp\logs>Quote from: skhudy on May 24, 2010, 07:16:20 AM
if I use forfiles.exe and forfiles -pc:\temp\logs -d+1 -m*%username% I get a list of files for a user in the last day.

I wanted to get this as a count of number of files it finds in a variable, not just a list of them


The above post did not assign the count to a variable. Also, the count was 3 and should be 2.


c:\test>type sk.bat
@echo off

forfiles /p c:\temp\logs /m %username%* | find /c /v "" > filecount.txt

set /p var=set /a var=%var% - 1
echo var=%var%

Output:

c:\test> sk.bat
var=2

c:\test>Quote from: skhudy on May 24, 2010, 07:16:20 AM

if I use forfiles.exe and forfiles -pc:\temp\logs -d+1 -m*%username% I get a list of files for a user in the last day.



c:\test>type sk2.bat
@echo off

forfiles /p c:\temp\logs /m %username%*

forfiles /p c:\temp\logs /m %username%* | wc -l > filecount.txt

set /p var=set /a var=%var% - 1
echo var=%var%

Output:

c:\test>sk2.bat

"marvin.txt"
"marvin.txt"
var=2

c:\test>Quote from: skhudy on May 24, 2010, 07:16:20 AM

if I use forfiles.exe and forfiles -pc:\temp\logs -d+1 -m*%username% I get a list of files for a user in the last day.

I wanted to get this as a count of number of files it finds in a variable, not just a list of them


c:\test>type sk3.bat
Code: [Select]@echo off

forfiles /p c:\temp\logs /m %username%*

forfiles /p c:\temp\logs /m %username%* | wc -l > filecount.txt

set /p var=<filecount.txt
set /a var=%var% - 1
echo var=%var%

cd c:\temp\logs

dir /OD /A-D %username%*

dir /OD /A-D %username%* | findstr %username% | wc -l > count2.txt
set /p var2=<count2.txt

echo var2=%var2%

cd c:\test\

Output:

c:\test>sk3.bat

"marvin1.txt"
"marvin2.txt"
var=2
Volume in DRIVE C has no label.
Volume Serial Number is 0652-E41D

Directory of c:\temp\logs

05/24/2010 01:09 PM 8 marvin2.txt
05/24/2010 01:09 PM 8 marvin1.txt
2 File(s) 16 bytes
0 Dir(s) 295,916,421,120 bytes free
var2=2
c:\test>
3473.

Solve : I need help creating a batch file!?

Answer»

I'm new here but ANYWAY, I need help creating a batch file that creates a folder in the root of the C drive with the same
name as the computer. The script should run the Gpresult.exe program for the Administrator User and the computer scope
and send RSoP data output to a file name Gpresult.txt in the directory it was created.

This was given to me as a H/W assignment at my school lol but I seriously need some help.
I'm thinking doing stuff with ns, but with ns the only thing I know how to do is set up
a network drive. C:\&GT;type winturbo.bat

Code: [Select]@echo off

cd \
md %COMPUTERNAME%

cd %COMPUTERNAME%

Gpresult /R > Gpresult.txt

type Gpresult.txt


Output:

C:\>winturbo.bat

Microsoft (R) Windows (R) Operating System Group Policy Result tool v2.0
Copyright (C) Microsoft Corp. 1981-2001

Created On 5/12/2010 at 12:05:13 AM


RSOP data for Marvin : Logging Mode
-----------------------------------------------------

OS Configuration: Standalone Workstation
OS Version: 6.1.7600
Site Name: N/A
Roaming Profile: N/A
Local Profile: C:\Users\Marvinl
Connected over a slow link?: No


COMPUTER SETTINGS
------------------

Last time Group Policy was applied: 5/11/2010 at 11:36:44 PM

Group Policy slow link threshold: 500 kbps
Domain Name: 37L4247D28-05
Domain Type: WindowsNT 4


The following GPOs were not applied because they were filtered out
-------------------------------------------------------------------
Local Group Policy

The computer is a part of the following security groups
-------------------------------------------------------
System Mandatory Level


This Organization
BITS
CertPropSvc
EapHost
hkmsvc
IKEEXT
iphlpsvc
LanmanServer
MMCSS
MSiSCSI
RasAuto
RasMan
RemoteAccess
Schedule
SCPolicySvc
SENS
SessionEnv
SharedAccess
ShellHWDetection
wercplsupport
Winmgmt
wuauserv
LOCAL


USER SETTINGS
--------------

Last time Group Policy was applied: 5/11/2010 at 11:37:02 PM
Group Policy was applied from: N/A
Group Policy slow link threshold: 500 kbps
Domain Name: MarvinPC
Domain Type:

Applied Group Policy Objects
-----------------------------
N/A

The following GPOs were not applied because they were filtered out
-------------------------------------------------------------------
Local Group Policy
Filtering: Not Applied (Empty)

The user is a part of the following security groups
---------------------------------------------------
None
Everyone
This Organization

C:\MarvinPC>Quote from: Twinturbo120 on May 11, 2010, 09:33:59 PM

This was given to me as a H/W assignment at my school lol but I seriously need some help.

When you turn in WORK done by someone else your tutor may believe that you UNDERSTOOD the assignment and do not need any further assistance. This won't be good when you come to an exam environment when there's no-one to do your work for you. Any assistance with homework should come from your tutor.

Welcome to the CHope forums where an unwritten rule is that we may ADVISE where to get the required information but we shy away from doing homework for anyone.

Quote from: marvinengland on May 11, 2010, 11:08:35 PM
C:\>type winturbo.bat

Code: [Select]@echo off

cd \
md %COMPUTERNAME%

cd %COMPUTERNAME%

Gpresult /R > Gpresult.txt

type Gpresult.txt


Output:

C:\>winturbo.bat

Microsoft (R) Windows (R) Operating System Group Policy Result tool v2.0
Copyright (C) Microsoft Corp. 1981-2001

Created On 5/12/2010 at 12:05:13 AM


RSOP data for Marvin : Logging Mode
-----------------------------------------------------

OS Configuration: Standalone Workstation
OS Version: 6.1.7600
Site Name: N/A
Roaming Profile: N/A
Local Profile: C:\Users\Marvinl
Connected over a slow link?: No


COMPUTER SETTINGS
------------------

Last time Group Policy was applied: 5/11/2010 at 11:36:44 PM

Group Policy slow link threshold: 500 kbps
Domain Name: 37L4247D28-05
Domain Type: WindowsNT 4


The following GPOs were not applied because they were filtered out
-------------------------------------------------------------------
Local Group Policy

The computer is a part of the following security groups
-------------------------------------------------------
System Mandatory Level


This Organization
BITS
CertPropSvc
EapHost
hkmsvc
IKEEXT
iphlpsvc
LanmanServer
MMCSS
MSiSCSI
RasAuto
RasMan
RemoteAccess
Schedule
SCPolicySvc
SENS
SessionEnv
SharedAccess
ShellHWDetection
wercplsupport
Winmgmt
wuauserv
LOCAL


USER SETTINGS
--------------

Last time Group Policy was applied: 5/11/2010 at 11:37:02 PM
Group Policy was applied from: N/A
Group Policy slow link threshold: 500 kbps
Domain Name: MarvinPC
Domain Type: <Local Computer>

Applied Group Policy Objects
-----------------------------
N/A

The following GPOs were not applied because they were filtered out
-------------------------------------------------------------------
Local Group Policy
Filtering: Not Applied (Empty)

The user is a part of the following security groups
---------------------------------------------------
None
Everyone
This Organization

C:\MarvinPC>

Wow thank you sir for your kind help much appreciated!
3474.

Solve : How to capture batch file error msg's??

Answer»

So in my batch file, I can capture the errorlevel (the error number), but the system is also outputting it's own error msg to the user, how do I capture that msg?

OS: Windows 2003 Server

Here is what I get when I run the batch file (I know what's causing it, I just want to log the msg I get back when it's run)

Code: [Select]D:\>cm_build.bat
System error 1219 has occurred.

Multiple connections to a server or shared resource by the same user, using more
than one user name, are not allowed. Disconnect all previous connections to the
server or shared resource and try again..
Here is what I get in the Logfile:

Code: [Select]------------------------------------------------
-- Batch Ran on Tue 05/11/2010 at 8:57:05.97 --
------------------------------------------------
Error: Tue 05/11/2010 at 8:57:06.12
Error Location: UnMapped
Error Msg: error during mapping, Error Number: 2

Here's a snippet of the code:

Code: [Select]@echo off
set logLocation="d:\BuildLogs.txt"
set deletedFoldersList="deletedfolders.txt"

echo ------------------------------------------------ >> %logLocation%
echo -- Batch Ran on %date% at %time% -- >> %logLocation%
echo ------------------------------------------------ >> %logLocation%

for /f "tokens=2-3" %%i in ('net use ^| find /i "Z:"') do (
IF %ERRORLEVEL% EQU 0 (
set local=%%i
set remote=%%j
goto :successfulRun
) ELSE (
goto :UnMapped
)
)

:UnMapped
echo unmapped >> %logLocation%
net use Z: \\a_drive\a_directory /USER:username password
IF %ERRORLEVEL% NEQ 0 (
set errorLoc=UnMapped
set errorMsg=error during mapping, Error Number: %ERRORLEVEL%
goto :errorFound
)
goto :successfulRun


:successfulRun
echo -- Batch run completed SUCCESSFULLY on %date% at %time% -- >> %logLocation%
goto :eof

:errorFound
echo Error: %date% at %time% >> %logLocation%
echo Error Location: %errorLoc% >> %logLocation%
echo Error Msg: %errorMsg% >> %logLocation%
goto :eof

So I'm curious if there's a way to put that system msg from the dos prompt:

System error 1219 has occurred.

Multiple connections to a server or shared resource by the same user, using more
than one user name, are not allowed. Disconnect all previous connections to the
server or shared resource and try again..

into the log files? Being able to do caputer the dos system messages will go a long way in helping me to DEBUG this batch file when it's run from scheduled tasks while the user is logged off.

Thx!yes, it is more than possible, it is easy!
the redirection symbol takes screen output and puts it into a file, eg
Code: [Select]net use Z: \\a_drive\a_directory /USER:username password>logfile
the single > will blank out the current contents of the file, using >> will append it to the end.

The End

Well, not quite, sometimes you cannot redirect the output like this because it is sent via the stderr channel, there is a fix for this, quote the channel number
Code: [Select]net use Z: \\a_drive\a_directory /USER:username password 2>logfileI havent used the redirection of the error channel, so I am not sure if 2>>logfile would work! (if it doesnt, then use 2> to redirect to a temp file and append the temp file to your logfile)

this is a useful resource http://ss64.com/nt/syntax-redirection.htmlQuote from: gpl on May 11, 2010, 09:15:09 AM

yes, it is more than possible, it is easy!
the redirection symbol takes screen output and puts it into a file, eg
Code: [Select]net use Z: \\a_drive\a_directory /USER:username password>logfile
the single > will blank out the current contents of the file, using >> will append it to the end.

The End

Well, not quite, sometimes you cannot redirect the output like this because it is sent via the stderr channel, there is a fix for this, quote the channel number
Code: [Select]net use Z: \\a_drive\a_directory /USER:username password 2>logfileI havent used the redirection of the error channel, so I am not sure if 2>>logfile would work! (if it doesnt, then use 2> to redirect to a temp file and append the temp file to your logfile)

this is a useful resource http://ss64.com/nt/syntax-redirection.html

Yea, I had tried

Code: [Select]net use Z: \\a_drive\a_directory /USER:username password>>logfile
which didn't work. I didn't think about trying 2>> (actually didn't even know what 2> did until now), so I just did that one and it worked, even with >> :-)

Code: [Select]net use Z: \\a_drive\a_directory /USER:username password 2>>logfile
Thank you! :-)

Glad it was an easy change. Thanks for the link too, that'll come in handy for sure.Thank you for the confirmation of 2>> - I thought it might work but had had no reason to try it before.

That site has many very useful examples of batch usageBy default, batch sees > (or >>) as 1> (or 1>>). That is what you see on screen as normal messages, 2> or 2>> will output error messages.Quote from: Helpmeh on May 11, 2010, 12:57:46 PM
By default, batch sees > (or >>) as 1> (or 1>>). That is what you see on screen as normal messages, 2> or 2>> will output error messages.
1 is the standard output stream.
2 is the standard error stream.

>,>> , <, and | can have a stream number prefixed to them. for example, if you use:

program.exe 2>&1 | program2.exe

then the standard error and standard output of program.exewill both be piped to program2 as it's standard input.
Quote from: BC_Programmer on May 11, 2010, 08:24:32 PM
program.exe 2>&1 | program2.exe


Why the &1, what does that do?Quote from: Panthers_Den on May 12, 2010, 05:40:15 AM
Why the &1, what does that do?

For the answer to that and any other questions about redirection, check out this article

Quote from: Sidewinder on May 12, 2010, 10:30:41 AM
For the answer to that and any other questions about redirection, check out this article



oh that's a helpful article, thanks
3475.

Solve : Shift command?

Answer»

Win XP SP.3

Can the Shift command be used when setting environment variables in the command environment from the LOCAL environment? A code snippet is shown below and I'd like to Shift the variables, if that is possible, instead of using the SET command underlined===== I've tried various combinations without success.

I have attached the full script and emphasize that this is a work-in-progress, at this time I only need INFORMATION about Shift(ing).

Thanks guys.

Code: [Select]:: Calculate elapsed time
call :Elapsed %StartHour% %StartMins% %StartSecs% %StopHour% %StopMins% ^
%StopSecs% Hours Minutes Seconds


:: Calculate elapsed time and set environment variables in the command
:: shell environment
:Elapsed
setlocal
set /a ElapsedSecs=3600*%4+60*%5+%6-(3600*%1+60*%2+%3)
if %ElapsedSecs% LSS 0 set /a ElapsedSecs=%ElapsedSecs%+24*3600
set /a h=(%ElapsedSecs%/3600)
set /a m=(%ElapsedSecs%/60)-60*%h%
set /a s=%ElapsedSecs%-60*(%ElapsedSecs%/60)
endlocal&set %7=%h%&set %8=%m%&set %9=%s%&set Elsecs=%ElapsedSecs%&goto :EOF
:: ================

[recovering disk space - old attachment deleted by admin]shift replaces %1 with %2 etc
not variblesThe shift command. It is used to process a list of items where you process a few items from left end of the list and then you do a shift and process a few more items and do a shift in process a few more items and so on.
I don't know that this will help or not. Here is a very simple shift that is only for the purpose of showing what the shift does.

Code: [Select]set AA=one
set BB=two
set CC=three
set DD=four
CALL :SEEME %AA% %BB% %CC% %DD%
GOTO END
:SEEME
ECHO %1 %2
SHIFT
ECHO %1 %2
SHIFT
ECHO %1 %2
:END
Quote from: Valerie

....I'd like to Shift the variables....

Quote from: Mat123
shift replaces %1 with %2 etc not varibles

Correct Mat123, I should have said "I'd like to change the position of command line parameters....". I hope others are not confused by my misuse of terminology.

Geek-9pm - Thank you for the demo.

V.
3476.

Solve : endless loop?

Answer»

how to create an ENDLESS loop

I tried this but not working
Quote

@echo off
set j=2
for /L %%i IN ( 1,1,%j% ) DO (

echo %%i %j%
set /A j = !j!+1
)
even the variable j does not seem to be incrementing @echo off
set j=2
for /L %%i IN ( 1,1,%j% ) DO (

echo %%i %j%
set /A j = !j!+1
)
Try replacing the % with ! where noted.I think there is a BIT of confusion here...

1. If you want to CHANGE a variable in a loop, yes, you have to use exclamation marks ("exclamation points" in some places) but first you have switch on delayed expansion with this line

setlocal enabledelayed expansion

2. In any case both of you have misunderstood an important point. At run time, when cmd.exe processes the FOR line, it expands the %j% variable into its value at that time, that is, the line is expanded to

for /L %%i IN ( 1,1,2 ) DO etc

and the value 2 is STORED in memory as the loop count limit. Whatever you do later to the variable j in the loop will not affect this. The FOR command does not check the value of %j% (or even !j!) each time round the loop. Therefore the loop will run exactly 2 times. %%A will successively store 1 and then 2 and then the loop will finish. %j% will always be 2.

In this code...


@echo off
set j=2
for /L %%i IN ( 1,1,%j% ) DO (
echo %%i %j%
set /A j = !j!+1
)


...the variable %j% uses percent signs, there is no delayed expansion, the set /a command has no effect, and therefore %j% stays at 2

in this code...


@echo off
setlocal enabledelayedexpansion
set j=2
for /L %%i IN ( 1,1,%j% ) DO (

echo %%i !j!
set /A j = !j!+1
)


...the variable !j! is an exclamation-mark variable, delayed expansion is enabled, so that the set /a command is able to add 1, so the first time around the loop, !j! equals 2, and the second time around the loop, !j! equals 3, and as I showed above, FOR does not care what you do to !j! in the loop.

If you want an infinite loop, you can use a label and GOTO LIKE this...


set j=2
:loop
echo j=%j%
set /a j=%j%+1
goto loop


Terminate with CTRL-C









Quote from: Bukhari1986 on May 23, 2010, 03:42:01 AM
how to create an endless loop

I tried this but not working even the variable j does not seem to be incrementing


C:\test>type buk3.bat
Code: [Select]@echo off
setlocal enabledelayedexpansion
:begin
set /a j=2
for /L %%i IN ( 1,1,%1 ) DO (

echo i=%%i
set /A j=!j! + 1
echo j=!j!
)
goto begin

Output:

C:\test>buk3.bat 10

i=1
j=3
i=2
j=4
i=3
j=5
i=4
j=6
i=5
j=7
i=6
j=8
i=7
j=9
i=8
j=10
i=9
j=11
i=10
j=12
i=1
j=3
i=2
j=4
i=3
j=5
i=4
j=6
i=5
j=7
i=6
j=8
i=7
j=9
i=8
j=10
i=9
j=11
i=10
j=12
i=1
j=3
^Ci=2
j=4
Terminate batch job (Y/N)? y

C:\test>

Thanks
Salmon Trout


Thanks
marvinengland

THANKS A LOT

.
3477.

Solve : Move files recursively from source to destination that are older than 15 days?

Answer»

Hi -

I have a requirement to move files from source location(recursively) to destination(mapped drive) that are older than 15 days from current date


folder structure in both source and destinatin is similar

Please helpQuote from: nirasmar on May 12, 2010, 03:34:48 PM


I have a requirement to move files from source location(recursively) to destination(mapped drive) that are older than 15 days from current date



The following code is only a start. I have tried to list the files that are older than 15 days with the forfiles command.

The code needs a lot of work but might help to get you started.

Good Luck
_______________________________________ __


C:\test>type mira.bat
Code: [SELECT]@echo off

FORFILES /D -15 /M *.* > old15.txt

echo. > old15days.txt

for /f "delims=" %%i in (old15.txt) do echo %%~i >> old15days.txt

for /f "delims=" %%i in (old15days.txt) do echo %%i
Output:


C:\test>mira.bat
buildlog.bat
chtoE.bat
cmpfil.bat
cmplist.bat
evaluate.vbs
fil.bat
helpme.bat
matt.bat
matt2.bat
matt3.bat
matt4.bat
matt5.bat
ver6.txt
ver61.bat
ver612.bat
x.bat
yesterday.bat

C:\test> type count.txt
03/04/2009 12:26 PM 41 evaluate.vbs
01/01/2010 11:33 AM 187 yesterday.bat
04/24/2010 02:39 PM 1,018 buildlog.bat
04/24/2010 02:39 PM 1,018 x.bat
04/24/2010 06:37 PM 199 matt.bat
04/25/2010 11:27 AM 260 matt2.bat
04/25/2010 11:27 AM 260 matt5.bat
04/25/2010 11:34 AM 307 matt3.bat
04/25/2010 11:41 AM 224 matt4.bat
04/25/2010 02:07 PM 38 ver6.txt
04/25/2010 02:17 PM 125 ver61.bat
04/25/2010 02:33 PM 190 ver612.bat
04/25/2010 05:14 PM 235 helpme.bat
04/27/2010 12:06 PM 32 chtoE.bat
04/27/2010 07:33 PM 89 fil.bat
04/27/2010 09:52 PM 631 cmpfil.bat
04/27/2010 10:18 PM 698 cmplist.bat
C:\test>
3478.

Solve : Stylish Name In Batch?

Answer»

See This After Replacing 1.1.1.1 To 127.0.0.1 Its Not Working

Code: [Select]@echo off
Title The God Slayer with art
color 0e
PING 127.0.0.1 -n 1 -w 400 >NUL
echo ,.,
PING 127.0.0.1 -n 1 -w 400 >NUL
echo T ___,---.__ / \ __,---,___ T
PING 127.0.0.1 -n 1 -w 400 >NUL
echo H ,-' \` `-.____,-' ² `-.____,-' // `-. H
PING 127.0.0.1 -n 1 -w 400 >NUL
echo E ,' I ~'\ /`~ I `. E
PING 127.0.0.1 -n 1 -w 400 >NUL
echo / ___// `. ,' , , \___ \
PING 127.0.0.1 -n 1 -w 400 >NUL
echo G I ,-' `-.__ _ I , __,-' `-. I G
PING 127.0.0.1 -n 1 -w 400 >NUL
echo O I / /\° ` . I , °/\ \ I O
PING 127.0.0.1 -n 1 -w 400 >NUL
echo D \ I \ \°°.°°° \ I / °°° °°/ / I / D
PING 127.0.0.1 -n 1 -w 400 >NUL
echo \ \ I `.°ÛÛÛ°\\ I //°ÛÛÛ° I / /
PING 127.0.0.1 -n 1 -w 400 >NUL
echo S `-.\ /' _ °°°°'' , . `°°°° _ `\ /,-' S
PING 127.0.0.1 -n 1 -w 400 >NUL
echo L `` / \ ,='/ \`=. / \ '' L
PING 127.0.0.1 -n 1 -w 400 >NUL
echo A I__ /I\_,--.,-.--,--._/I\ __I A
PING 127.0.0.1 -n 1 -w 400 >NUL
echo Y / `./ \\`\ \ I / /,//' \,' \ Y
PING 127.0.0.1 -n 1 -w 400 >NUL
echo E / / \I--+--I----/-I \ \ E
PING 127.0.0.1 -n 1 -w 400 >NUL
echo R I I /'\_\_\ I /_/_/`\ I I R
PING 127.0.0.1 -n 1 -w 400 >NUL
echo \ \__, \_ `~' _/ .__/ /
PING 127.0.0.1 -n 1 -w 400 >NUL
echo `-._,-' `-._______,-' `-._,-'
echo.
echo.
echo.
PING 127.0.0.1 -n 1 -w 200 >NUL
color C0
PING 127.0.0.1 -n 1 -w 200 >NUL
color 0C
PING 127.0.0.1 -n 1 -w 200 >NUL
color C0
PING 127.0.0.1 -n 1 -w 200 >NUL
color 0C
PING 127.0.0.1 -n 1 -w 200 >NUL
color C0
PING 127.0.0.1 -n 1 -w 200 >NUL
color 0C
PING 127.0.0.1 -n 1 -w 200 >NUL
color C0
PING 127.0.0.1 -n 1 -w 200 >NUL
color 0C
PAUSEI used ping -n 2 127.0.0.1 >NUL on these.

Here are the same SAMPLES with the new ping

[recovering disk space - old attachment deleted by admin]faster sample with color change.bat Is Not Working (Process Completes Within 1 Sec)

Sample.bat Is WORKING Well Yea, I set it to go faster.

If you want it slower, replace
ping -n 1 with ping -n 2. Thanx 4 The Try But..
Dude Its Tooooooo SlowQuote

One Question

If I Use 1.1.1.1 As IP In That Batch A PC On Which INTERNET Is Not Available; Would It Be Able To Run It

Reply My This Post To Put An Solution To This TopicI've used the ping in the original samples for the last 8 years. I've never had any problems with it. I'm connected to a network now running XP Pro - SP-3.

However, with all of the Anti-VIRUS programs and the newer versions of windows constantly trying to police the internet, it could cause a problem.

You could use the original and if it didn't work for everyone, then look for a solution.Quote
it could cause a problem

1] In What Manner ?

Means What Type Of Problem Virus Or Something Like That

And U Didnt Answer My Question

2] If The Batch Containing IP As 1.1.1.1 Is Executed On A PC Without Internet , Will The Batch Run ? Will It Cause Any Problem

IF : Yes It Will Run Without Any Problem - Than Thats The Solution

IF No : Then Please Give Any Other IP That Will Not Go Out Of NetworkQuote
1] In What Manner ?

Means What Type Of Problem Virus Or Something Like That

And U Didnt Answer My Question

I didn't answer with a yes or no because it isn't that simple.
Everyone has different versions of windows with different versions of AV software.
Some settings may TAKE it as a virus. (It is called a false postive). What I wrote for you is not a virus, the application you intend to run with it, I can't say.


Quote
2] If The Batch Containing IP As 1.1.1.1 Is Executed On A PC Without Internet , Will The Batch Run ? Will It Cause Any Problem

Of course it will, without problems.Thanx For The Help All Of You Who Tried To Solve



(Special Thanx To Salmon , Hope You're Reading It )



3479.

Solve : Delete File With Ping Command ??

Answer»

Hi Friends

I Recently Came Across A Batch File In Which Some Files Were Deleted With
PING Command

The Command Line Was SOMETHING ping -127.1 Or Something Like That
(I ve lost That Batch File While Formatting )

Is It Possible Or My Eyes Were Eating GRASS ive never HEARD of it, ping 127.1.1.1 is your LOCAL machine, it could of had a delete function WITHIN the batch file but the ping itself would not have deleted the filedoesn't exist. Ping sends ICMP packets. ICMP packets are either echoed, or ignored by the receiving machine. it doesn't cause files to be deleted.Quote

doesn't cause files to be deleted

Let Me Give An Example BC

If Some1 Had Downloaded Bioshock 2 rip by Freeman g ripper :Ive Downloaded It For Educational Purposes (The Batch File In Rip > It Contains A Lot Of Knowledge )

It Also Had Uninstaller.bat Which Contained These Commands , I Ran Them And It Uninstalled The Game Files And Erased It From Registry

I Still Dont Remember Its Command Line But It Was Still Like "ping -127.1....." Something Like That We don't assist with Warez here...
This has been mentioned to you before.

Topic Closed.
3480.

Solve : Capturing TIMEIT.EXE Output To A Text File?

Answer»

I know this sounds relatively simple but it turns out it isn’t for me.

Here is one of the command line commands I have tried.


c:\timeit xcopy a.txt b.txt > test.txt


I had expected the following to be in the output file.

(BEGIN)

Version Number: Windows NT 5.1 (Build 2600)
Exit Time: 2:23 pm, Wednesday, January 30 2008
Elapsed Time: 0:00:10.860
Process Time: 0:00:00.046
System Calls: 227519
Context Switches: 109458
Page Faults: 4909
Bytes Read: 103812
Bytes Written: 156129
Bytes Other: 298850

(END)

Instead I have this.

(BEGIN)

C:a.txt
1 File(s) copied

(END)

Apparently I am capturing the output of the xcopy command and not timeit. I have tried various combinations of pipes and redirections to no avail. Any ideas?

try this
> test.txt c:\timeit xcopy a.txt b.txt

if that doesnt work, do this

> test.txt cmd c:\timeit xcopy a.txt b.txt
which opens up a new command shell and executes your command within that, the WHOLE lot being redirected to a file ... it might be simpler if you put the SE commands into a .bat file
c:\timeit xcopy a.txt b.txt

call it mybatch.bat,
then do this
> test.txt cmd mybatch

Graham
> test.txt c:\timeit xcopy a.txt b.txt

The text file still contains the output of xcopy and not timeit.


> test.txt cmd c:\timeit xcopy a.txt b.txt

Adding "cmd" hangs it.


> test.txt cmd mybatch

Hangs. It appears any lines that include "cmd" hang for some reason. Without the "cmd", it runs, but again it captures the xcopy output and not the timeit output.

It is as if the output of timeit is sent directly to the screen rather than letting the shell handle it.

Using timeit.exe was my second attempt. My first was to use "time /t > test.txt" on a line before the xcopy command and "time /t >> test.txt" after the xcopy command to obtain the start and finish time, but unlike my memory of the "time" command in earlier DOS implementations, the maximum resolution is in minutes, e.g. 1:23 PM. I need a resolution in at least whole seconds but to a tenth would be better e.g. 1:23:45 PM or 1:23:45.6 PM
It's very possible that timeit is not using the STDOUT device.

Code: [Select]echo. | time > time.txt
xcopy
echo. | time >> time.txt


Precision is .01 seconds

The output isn't very pretty since it echos the request for a new time. but it works and that is all that matters.

I assumed I needed the "/t" or it would hang, which as I recall it did with just "time > test.txt" but you have proved that doesn't have to be the case in all instances.

Thanks for your help.
This worked for me... Seems that the timeit.exe uses the normal error level 2 to output it's results.

c:\timeit xcopy a.txt b.txt 2> test.tmp

~~~~~
rog

C:\test>timeit.exe "sleep 60"

Version Number: Windows NT 6.1 (Build 7600)
Exit Time: 5:15 pm, Friday, May 21 2010
Elapsed Time: 0:01:00.013
Process Time: 0:00:00.000
System Calls: 12804
Context Switches: 10368
Page Faults: 1342
Bytes Read: 16679
Bytes Written: 9790
Bytes Other: 9484

C:\test>

_________________________

C:\test>timeit.exe sleep 60 2> test.txt

C:\test>type test.txt

Version Number: Windows NT 6.1 (Build 7600)
Exit Time: 5:33 pm, Friday, May 21 2010
Elapsed Time: 0:01:00.013
Process Time: 0:00:00.000
System Calls: 14938
Context Switches: 11090
Page Faults: 1100
Bytes Read: 16715
Bytes Written: 512
Bytes Other: 5692

C:\test>why did rogs revive a thread which is nearly two and a half years old?Quote from: rogs on May 21, 2010, 01:40:04 PM

This worked for me... Seems that the timeit.exe uses the normal error level 2 to output it's results.

c:\timeit xcopy a.txt b.txt 2> test.tmp


rog


Rog,

Thanks for reviving good questions and solutions from the archive. Many new members and readers have not used timeit.exe before now.

____________________

p.s. Some ideas are always relevant. We still read and agree with what Jesus said many years ago.Quote from: rogs on May 21, 2010, 01:40:04 PM
This worked for me... Seems that the timeit.exe uses the normal error level 2 to output it's results.

c:\timeit xcopy a.txt b.txt 2> test.tmp


By the way, I know "2>" redirection works in this case. But I thought "2>" was for standard error? Redirection works nearly the same for Unix. I'm not perfectly CLEAR on how and when to use the different symbols of redirection.

Please enlighten.

Thanksstreams:

1. STDOUT

> on its own is the short way of redirecting stream 1

these are equivalent:

command >file.txt
command 1>file.txt

2 STDERR

command 2>file.txt

to combine both streams

command>file.txt 2>&1

so to get both the standard output of DIR (the file listing) and also any error message ("file not found")

dir >file.txt 2&>1


Quote from: rogs on May 21, 2010, 01:40:04 PM
This worked for me... Seems that the timeit.exe uses the normal error level 2 to output it's results.

c:\timeit xcopy a.txt b.txt 2> test.tmp



There must a bug with timeit.exe since timeit.exe requires "2>" to redirect regular output ( standard Out ) to a file. For other programs only ">" is required.

Quote from: marvinengland on May 22, 2010, 06:49:54 PM
There must a bug with timeit.exe since timeit.exe requires "2>" to redirect regular output ( standard Out ) to a file. For other programs only ">" is required.



Not a bug necessarily; some programs are deliberately designed that way. I expect in this case it is done so that the output of the program to be timed can be kept separate from the output of timeit. Or some such reason.


3481.

Solve : Drive A error. System halt **URGENT****?

Answer»

I cant. I dont GO to the boot screen, I cant get to the Bios Screen or anything else. I Just SEE the ERROR. Nothing else.Are you saying the error comes up before you have the OPPORTUNITY to press the key(s) required to enter the bios? If so, the only other suggestion I can make is to replace the existing ram. But keep in mind there's no way we can be 100% certain the ram is the problem without testing it. Sorry - I'm not sure what else to suggest.Thanks for the help.

3482.

Solve : Next sequence variable in DOS?

Answer»

Need to rename data FILE DATA256 after processing data.

Naming convention is BATCHxxx-YYYYMMDD-HHMM.
xxx is a sequential number incremented PRIOR to rename.

Is this possible WITHIN .bat?

Thanks

lswain
C:\test>type iswain.bat
Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=1-3 delims=/" %%i in ("%DATE%") do (
set M1=%%i
set M1=!M1:~-2!
echo M1=!M1!
set DD=%%j
echo DD=!DD!
set YYYY=%%k
echo YYYY=!YYYY!
)
set HH=%TIME:~0,2%
set MM=%TIME:~3,2%
echo HH=%HH%
echo MM=%MM%
pause
set /p seq=<seq.txt
set /a seq=%seq% + 1
echo %seq% > seq.txt
type seq.txt
echo date = %DATE%

copy DATA256.txt BATCH%seq%-%YYYY%%M1%%DD%-%HH%%MM%.txt
dir BATCH*.txt
rem del DATA256.txt
rem del BATCH*.txt
Output:

C:\test> iswain.bat
M1=05
DD=08
YYYY=2010
HH=14
MM=22
Press any key to continue . . .
115
date = Sat 05/08/2010
1 file(s) copied.
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of C:\test

05/09/2010 12:56 PM 9 BATCH115-20100508-1422.txt
1 File(s) 9 bytes
0 Dir(s) 296,157,327,360 bytes free

C:\test>Quote from: lswain on May 05, 2010, 01:03:42 PM

Need to rename data file DATA256 after processing data.

Naming convention is BATCHxxx-YYYYMMDD-HHMM.
xxx is a sequential number incremented prior to rename.

Is this possible within .bat?

The for loop in post one is not needed.

Reference:

http://www.dostips.com/DtTipsStringManipulation.php



C:\test>type wain.bat
Code: [Select]@echo off

set M1=%date:~4,2%
set DD=%date:~7,2%
set YYYY=%date:~10,4%
echo M1=%M1%
echo DD=%DD%
echo YYYY=%YYYY%
pause
set HH=%TIME:~0,2%
set MM=%TIME:~3,2%
echo HH=%HH%
echo MM=%MM%
pause
set /p seq=<seq.txt
set /a seq=%seq% + 1
echo %seq% > seq.txt
type seq.txt
echo date = %DATE%

copy DATA256.txt BATCH%seq%-%YYYY%%M1%%DD%-%HH%%MM%.txt
dir BATCH*.txt
rem del DATA256.txt
rem del BATCH*.txt

Output:

C:\test>wain.bat
M1=05
DD=08
YYYY=2010
Press any key to continue . . .
HH=17
MM=01
Press any key to continue . . .
116
date = Sat 05/08/2010
1 file(s) copied.
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of C:\test

05/09/2010 12:56 PM 9 BATCH116-20100508-1701.txt
1 File(s) 9 bytes
0 Dir(s) 296,159,543,296 bytes free

C:\test>Works great.

Thanks for your support Marvin.

lswain
3483.

Solve : dir command?

Answer»

the following command finds the file provided name provided by %1
DIR /s C:\ %~n1
however it also displays all the FILES on the computer how do iget it to only display files with the same filename
i can't USE this
dir /s C:\ %~n1 &GT; nul because it doesn't display the resultsCode: [SELECT]dir /s C:\%~n1
thanks BC

3484.

Solve : visual/office?

Answer»

i WANT to know more about the VISUALS/ office under the FORUM or MICROSOFT link on DOS.Quote from: katzo on May 12, 2010, 05:37:06 AM

i want to know more about the visuals office under the forum or microsoft link on DOS.

http://www.visualsteps.com/index.php

http://www.visualsteps.com/contact.php
3485.

Solve : Resizing Command Window?

Answer»

Hi Every 1,

Is It Possible To Resize Command Prompt Window Through Command Line

If Yes, Please Post The Command Line Both of these will work:

MODE con: cols=40 lines=10

mode 40,10

Change the numbers to your specs.

Note: you can also use these same commands in a batch file.Thanx Sidewinder

But Can You Please Give Me An Example (Where To Write , HOW The Format Shld Be)Quote from: the_mad_joker on May 21, 2010, 12:47:53 AM

Thanx Sidewinder

But Can You Please Give Me An Example (Where To Write , HOW The Format Shld Be)

You were given TWO examples. You can write the mode command either at the command prompt to change the existing window, within a batch file to change the existing window, or with the start command to change the dimensions of a new window. The numbers (dimensions) I used are arbitrary. Within physical limitations, you can SET them as needed.

You can get further details by typing mode /? at the command prompt. The mode command can configure other system devices besides the CONSOLE.

With a little imagination you can even mimic an input BOX for your batch files.

You Are Amazing Dude Thanxxxxxxxxxxxxxxx
3486.

Solve : How to FORMAT !!! under BIOS?

Answer»

guys HELP how the f..k can i format my hard drive under BIOS . i want to install Win 7 but i cant DELETE my old version
the menus from the Win wont work You can't format from the BIOS - Try DOWNLOADING a free dos boot disk and USING that to fomart. (fdisk command)And watch your MOUTH. That's no way to introduce yourself to the forum.Quote from: Allan on May 13, 2010, 01:18:24 PM

And watch your mouth. That's no way to introduce yourself to the forum.

Agreed.

If you can't delete your old version from your current Win7 DVD you may want to considering purchasing it...
3487.

Solve : How to start and then later kill an exe from a .bat file???

Answer»

I've an .exe which i need to call through an .BAT file and then i need to kill this .exe at a later stage.
Please tell me how to do that??start file.exe
tskill fileQuote from: Anupam Sharma on MAY 20, 2010, 12:14:15 AM

I've an .exe which I need to call through an .bat file and then I need to kill this .exe at a later stage.
Please show me how to do that?



E:\>type killnote.bat
Code: [Select]@echo off

start notepad joe.txt

sleep 60

tasklist | findstr "%1" > notepid.txt


for /f "tokens=1,2 delims= " %%i in (notepid.txt) do (
echo PID=%%j

taskkill /pid %%j

)
OUTPUT:

E:\>killnote.bat note
pid=3056
SUCCESS: Sent TERMINATION signal to the process with PID 3056.

E:\>
3488.

Solve : Variable in a variable?

Answer»

Hi ppl, I just joined the forum because I'm a bit stuck. I'm running Win Vista Home Premium (I know it's lame :/) and I thought to make something like a quick file browser, I have made most of it but what I want to be able to do is allow the user to go to complex folder trees without me having to write a couple of lines for each sub-folder.

I had an idea (not complete) and it looks like this:
ECHO Go down a level?
ECHO 1=Yes 2=No 3=Exit
@Echo off
CHOICE /N /C:123 %1
IF ERRORLEVEL ==3 GOTO Exit
IF ERRORLEVEL ==2 GOTO NOSUB3
IF ERRORLEVEL ==1 GOTO SUBINF
:NOSUB3
start %var1%:\%VAR2%\%var3%\%var4%
Goto BEGIN
:SUBINF
set varf=%varer%
start %var1%:\%var2%\%var3%\%var4%\%var%varf%%

Th problem occurs with the last line of variables, I need to know how to modify a variable by adding another variable inside it, OR I need a better solution than 2 variables...

Thx in advance MeitneriumBTW, sorry for my bad POST, this is just a fragment of my work not all of commands Quote from: Meitnerium on MAY 12, 2010, 11:36:10 AM

Quick file browser.


C:\test&GT;type meit2.bat
Code: [SELECT]@echo off

dir /B /s *.txt

echo bye
Output:

C:\test>meit2.bat
C:\test\5810.txt
C:\test\BATCH116-20100508-1701.txt
C:\test\compare.txt
C:\test\count.txt
C:\test\count2.txt
C:\test\DATA256.txt
C:\test\folderlog.txt
C:\test\nc.txt
C:\test\old15.txt
C:\test\old15days.txt
C:\test\seq.txt
C:\test\test.txt
C:\test\timefile1.txt
C:\test\timefile2.txt
C:\test\timefile3.txt
C:\test\timefile4.txt
C:\test\today.txt
C:\test\var.txt
C:\test\ver6.txt
C:\test\folderA\a.txt
C:\test\folderA\b.txt
C:\test\folderA\c.txt
C:\test\folderB\a.txt
C:\test\folderB\c.txt
C:\test\space name\test.txt
bye
C:\test>Wow, thaks... It's quiet impressive however I wanted to keep all stuff in 1 file.... anyway thanks for that
I wish you good luck and thanks againQuote from: Meitnerium on May 13, 2010, 02:02:59 PM
I wanted to keep all stuff in 1 file....


C:\test>type meit2.bat
Code: [Select]@echo off

dir /B /s *.txt > onefile.txt

type onefile.txt
Output:

C:\test>meit2.bat
C:\test\5810.txt
C:\test\BATCH116-20100508-1701.txt
C:\test\compare.txt
C:\test\count.txt
C:\test\count2.txt
C:\test\DATA256.txt
C:\test\folderlog.txt
C:\test\nc.txt
C:\test\old15.txt
C:\test\old15days.txt
C:\test\onefile.txt
C:\test\seq.txt
C:\test\test.txt
C:\test\timefile1.txt
C:\test\timefile2.txt
C:\test\timefile3.txt
C:\test\timefile4.txt
C:\test\today.txt
C:\test\var.txt
C:\test\ver6.txt
C:\test\folderA\a.txt
C:\test\folderA\b.txt
C:\test\folderA\c.txt
C:\test\folderB\a.txt
C:\test\folderB\c.txt
C:\test\space name\test.txt
C:\test>
3489.

Solve : Deleting Profiles with exceptions in a Batch File.?

Answer»

Hello!

I'd like to save the introduction for a later date, so let's get right down to business at hand.

I've been going through different ways of trying to delete all profiles (Except for the current profile, administrator, default user, and my own). I've thought about MAKING it work like this

md copy directory, Xcopy all profiles I want to save, RD Documents and Settings, MD a new Documents and settings, then xcopy the folders back into the new Documents and settings

Simply stated, it doesn't work.

Im hoping someone else knows how to create a batch file that will:
1. Delete all the profiles within Documents and Settings, saving a few profiles.

I've been digging through various other commands, Deltree, Copy... for an example. I still can't crack it and I've been digging at this for a couple days now.

My Name's Cliff by the WAY Quote from: melanton on May 13, 2010, 02:51:10 PM


1. Delete all the profiles within Documents and Settings, saving a few profiles.


http://www.dabcc.com/article.aspx?id=9369

( All the following information from the above site. )

<<<<<<<

"Deleting Profiles Manually:

•Open the control panel applet "System Properties" and navigate to the tab "Advanced". I know of the following shortcuts for this often needed dialog box:
◦Press Win+Break
◦Press Win+R to open the run dialog box. TYPE in control sysdm.cpl,,3 and press enter. Note there must not be entered a SPACE in front of the commas.
•Click on the settings button in the user profiles section.
•In the dialog that appears, CHOOSE the appropriate user profile and click on delete. Note: you must be an administrator for the delete button to even show up. And: you cannot delete your own profile.
Deleting Profiles Automatically

To learn more and to read the entire article at its source, please refer to the following page, Deleting User Profiles - Correctly at Helge Klein"
>>>>>
3490.

Solve : How To Extract The Figures Using DOS?

Answer»

Hi ;

I need to extract the figures from a file which contains below information using DOS:

2, ,[1024], Application, CBR Server,Throughput (bits/s) = 269338
3, ,[1025], Application, CBR Server,Throughput (bits/s) = 263941
4, ,[1026], Application, CBR Server,Throughput (bits/s) = 266663
5, ,[1027], Application, CBR Server,Throughput (bits/s) = 265108
6, ,[1028], Application, CBR Server,Throughput (bits/s) = 268421
7, ,[1029], Application, CBR Server,Throughput (bits/s) = 269602
8, ,[1030], Application, CBR Server,Throughput (bits/s) = 266973
9, ,[1031], Application, CBR Server,Throughput (bits/s) = 266477
10, ,[1032], Application, CBR Server,Throughput (bits/s) = 270655
11, ,[1033], Application, CBR Server,Throughput (bits/s) = 266822
12, ,[1034], Application, CBR Server,Throughput (bits/s) = 268137
13, ,[1035], Application, CBR Server,Throughput (bits/s) = 267681
14, ,[1036], Application, CBR Server,Throughput (bits/s) = 266535

I have tried:
for /f "tokens=7 delims=,=" %%a in ("test.txt") Do Echo
%%a >> tgk.txt

I got:
%%a was unexpected at this time.

Why is it? Does this codes able to read all the lines in the file?

Many thanks.

The reason you got the error is because on the command line you type in 1 '%', from a BATCH you use 2 '%%'

this appears to solve your problem
for /f "delims=*" %a in (test.txt) Do CALL set aa=%a&AMP;echo %aa:~-6%

which trims the last 6 chars from each line - ASSUMING your number is always 6 digits

if you run it in a batch, you would do this
for /f "delims=*" %%a in (test.txt) Do call set aa=%%a&echo %aa:~-6%
C:\test>type zee2.bat
Code: [Select]@echo off
for /f "tokens=1-7 delims=,=],[" %%a in (test.txt) do (
echo %%a %%c %%g
)
Output:

C:\test>zee2.bat
2 1024 269338
3 1025 263941
4 1026 266663
5 1027 265108
6 1028 268421
7 1029 269602
8 1030 266973
9 1031 266477
10 1032 270655
11 1033 266822
12 1034 268137
13 1035 267681
14 1036 266535


C:\test>Quote from: RuZee on May 13, 2010, 08:09:35 AM


I need to extract the figures from a file which contains below information using Batch:


If RuZee needs only the last six numbers from each input line, then we were able to use the gpl code
with a slight midification:


C:\test>type gpl.bat
Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "delims=*" %%a in (test.txt) do (
set aa=%%a
rem echo aa = !aa!
rem echo %%a
echo !aa:~-6!

)
Output:


C:\test>gpl.bat
269338
263941
266663
265108
268421
269602
266973
266477
270655
266822
268137
267681
266535

C:\test>Quote from: RuZee on May 13, 2010, 08:09:35 AM

I have tried:
for /f "tokens=7 delims=,=" %%a in ("test.txt") Do Echo
%%a >> tgk.txt

I got:
%%a was unexpected at this time.

Why is it? Does this codes able to read all the lines in the file?


Zee,

Your code is correct except you asked for a display of token 7 and then tried to use token one.

C:\test>type zee4.bat
Code: [Select]@echo off
echo > tgk.txt
for /f "tokens=7 delims=,=" %%g in (test.txt) Do (
Echo %%g >> tgk.txt
)

type tgk.txt
Output:

C:\test>zee4.bat
269338
263941
266663
265108
268421
269602
266973
266477
270655
266822
268137
267681
266535

C:\test>Quote from: marvinengland on May 15, 2010, 03:02:35 AM
Zee,

Your code is correct except you asked for a display of token 7 and then tried to use token one.


C:\test>type zee4.bat
Code: [Select]@echo off
echo. > tgk.txt 2>null
for /f "tokens=1-7 delims=,=" %%a in (test.txt) Do (
echo. %%g >> tgk.txt 2>null
)

type tgk.txt
Output:

C:\test>zee4.bat

269338
263941
266663
265108
268421
269602
266973
266477
270655
266822
268137
267681
266535


C:\test>

p.s This code is better than the above post. We filter out the echo off message with 2>null
3491.

Solve : user creation from text file?

Answer»

I want a batch file which will create users. the user names and passwords should be taken from the file.

I can do the following

Quote

@echo off
TITLE User Creation
cls
echo.
echo.
echo #######################################################
echo # #
echo # This is Automatic User Creation Program #
echo # #
echo # Select the OPTION according to your Choice #
echo # #
echo # 1. ADD Users #
echo # #
echo # 2. DELETE Users #
echo # #
echo #######################################################
echo.
echo.
TITLE Enter the choice!
set /P MENU="Enter Your Choice: "
if %MENU%==1 goto add
if %MENU%==2 goto delete

goto error

:add
echo.
echo How much users do you want to add ?
echo.
echo.
TITLE Enter the Number!
set /P usrs="Enter the Number <1-1000> "
if %usrs% LSS 1 goto error
if %usrs% GTR 1000 goto error
cls
echo.
echo.
echo.
echo Enter the prefix you want to use to create the users.
echo.
echo Users will be created in a form PREFIX_NUMBER
echo.
echo.E.g.BNU_1, BNU_2, BNU_3 .....
echo.
echo.
TITLE Enter the Prefix!
set /P prfx="Enter the Prefix: "
echo.
echo.
echo.
echo
echo Adding . . .
echo.
echo.
TITLE Adding Users!
for /L %%i IN ( 1,1,%usrs% ) DO net user %prfx%_%%i Pass123 /ADD >> NUL
echo.
goto doneadd

:delete
echo.
echo How much users do you want to delete ?
echo.
echo.
TITLE Enter the Number!
set /P usrs="Enter the Number <1-1000> "
if %usrs% LSS 1 goto error
if %usrs% GTR 1000 goto error
cls
echo.
echo.
echo.
echo Enter the prefix you want to use to delete the users.
echo.
echo Users will be deleted in the form PREFIX_NUMBER
echo.
echo.E.g.BNU_1, BNU_2, BNU_3 .....
echo.
echo.
TITLE Enter the Prefix!
set /P prfx="Enter the Prefix: "
echo.
echo.
echo Deleting . . .
echo.
echo.
TITLE Deleting Users!
for /L %%i IN ( 1,1,%usrs% ) DO net user %prfx%_%%i /DELETE >> NUL
echo.
goto donedelete

:error
echo.
echo.
echo.
echo wrong entry
echo.
echo.
echo.
TITLE Wrong Entry!
goto exit


:doneadd

echo.
echo.
echo.
echo Users are added
echo.
echo.
echo.
TITLE Users Created!
goto exit

:donedelete
echo.
echo.
echo.
echo Users Deleted
echo.
echo.
echo.
TITLE users Deleted!
goto exit

:exit

3492.

Solve : Is it possible to have a batch file copy files from a cd to the C Drive ??

Answer»

Guys,

Thank you all for your help, but as I'm such a newbie when it comes to batch files and MS-DOS, WOULD any of you be willing to set up a screenshare and I can show exactly what is happening and if what I want to do is possible at all ?

I use TeamViewer for screensharing and we could use SKYPE as a means of talking to each other. Any takers ? i could use team viewer pm me with time and id
i don't have skype though team viewer has a chatting feature.one QUESTION
is the batch file in the root of the cdYes, the batch files is in the root of the CD. I will GET back on this topic on Tuesday, I have to finish an ASSIGNED on Monday so I'll be a bit busy this weekend and Monday. I apologise to all of you who are helping, for any inconvenience this may cause...

Thank you all.

carlstarus

3493.

Solve : how can one get the timezone with a DOS command??

Answer»
All --

Please help.

I am on Windows XP and I need to know-- how can one get the timezone (time zone) with a DOS command?

I tried this...

C:\Documents and Settings\mkamoski>timezone /g

Current Timezone is :

Daylight Saving Time begins at 02:0:2:03

Daylight Saving Time ENDS at 02:0:1:11

...but that is not what I need...

...I also can run the "systeminfo" command and what I need is buried in there but there is no way that I can see to get JUST the timezone from that DATA...

...RATHER, I need something like this...

-04:00

...but I cannot see how that can be done...

...so what do you think?

Please advise.

Thank you.

-- Mark Kamoski
Code: [Select]C:\>systeminfo | find "Time Zone"
Time Zone: (UTC) Dublin, Edinburgh, Lisbon, LondonIt WORKS! How did you know that? Quote from: Geek-9pm on May 18, 2010, 01:15:02 PM
It Works! How did you know that?

Isn't it obvious?
3494.

Solve : Count files and email ---Batch file?

Answer»

Hello All,

I would like to count the number of files from a folder and only count the files from yesterday. And email the count to a specific email address. I would set this on a Task Scheduler to daily to get a count and see how many files are added to the folder. I tried creating a batch file
dir /a "C:xx\" |find /c /v ""

But this gives me a count of everything in the folder, i just need a count from yesterday and also i dont KNOW how to email the count.
Please help!Quote from: TechAbhi on May 16, 2010, 11:57:45 AM


I would like to count the number of files from a folder and only count the files from yesterday.


C:\test>type Abhi.bat

CODE: [Select]@echo off

for /f "delims=" %%i in ('cscript //nologo c:\test\evaluate.vbs "date -1"' ) do (
set yesterday=%%i
echo yesterday=%yesterday%
)

set Today=%DATE:~4,10%

echo Today=%Today%

dir /OD /A-D | findstr "%yesterday% %Today%"

dir /OD /A-D | findstr "%yesterday% %Today%" | find /c /v "" > filecount.txt

echo type filecount.txt

type filecount.txt
rem evaluate.vbs
rem Wscript.echo eval(WScript.Arguments(0))
rem Thank Salmon Trout for evaluate.vbs

Output:

C:\test>Abhi.bat
yesterday=5/15/2010
Today=05/16/2010
05/15/2010 03:57 AM 14 trk.txt
05/15/2010 04:43 AM 129 gpl77.bat
05/15/2010 09:56 PM 138 zee4.bat
05/15/2010 09:57 PM 150 tgk.txt
05/16/2010 04:19 AM 361 st0510.bat
05/16/2010 01:20 PM 92 teststr.txt
05/16/2010 09:37 PM 135 yesterday.bat
05/16/2010 10:29 PM 3 filecount.txt
05/16/2010 10:32 PM 466 Abhi.bat
type filecount.txt
9
C:\test>



Hi marvin,

Thanks for the quick reply, question since i am new to writing batch files, where do i give the path to the folder i want a count of, and you have used a .vbs file?
Also i do not want a listing of the files, just a count as there could be over 100 files. And how should i go about setting up the email?Quote from: TechAbhi on May 16, 2010, 11:57:45 AM
""

I dont know how to email the count.


Point to filecount.txt, right click and choose send to mail recipient.

[recovering disk space - old attachment deleted by admin]Hi Marvin,

I will be putting this up on a task scheduler to run every night. How do i set up the email so it sends an email automatically. Did a test run and got a file count of 8, but when i opened the folder saw the file count was much higher for yesterday.

[recovering disk space - old attachment deleted by admin]Quote from: TechAbhi on May 17, 2010, 08:36:28 AM
Did a test run and got a file count of 8, but when i opened the folder saw the file count was much higher for yesterday.
You must create and INSTALL "evaluate.vbs" and in the code show the complete path to evaluate.vbs

The batch is run inside the photo folder or show a cd to the photo folder in the code before dir command is run
'cscript //nologo c:\test\evaluate.vbs "date -1"'

What did the variable yesterday show at the top of the output? 05/16/2010 ?

Do not schedule the batch file until it runs correctly for you.

I don't know how to email from batch.
Quote from: TechAbhi on May 17, 2010, 08:36:28 AM
Did a test run and got a file count of 8, but when i opened the folder saw the file count was much higher for yesterday.

It appears the path to the folder on your machine where we need to count new files from yesterday and today is:

c:\netpub\ftproot\photos\

Also, the evaluate.vbs does not work on your machine.

The batch file will run on a schedule at 2AM ( or so) and we cannot prompt a user for yesterday's date. The batch must run automatically and yesterday's date must be currently assigned to yesterday's variable. All values assigned to ram variables disappear when the batch file is no longer in RAM.

I shall modify the original code so we can assign yesterday's date to the RAM variable without using evaluate.vbs or interactive input.

I shall post the code today 05/17/2010.

Thank you Marvin, appreciate your help.Quote from: TechAbhi on May 17, 2010, 11:07:58 AM
Thank you Marvin, appreciate your help.

Please try the following code:

C:\test>type abhi2.bat
Code: [Select]@echo off

Rem USE the following code only one time
echo 05/16/2010 > yesterday.txt
rem erase the above line after 23:50 today

set /p yesterday=<yesterday.txt
echo yesterday=%yesterday%
)
set Today=%DATE%
set Today=%DATE:~4,10%

echo Today=%Today%

cd c:\netpub\ftproot\photos\
rem the above folder is where we count files?

dir /OD /A-D | findstr "%yesterday% %Today%"

dir /OD /A-D | findstr "%yesterday% %Today%" | find /c /v "" > filecount.txt

echo type filecount.txt

type filecount.txt

echo %Today% > yesterday.txt


The following Output is for c:\test\ on my computer

C:\test>abhi2.bat
yesterday=05/16/2010
Today=05/17/2010
05/16/2010 04:19 AM 361 st0510.bat
05/16/2010 01:20 PM 92 teststr.txt
05/16/2010 09:37 PM 135 yesterday.bat
05/16/2010 10:32 PM 466 Abhi.bat
05/16/2010 10:32 PM 3 filecount.txt
05/17/2010 12:26 PM 483 abhi2.bat
05/17/2010 12:27 PM 14 yesterday.txt
type filecount.txt
7
Quote from: TechAbhi on May 16, 2010, 11:57:45 AM
How to email from commamd prompt the count.

"You can use blat (www.blat.net) to send the email"

I have not used www.blat.net

Let us know how you send email from the command prompt?
3495.

Solve : Batch script for/if not looping?

Answer»

Win XP SP.3

Why does the For loop in the FOLLOWING script not loop please?

Code: [SELECT]@ECHO off
setlocal enabledelayedexpansion
cls

set year=9
set month=8
set DAY=25
set cnt=1

for /f "tokens=%cnt%" %%1 in ("year month day") do (
if !%%1! lss 10 set %%1=0!%%1!
set /a cnt+=1
)
echo !year!:!month!:!day!
exit /b
Because there is only one line being fed into the for loop. It does the action(s) for each line it is fed.See the lines in red

@echo off
setlocal enabledelayedexpansion
cls

set year=9
set month=8
set day=25
set cnt=1

:loop
for /f "tokens=%cnt%" %%1 in ("year month day") do (
if !%%1! lss 10 set %%1=0!%%1!
set /a cnt+=1
)
if %cnt% LSS 4 goto loop
echo !year!:!month!:!day!






Thank you both.

V.

3496.

Solve : Creating batch file to count number of files in a directory?

Answer»

I would like to do the above and then if the number of files is larger then what I specify, have it email me and tell me that the number of files has been exceeded. Any advice on this would be great.I don't THINK MS-DOS can email, if anyone knows different, tell please. I am like 90% sure I'm RIGHT on this.there are probably programs that could be invoked from the command-line to E-mail.

as for counting the number of files, I'd imagine it would involve sending the output to FIND, and finding the last line with "File(s)", and then grabbing the number before that and comparing it to the value your checking for. If it is larger, you would invoke the e-mail sending program with appropriate arguments.

The attackment should do what you want, it will count files and folders in the directiory that the program is placed in. It is not as easy as you would think so I dout it to be in any book because this is really complicated batch stuff that what you are asking gets into.

Hope you like, but since the code is quite difficult the app is and EXE,
Tan_Za

[attachment deleted by admin]Here is my version:

the only real thing I could think of was (ASIDE from not search subdirectories(?)) was that it included all the directories in the file count.

In order to remedy this, I used a switch on dir to exclude directories.

Code: [Select]@echo off
title File Counter batch.
:recurse
set I=1

echo "files in folder"
cd
REM view all files, EXCEPT directories.
FOR /f "tokens=*" %%P IN ('dir /A-d /b') do (call :showfiles "%%P")
echo Filecount: %I%
REM now call on all subfolders...




:showfiles
echo %1
set /a I+=1
GOTO :eof


for the record, Tan_Za's code would be:


Code: [Select]@echo off
title File Counter by Tan_Za
SET count=1
FOR /f "tokens=*" %%G IN ('dir /b') DO (call :s_do_sums "%%G")
echo Any key to continue
echo made by Tan_Za. any questions email me at:[emailprotected]l.com
pause >nul
GOTO :eof
:s_do_sums
echo %count%:%1
set /a count+=1
GOTO :eof


your measly EXE compression does nothing to dissuade me! MWA HA HA *cough*.

also, the recurse: label was a remnant from my almost successful attempt to iterate through subdirectories by afterwards using dir /b /ad in the for command to iterate on each folder and recurse on it with the batch file.
Turns out batch files don't like recursion.Yeah batch to exe is a very easy thing to do and to reverse lol, but my code is a little complex for some peole because it sure took a while to do.

DAM you...

Not really, thats ok,
Tan_ZaIf you want to count all the files in the subdirectories as well (also it's smaller than the other two's) this should work:

Code: [Select]@echo off
setlocal enabledelayedexpansion

for /f %%A in ('dir /s ^| find "File(s)"') do (set B=%%A+!B!)
set B=%B%0
set /a C=%B%
echo %C
pause
exit
FBBC programmer, you're batch file counted the files. But then it just exited out. Quote from: BatchFileCommand on January 10, 2009, 01:11:52 PM

BC programmer, you're batch file counted the files. But then it just exited out.

ahh yes, just add "Pause" right before the ":showfiles" line.
It still doesn't seem to work, it pauses in the beginning before it counts the file. I need it to pause after it's counted all the files.don't put pause at the end of the batch, but rather in the same area that Tan_Za has placed their pause, which is right before the subroutine.

here, I also fixed a bug involving a forgotten GOTO :EOF, not sure if it was affecting the program or not, though.

Code: [Select]@echo off
title File Counter batch.
:recurse
set I=1

echo "files in folder"
cd
REM view all files, EXCEPT directories.
FOR /f "tokens=*" %%P IN ('dir /A-d /b') do (call :showfiles "%%P")
echo Filecount: %I%
REM now call on all subfolders...



PAUSE


goto :eof
:showfiles
echo %1
set /a I+=1
goto :eof
What's wrong with:

dir /b /s /A-d c:\temp | find "" /v /n /c

You can use blat (www.blat.net) to send the email Quote from: rbird on February 11, 2009, 03:18:57 AM
What's wrong with:

dir /b /s /A-d c:\temp | find "" /v /n /c

why, it's too easy, of course! redirect that to a variable and he'd be good to go

bit of a topic bump, but for a good reason from somebody who knows their switches .

EDIT: welcome to CH!Hello All,

I would like to count the number of files from a folder and only count the files from yesterday. And email the count to a specific email address. I would set this on a Task Scheduler to daily to get a count and see how many files are added to the folder. I tried creating a batch file
dir /a "C:xx\" |find /c /v ""

But this gives me a count of everything in the folder, i just need a count from yesterday and also i dont know how to email the count.
Please help!Quote from: TechAbhi on May 16, 2010, 11:55:42 AM
Hello All,

I would like to count the number of files from a folder and only count the files from yesterday. And email the count to a specific email address. I would set this on a Task Scheduler to daily to get a count and see how many files are added to the folder. I tried creating a batch file
dir /a "C:xx\" |find /c /v ""

But this gives me a count of everything in the folder, i just need a count from yesterday and also i dont know how to email the count.
Please help!
Please make your own thread instead of bumping one from last year.
3497.

Solve : Need help with the 'Wait' or 'Sleep' command in a batch file?

Answer»

I am trying to run the following simple batch file: [I am using the pauses just to step through the file]

c:

cd\

pause

cd dxr

cd program

pause

dir

pause

C:\DXR\PROGRAM\Dxr32 /si /pn1-5000 /pfc:\temp\Test-5.pdf

C:\DXR\PROGRAM\Dxr32 /si /pn10001-15000 /pfc:\temp\Test-6.pdf

pause


This operation is calling a program of ours that is CREATING PDF's in 5000 page segments. HOWEVER I can not get the second segment created because I need to wait until the first operation has completed.

I KNOW that this is a simple batch file and I have been able to successfully create the 2 PDF files by placing a 'Pause' between the two operation. Doing this does require interaction with a person and I am wanting the ability to run this unattended.

I have tried placing 'start /wait' at the beginning of the line but it did not help

Thanks in advance for your time........

Markuse :

Code: [Select]ping -n 1 -w 1000 1.1.1.1 >nul <--- 1 second
ping -n 1 -w 10000 1.1.1.1 >nul <--- 10 second
ping -n 1 -w 100000 1.1.1.1 >nul <--- 100 secondstart /wait "" C:\DXR\PROGRAM\Dxr32 /si /pn1-5000 /pfc:\temp\Test-5.pdfQuote from: devcom on September 17, 2008, 11:01:40 AM

use :

Code: [Select]ping -n 1 -w 1000 1.1.1.1 >nul <--- 1 second
ping -n 1 -w 10000 1.1.1.1 >nul <--- 10 second
ping -n 1 -w 100000 1.1.1.1 >nul <--- 100 second

er, no.

Quote from: mdprator
I need to wait until the first operation has completed.
You might want to throw in the /b switch to PREVENT a secondary window.

Code: [Select]start /wait /b "" C:\DXR\PROGRAM\Dxr32 /si /pn1-5000 /pfc:\temp\Test-5.pdf

Sidewinder,

Thank you so much for your suggestion [ start /wait /b "" ] it worked like a champ.........

Thanks again.............. Another satisfied customer... Nice catch, SW, with the /b switch.
Just to explain...

The start command needs to have a string supplied to it CALLED the "title". This can be a blank string, just 2 quote marks, but it cannot be left out.

start "title" program.exe param1 param2 param3

3498.

Solve : Read and Write to a value?

Answer»

Hi,
Is there a batch command that checks the value in the file test.txt?
After that, it will increment the value by 1.

Its KIND of a counter that will be used for me to save the state other batch file.

Thnaks!
Lekfir
you mean how many rows are in this file ??

if so :

Code: [Select]setlocal enabledelayedexpansion
for /f %%a in (file.txt) do (
set /a num+=1
)
echo %num%
Thanks for your replay!

But I still dont have the answer.
Let me explain
Lets say that I have 2 files:
File.txt that contains only the value 1 in it.
Test.bat file that has 2 goals:
1. Checks the value in the file.txt and if it is > 4 it will Call to another batch file.
2. After the check, it will increment the value in the file.txt by 1 each time I call to Test.bat.

Thanks! my Hero.As long as there is but a single value in file.txt, you can eliminate that pesky delayed expansion:

Code: [Select]set /p num=<file.txt
if %num% GTR 4 call another
set /a num=%num%+1
echo %num% > file.txt

Sidewinder Thank you very much!
It WORKED great.

BTW, Can I place the file.txt in a different location. not in the same location with the Test.bat?
For example: Test.bat is located in d:\ and file.txt in c:\ ?
Like here:

set /p num=if %num% GTR 4 call another
set /a num=%num%+1
echo %num% > c:\file.txt

Quote

Can I place the file.txt in a different location. not in the same location with the Test.bat

This is the type of question you could answer by TRYING the code. In fact the answer is yes. You can never go wrong using the PATH of a file, provided of course the path is correct. Thanks!
3499.

Solve : Text Search and Bat file?

Answer» HI every body!!
I have program Text Search (TS.exe) and use one bath file use it search some code from file
This is bat file:

@echo off
rem :ikot
rem cls
rem if %1 errorlevel -- 0 GOTO tapos
ts /s %1 "$$"
ts /s ......
ts /s %1 " t H "
rem shift
rem goto ikot
rem :tapos
exit

Any thing i want find between ""
How I can use bat file find Some special Character
Example: "%", "LR" or Quotation mark
Help me if i want find percent SIGHT or other only start Line, "space Quotation space" , ETC.. in file Text
ThanksSorry all
Quote
I have program Text Search (TS.exe)
It is program create by some body in my country and it have same name with some program.
But I want know, how I can search text and special Character.
Example:

$Zasd "dasd$Z dsad $I
asd $Idasd$Z" dsad dsad
$Zdafh " asdfgf "asd
adsd $Z asdfsd" $Zasdas%

How I can find only $Z Start Line, $I End Line or %, " (space Quotation mark space), etc... in DOS
3500.

Solve : How to split any line(path) throught command line (for batch file)??

Answer»

Quote from: Sidewinder on September 12, 2008, 08:16:46 AM

Code: [Select]if .%%G==. goto getout

That's a new one on me. I am used to doing it this way

Code: [Select]if "%%G"=="" goto getout
hi side winder
i used the code send by you and after that code i have to set some enviorment
but after that it doesnot set any enviorment varible, can u tell me why this happens?

i think because of setlocal enabledelayedexpansionQuote
i think because of setlocal enabledelayedexpansion

Indeed it is. Usually I try not to use setlocal for this very reason. The call instruction can be put to good use in this context.

Code: [Select]@echo off
for /F "tokens=* delims=\" %%a in ('cd') do (
set parse=%%a
call set new=%%parse:\= %%
)

for %%G in (%new%) do (
if .%%G==. goto getout
if %%G==test goto getout
call set p=%%p%%\%%G
)
:getout
set p=%p:~1%
echo %p%

After the batch file executes, the variable p will CONTAIN the directory name.

Good luck. i used following code

setlocal enabledelayedexpansion
set DIR=
for /f "tokens=* delims=\" %%P in ('cd') do (
set mypath=%%P
set array=!mypath:\= !
)

for %%E in (%array%) do (
if .%%E==. goto getout
if %%E==test goto getout
call set DIR=%%DIR%%\%%E
)
:getout

set TOP_DIR=%DIR%//test1

and if i removed setlocal enabledelayedexpansion
and prints valuse of TOP_DIR = \!mypath:\\!\\test1

and if print the value of TOP_DIR with enabledelayedexpansion
it is TOP_DIR = %TOP_DIR%
that is no value is set

so now what should doneIf you remove the setlocal statement, you must also remove any references to delayed expansion:

Code: [Select]set DIR=
for /f "tokens=* delims=\" %%P in ('cd') do (
set mypath=%%P
call set array=%%mypath:\= %%
)

for %%E in (%array%) do (
if .%%E==. goto getout
if %%E==test goto getout
call set DIR=%%DIR%%\%%E
)
:getout

set TOP_DIR=%DIR%//test1

Why are you using both FORWARD and BACKWARD slashes? They are not interchangeable.

Why keep changing the variable (both declared and generated) names? Many people read these posts; let's try and keep it simple.

I thought you were trying to find the parents of the test directory on the path. Now I see you're appending test1 to the generated path. Any more surprises first of all sorry for changing variables .


now let me explain you what i was doing
i find out the the parents of the test directory, which i FOUND with the hlep of ur code.
After then i want to set some eviorment variables using this DIR(perent directory ) path.
and that variables value should be fixed till that command prompt is open or setup is runs again.

so finally The thing is done .
No more surprisess.
and thanks for that much support.