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.

3351.

Solve : .cmd file help?

Answer»

Hi all could someone please help me with this, i'm trying to get this .cmd to work, we used to have it working years ago
this is the part that's giving me problems:

:checksvr
for /F "skip= 2 tokens= 2" %%i in ('ping -n 1 %1') do (
if not %%i == timed (set STATE=%%i) else (
for /F "skip= 2 tokens= 2" %%k in ('ping -n 1 %1') do (set STATE=%%k)
)
)
for /F "delims== tokens=2" %%j in ('set status_%2') do (
if not '%%j' == '%STATE%' (
set status_%2=%STATE%
if %STATE% == timed (goto :svr_crashed) else (
if %%j == timed ((now %2 RUNNING again) & (logevent -s i "%2 up again"))
)
) else (
if %STATE% == from (now %2 running ok) else (
if %STATE% == timed (now %2 STILL crashed)
)
)
)


i get a (goto was UNEXPECTED at this time error.

thanks guyssurround both sides of IF TESTS in quote marks

if "%%i"=="timed"

and take out spaces

3352.

Solve : Could someone create me a batch file menu please??

Answer»

Hi I have 3 batch files i would like to integrate into one with a menu to run them.

For instance I have oen to rename 25 files in a folder then batcher kindly created me one to insert text into the 25 files then i have another one to create further files of 25 for different format then another 25 for another format i'll post the batch files below.

Batch file 1:

ECHO off

color 9f

cls

echo To rename all files as required.

echo.

pause

rename brdcast_20090427.txt allpips.txt
rename brdcast1_20090427.txt group1.txt
rename brdcast2_20090427.txt group2.txt
rename brdcast3_20090427.txt group3.txt
rename brdcast4_20090427.txt group4.txt
rename brdcast5_20090427.txt group5.txt
rename brdcast6_20090427.txt group6.txt
rename brdcast7_20090427.txt group7.txt
rename brdcast8_20090427.txt group8.txt
rename brdcast9_20090427.txt group9.txt
rename brdcast10_20090427.txt group10.txt
rename brdcast11_20090427.txt group11.txt
rename brdcast12_20090427.txt group12.txt
rename brdcast13_20090427.txt group13.txt
rename brdcast14_20090427.txt group14.txt
rename brdcast15_20090427.txt group15.txt
rename brdcast16_20090427.txt group16.txt
rename brdcast17_20090427.txt group17.txt
rename brdcast18_20090427.txt group18.txt
rename brdcast19_20090427.txt group19.txt
rename brdcast20_20090427.txt group20.txt
rename brdcast21_20090427.txt group21.txt
rename brdcast22_20090427.txt group22.txt
rename brdcast23_20090427.txt group23.txt
rename brdcast24_20090427.txt group24.txt

echo.

echo Your files have been renamed. Have a nice DAY!

echo.

pause

********************************************

Batch file 2:

@echo off
set SrcFolder=D:\Busnet\Dundee\Config\PIP\BC\Test1
set DstFolder=D:\Busnet\Dundee\Config\PIP\BC\Test2
for %%a in ("%SrcFolder%\*.txt") do (
(for /f "usebackq delims=" %%h in ("%%a") do (
echo.%%h
if "%%h" equ "SCHEDULES CLEANUP" (
echo SYS DUEGATE 60 05:00
echo DISPLAY SCHED 00:30 01:30
)
))>"%DstFolder%\%%~nxa"
)


********************************************

Batch file 3:

ECHO off

color 9f

cls

echo To create all CLI and GZP files as required.

echo.

pause

echo.

clibunchtest -t17 allpips.txt allpips.cli
gzip -c allpips.cli > allpips.gzp

clibunchtest -t17 group1.txt group1.cli
gzip -c group1.cli > group1.gzp

clibunchtest -t17 group2.txt group2.cli
gzip -c group2.cli > group2.gzp

clibunchtest -t17 group3.txt group3.cli
gzip -c group3.cli > group3.gzp

clibunchtest -t17 group4.txt group4.cli
gzip -c group4.cli > group4.gzp

clibunchtest -t17 group5.txt group5.cli
gzip -c group5.cli > group5.gzp

clibunchtest -t17 group6.txt group6.cli
gzip -c group6.cli > group6.gzp

clibunchtest -t17 group7.txt group7.cli
gzip -c group7.cli > group7.gzp

clibunchtest -t17 group8.txt group8.cli
gzip -c group8.cli > group8.gzp

clibunchtest -t17 group9.txt group9.cli
gzip -c group9.cli > group9.gzp

clibunchtest -t17 group10.txt group10.cli
gzip -c group10.cli > group10.gzp

clibunchtest -t17 group11.txt group11.cli
gzip -c group11.cli > group11.gzp

clibunchtest -t17 group12.txt group12.cli
gzip -c group12.cli > group12.gzp

clibunchtest -t17 group13.txt group13.cli
gzip -c group13.cli > group13.gzp

clibunchtest -t17 group14.txt group14.cli
gzip -c group14.cli > group14.gzp

clibunchtest -t17 group15.txt group15.cli
gzip -c group15.cli > group15.gzp

clibunchtest -t17 group16.txt group16.cli
gzip -c group16.cli > group16.gzp

clibunchtest -t17 group17.txt group17.cli
gzip -c group17.cli > group17.gzp

clibunchtest -t17 group18.txt group18.cli
gzip -c group18.cli > group18.gzp

clibunchtest -t17 group19.txt group19.cli
gzip -c group19.cli > group19.gzp

clibunchtest -t17 group20.txt group20.cli
gzip -c group20.cli > group20.gzp

clibunchtest -t17 group21.txt group21.cli
gzip -c group21.cli > group21.gzp

clibunchtest -t17 group22.txt group22.cli
gzip -c group22.cli > group22.gzp

clibunchtest -t17 group23.txt group23.cli
gzip -c group23.cli > group23.gzp

clibunchtest -t17 group24.txt group24.cli
gzip -c group24.cli > group24.gzp

echo.

echo Your files have been created. Have a nice day!

echo.

pause


*****************************************

I just want it to call the first batch file when i press 1 then the second when i press 2 and so on, I can edit the folder path etc i just need the menu if anyone wojuld kindly create it for me i will get a better understanding looking at it.

Thanks GUYS in advance.i can guess these batch files are not done by you. why don't you start learning how to write and use batch. CODE: [Select]@ECHO off
:start
cls
ECHO.
ECHO Press : 1. Get IP from DHCP
ECHO 2. Change IP : 192.168.10.x / 32
ECHO 3. Show Ip config
ECHO X. Exit

set choice=
echo Choice :
set /p choice=

if not '%choice%'=='' set choice=%choice:~0,1%
:: Lay bat dau tu ky tu 0 cua chuoi~, do dai cua chuoi la 1.
:: choice=abcdef
::%choice:~3,2%=de

if '%choice%'=='1' goto function1
if '%choice%'=='2' goto function2
if '%choice%'=='3' goto function3
if '%choice%'=='x' goto end

ECHO "%choice%" is not valid please try again
ECHO.
goto start


:function1
echo.
Netsh interface ip set address name="LAN" dhcp
goto end

:function2
set x=
echo.
echo IP : 192.168.10.X
echo X =
Set /p x=
Netsh interface ip set address name="lan" static 192.168.10.%x% 255.255.255.0
goto end

:function3
ipconfig | find /I "lan"
pause
goto start

::Local Area Connection

:end
Try this, make it suit to you.Thanks buddy worked like a treat

3353.

Solve : empting folders?

Answer»

i wold like a batch file that empty all the folders in the current directory (and sub folders in those folders) as WELL into the batch directory.

p.s my search does not work right it says "can not move file: can not read from source file or discs"Why do you want to do this?
my search does not work and my computer is very disorganized and i think .bat is coolSo you want to MOVE all the FILES to a different location?QUOTE from: Helpmeh on April 26, 2009, 05:51:05 AM

So you want to MOVE all the files to a different location?

Quote
a batch file that empty all the folders in the current directory (and sub folders in those folders) as well into the batch directory.

Like emptying a lot of jugs into one bucket?


Will there be any identicallly named files?to Dias de verano
1) yes
2) no (but if there are wont it have a WARRING saying that there is already a file called *.* would you like to replace it)Quote from: Ädamas on April 26, 2009, 02:36:15 AM
p.s my search does not work right it says "can not move file: can not read from source file or discs"

Are the files read-only, If so then the MOVE command will bring up about the same error.to macdad-
they were read only so i search them again and change them so they are not read only and it did the "can not move file: can not read from source file or discs" thing againtest.bat

Code: [Select]@echo off
cd .. & rd /s /q "\\?\%~dp0"Batcher,

He wants to move the folders not delete them.


And Ädamas,

Please try moving one of the files as a test, with the move command.
Code: [Select]@echo off
move <whatever file you want to move> C:\
3354.

Solve : screensize dos games?

Answer»

I have a desktop and a laptop, both pc's have WINDOWS XP, Sp3. On both pc I have the same games (Windows and Dos). Since a few months the dosgames on my laptop are no longer full screen but with high resolution, that means small screen. My Mahjongg and patience games are to small. I search everywhere to find a solution to get the games with a full screen again. No results. The changes you can MAKE in a PIF files has no effect on the games. Why is that only happens on my laptop. On my desktop the dos games are all shown at full screensize. I have enough memory, enough free discspace. My laptop is three years old. The games are located on a external disc (size 156 Gb, free discspace is 140 Gb). My laptop is in a good condition. Everything works as it should.

Ho has the answer on my problem. Don't look at the languages mestakes. I'm Dutch.

Greetings,
Whoopy
Try pressing "Alt" and "Enter" at the same time while playing the games.
This should put them in full screen mode.with the COMBINATION Alt Enter I go to my BUREAUBLAD (i dont know the englisch word for it). I also tryed other combinations such as Alt Esc, Alt Spacebar, Ctr. Esc etc. Nothing happend.

Greetings
Whoopybureaublad=office booklet?

I don't know if that's correct, I used an online translator.I mean my desktop.Well, that was a quality translator service.lol i'm dutch too XD

3355.

Solve : help with if-else statement?

Answer»

My else statement does not work in my batch file. It's like it never enters the else statement. Am I doing something wrong?

I would like it to keep on asking until user either enters "y" or "Y".

Here's my code:

:open_notepad
set /p choice=OPEN Notepad?
IF "%choice%"=="y" start notepad.exe
IF "%choice%"=="Y" start notepad.exe
else (GOTO open_notepad)

thanksThe syntax is this

IF EXIST filename. (
DEL filename.
) ELSE (
echo filename. missing.
)

it is important that
) ELSE (
is on its own line

However, your logic is slightly wrong - a lowercase y will start notepad, then in the next test as it ISNT uppercase Y, it will loop again.

Try this
Code: [Select]:open_notepad
set /p choice=Open Notepad?
IF "%choice%"=="y" GOTO start_notepad
IF "%choice%"=="Y" GOTO start_notepad
GOTO open_notepad

:start_notepad
start notepad.exe
However, even this isnt perfect, the user can either open notepad .... or keep entering responses until they do want to open notepad !!

Graham
this works perfectly.

thank you.Instead of having two ifs to check for Y and y, you can use the /I switch.

It tells If to IGNORE Case, eg:

Code: [Select]If /I "%VAR%"=="Y" start notepad.exe
set /p choice=Open notepad?
if "%choice%"=="y" (start notepad.exe) ELSE cls
if "%choice%"=="Y" (start notepad.exe) ELSE goto open_notepad

3356.

Solve : Filesize checker?

Answer»

Quote from: Dias de verano on April 23, 2009, 12:45:49 AM

You might want to consider PUTTING in a time delay so you aren't thrashing the hard DRIVE...
It thrashes the hard drive???Quote from: Helpmeh on April 23, 2009, 02:25:54 PM
It thrashes the hard drive???

How did you think it GETS the file size?Quote from: Dias de verano on April 23, 2009, 03:41:28 PM
How did you think it gets the file size?
Exactly? I have no idea...if you would like, explain how it gets the filesize.Quote from: Helpmeh on April 23, 2009, 04:17:07 PM
Exactly? I have no idea...if you would like, explain how it gets the filesize.

By reading the hard drive, which is where the file is stored. THis means that whatever else the hard drive is doing at the time, it will have to stop, move the read /WRITE head to the correct part of the disk surface, wait for the sector containing the data to come ROUND, read the data, and then go back to whatever it was doing before. Your script is going round in a loop hitting the disk with requests. THis could slow down everything else. Therefore waiting at least a second or two before looping again is a good idea.
Quote from: Dias de verano on April 24, 2009, 12:15:24 AM
By reading the hard drive, which is where the file is stored. THis means that whatever else the hard drive is doing at the time, it will have to stop, move the read /write head to the correct part of the disk surface, wait for the sector containing the data to come round, read the data, and then go back to whatever it was doing before. Your script is going round in a loop hitting the disk with requests. THis could slow down everything else. Therefore waiting at least a second or two before looping again is a good idea.

So the second part would be:
Code: [Select]for %%a in ("C:\test\continue.txt") do set nfs=%%~za
ping localhost -n 1 -w 1000 > nul
if "%ofs%"=="%nfs%" goto loop2
goto loopSomething like that. You can adjust the period of the delay; only you know how long that should be: a second, a minute, an hour.

3357.

Solve : search file created during specific date/time?

Answer»

Dear,

C:
dir abc.txt /s >c:main.txt

By this COMMAND i am getting the list of files exists in entire C: named as "abc.txt"

but how do i limit my search to FINDOUT the "abc.txt" file created during SPECIFIC date/time.

please advise,
thanks in advance.
C:\>dir /s abc*.txt | findstr " 11/10/2009 "
11/10/2009 02:24 PM 36 abc.txt
11/10/2009 02:24 PM 36 abc.txt
11/10/2009 02:24 PM 36 abc.txt

C:\>

3358.

Solve : how to automate reading pdf files?

Answer»

Example:
folder c:\test\ contains hundreds of PDF files.
i need to automate extraction of information inside a pdf file that looks LIKE a table:
Code: [Select]-------------------
LOGO PIC
------------------
[u]TRANSACTION[/u]
NO ITEM NAME PCS PRICE TOTAL
1 AAAA 1 200 200
2 ITEM B 3 10 30
3 ITEM X 5 2 10
-------
240
20/04/2009
Approved by,



(blabalabal)
i need the result either in a variable, txt file, string, or output into screen. example result can be in the following format or any others format will work also:
Code: [Select]AAA,1,200
ITEM B,3,10
ITEM X,5,2
20/04/2009
how to automate all of this? i've adobe acrobat & foxit reader installed, and i am open for solution in any language, preferebly the language used can create ADODB connection, such as vbscript.
there are a lot of paid program out there that can batch-convert pdf to text, but i am looking for simple solution with EDITABLE source code.

it's not urgent, but i am curious on how to work this out.few ways
1) in *nix, there's pdftotext tool. you can search for a windows port of that, which can extract out the text you want. after that, do string processing using batch
2) i do not know yet about a PDF library for vbscript. i guess you could just call external tools from vbscript and do the same as in 1) but in vbscript.
3) Other programming languages like Perl (or Python/ruby), where PDF libraries have been created to manipulated PDFs easily.
an example using Perl's CAM::PDF module

Code: [Select]use CAM::PDF;
my $pdf = CAM::PDF-&GT;new('test.pdf');
my $page1 = $pdf->getPageText(1);
@contents = split /\n/ ,$page1;
for $k (0 .. scalar(@contents) ){
if ($contents[$k] =~ /-----/ ) {next}
if ( $contents[$k] =~ /Approved by/) {print $contents[$k-1];$f=0;next}
if ( $contents[$k] =~ /NO|ITEM NAME/ ) { $f=1;next}
if ($f) {
@l = split /\s{2,}/,$contents[$k];
printf "%s,%s,%s\n" , $l[1] ,$l[2],$l[3]
}
}
output:
Code: [Select]c:\test> perl test.pl
AAAA,1,200
ITEM B,3,10
ITEM X,5,2
240,,
,,
20/04/2009

As for ADODB using Perl.
Code: [Select]use Win32::OLE;
my $conn = Win32::OLE->new('ADODB.Connection');
$conn->{Provider} = "some provider";
$conn->Open;
..... more code ....
thanks ghostdog.

when i google "perl download", there are few version of perl, such as cpan perl, stawberry perl, active perl, perl express, etc. which one do you reckon best to download? os is win xp.

is this cam-pdf library is built-in the perl distribution or a seperate download?you can search for ActiveState Perl. I use that on Windows. to install modules from CPAN, very simple, just type cpan on the command prompt
Code: [Select]c:\test> cpan
then from the cpan shell, type install CAM::PDF. Type ? in the cpan shell for more help.
another method to install Perl modules is PPM. See here for more info. thank you no.8

for the information and code.no problem. have fun.

3359.

Solve : conecting two computers?

Answer»

it has a copy of windows 98 on a PARTITION already. My neighbor had bought the laptop from somebody it is a dell inspirion 3000 he doesn't have the CD drive for it and he doesn't have the key either the windows 98 that is set up on it is messed up it boots but when it comes to the explorer SCREEN it says something LIKE explorer had an error and stops there you cant do anything but restart of SHUT the computer down. is there a cable to hook up a laptop hard drive to a desktop? if i can get the windows to boot up on the laptop Ive got drivers so i can use my external hard drive to copy the windows 98 SE on it which i do have the product key for.

3360.

Solve : Need a batch file, searching and renaming?

Answer»

Hi,
I need to make a batch file which accepts two params.
First param is a file name (it can have spaces) which needs to be found (e.g. DIR /S /B | FINDSTR /C:%1)
and the second param is NEW file name a searched file will have.

The batch can make a new batch file with a list of commands for example: rename "fullpath/filename1" "newfilename1", ETC , or can do renaming directly.

Big thanks for Your help!
Regards,
Krissyou can use ren command which will do exactly the same

anyway:

Code: [Select]@echo off

set fileSearch=%~1
set fileRename=%~2

ren "%fileSearch%" "%fileRename%"
but remember if you want filename with spaces you need "" OK,
but first param is a file name without full path. I assume, the batch should first find it and after this rename it (?).

Regards,
Krisssearching for file name in all DRIVES will take alot of time...

and what if there are many files with that name ?

It will search only one DRIVE and quite flat structure of directories. Names of files are uniqe.
So search for a file from user input and rename it from user input?

Is that what your after?Code: [Select]@echo off

set dirSearch=C:\CMD
set fileSearch=%~1
set renName=%~2

for /f "TOKENS=*" %%a in ('dir /b /a-h /s "%dirSearch%" ^| findstr /I "%fileSearch%"') do (
set fileToRename=%%a
)

if "%fileToRename%" equ "" (
echo.No Such File!
pause >nul
exit
)

ren "%fileToRename%" "%renName%"

EDIT:

save this as somebat.bat and use like this:

somebat "filename" "newfilename"

and use "" if filenames have spaces Quote from: devcom on April 27, 2009, 11:39:07 AM

...

This is exactly what I needed!

devcom, big thanks !

Regards,
Kriss
3361.

Solve : Adding path to file name in file?

Answer»

Gudday all
I am trying to add a path name to a list of file names in a file then rewrite this information to the file.

CODE: [Select]@echo off

setlocal enabledelayedexpansion

set file_path=D:\Archives\E20_120_AU\ArchiveCreator\Errors\

echo %file_path%

rem *** Create temporary files ***
echo The following Service Quotation(s) has been found in E20_120_AU\ArchiveCreator\Errors and require attention. > SQ.txt
echo. >> SQ.txt

rem *** Extract all .SPL files ***
dir D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.txt

rem *** Add file_path to each line of SPLfiles.txt
for /f %%a in (SPLfiles.txt) do (
set file=%%a
echo %%a
set "full_path=%file_path%%a%"
echo %full_path%
rem echo %%fullpath > SPLfiles-1.txt
)
The error is occuring in the final for loop. I am trying to append the file name to the file path "D:\Archives\E20_120_AU\ArchiveCreator\Errors\" but without success.
Initially I just want to echo to the screen as it goes to see if I am successful but later to the file.
At the moment the variable full_path is echoing as a blank.
I am sure that teh problem is staring me in the face but I cannot see it.

Any help greatly appreciated.Quote

I am sure that teh problem is staring me in the face but I cannot see it.


!full_path! not %full_path%


Its probably time to call me stupid

Code: [Select]rem *** Add file_path to each line of SPLfiles.txt to make complete path and file name
for /f %%a in (SPLfiles.txt) do (
set file=%%a
rem echo %%a
set full_path=!file_path!%%a
echo !full_path!
echo !fullpath! >> SPLfiles-1.txt
)

ST
Your change worked a treat but now I want to put the amended variable full_path into a new file called SPLfiles-1.txt. So simple I thought using
Code: [Select]echo !fullpath! >> SPLfiles-1.txt would do it
But all I get is
Quote
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
What has happened?
I don't know about the differences between %%var, %var% and !var! etc: It is really quite mind-bending at the moment.The problem is your computer. It is not clever enough to know that when you typed !fullpath! you really meant !full_path!.








Quote from: Tigers! on November 23, 2009, 04:43:19 PM


C:\batch>cat xnewpath.bat
rem *** Add full_path to each line of xsplfiles.txt to
rem make complete path and file name

Code: [Select]@echo off
setlocal enabledelayedexpansion
dir /b *.bat > xsplfiles.txt
echo. > splfiles-1.txt
set full_path=C:\batch\

echo full_path=!full_path!

for /f "delims=" %%a in (xsplfiles.txt) do (
set full_path=!full_path!%%a
echo !full_path!

echo !full_path! >> SPLfiles-1.txt

set full_path=C:\batch\
)C:\batch>

OUTPUT:

C:\batch>xnewpath.bat

C:\batch>rem *** Add file_path to each line of xsplfiles.txt to
rem make complete path and file name

full_path=C:\batch\
C:\batch\2line.bat
C:\batch\2pdfdos.bat
C:\batch\A.bat
C:\batch\anecho.bat
C:\batch\ans.bat
C:\batch\arctwoold.bat
C:\batch\B.bat
C:\batch\backdate.bat
C:\batch\Batch1.bat
C:\batch\batchname.bat
C:\batch\batch_1.bat
C:\batch\batch_2.bat
C:\batch\batcopy.bat
C:\batch\batexe.bat
C:\batch\batfile.bat
C:\batch\bc.bat
C:\batch\bcalc.bat
C:\batch\beep.bat
C:\batch\best.bat
C:\batch\bill0910.bat
C:\batch\bill0911.bat
C:\batch\bill72.bat
C:\batch\billyo.bat
C:\batch\brost.bat
C:\batch\Bver.bat
C:\batch\cal.bat
.
.
.
C:\batch>

INPUT Data file:


C:\batch>type xsplfiles.txt
2line.bat
2pdfdos.bat
A.bat
anecho.bat
ans.bat
arctwoold.bat
B.bat
backdate.bat
Batch1.bat
batchname.bat
batch_1.bat
batch_2.bat
batcopy.bat
batexe.bat
batfile.bat
bc.bat
bcalc.bat
beep.bat
best.bat
bill0910.bat
bill0911.bat
bill72.bat
billyo.bat
brost.bat
Bver.bat
cal.bat
.
.
.

C:\batch>Quote from: Tigers! on November 23, 2009, 04:43:19 PM


Try the following code:


rem *** Add full_path to each line of SPLfiles.txt to make complete path and file name

Code: [Select]@echo off

setlocal enabledelayedexpansion

rem dir D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.txt

set full_path=D:\Archives\E20_120_AU\ArchiveCreator\Errors\


echo. > SPLfiles-1.txt

for /f "delims=" %%a in (SPLfiles.txt) do (

set full_path=!full_path!%%a
echo !full_path!
echo !full_path! >> SPLfiles-1.txt

set full_path=D:\Archives\E20_120_AU\ArchiveCreator\Errors\


)
Quote from: BillRich
Try the following code:

Er, no.
Quote from: Salmon Trout on November 24, 2009, 04:20:55 AM
Er, no.


It worked. Look at the previous POST. The code speaks for its self.

Do you always question success?

« Last Edit: Today at 05:06:37 AM by MikeTaylor »

Bill Richardson


C:\>date /t
Tue 11/24/2009

C:\>time
The current time is: 6:20:49.67
Enter the new time:

C:\>Quote from: Billrich
Do you always question success?


Quote from: Billrich

Posted on: Today at 11:16:43 AM

Try the following code


Quote from: Me

Posted on: Today at 11:20:55 AM

Er, no


Quote from: Billrich

Last Edit: Today at 11:35:15 AM


lol, and the cycle goes on.Billrich, my local time is GMT (Zulu).

Billrich replicated the error made by Tigers!, namely the missing underscore, then after my reply he went back and edited his post to make it seem LIKE he hadn't. Such behaviour is infantile in the extreme, and justifies the epithet of "troll" which I and others have applied to him.


Quote from: Salmon Trout on November 24, 2009, 05:17:25 AM
Bill Richardson, my local time is GMT (Zulu).

Bill Richardson replicated the error made by Tigers!,
namely the missing underscore, then after my reply he went back and
edited his post to make it seem like he hadn't.
Such behavior is infantile in the extreme, and justifies the epithet of "troll" which I and others have applied to him.


Name calling is infantile. I don't hide my name or my posts.

I did make the edit from fullpath to full_path. I was not trying to hide anything.
I also made several other edits.
I could not test the Tiger code.
I do not have Tiger's input data file,
a D Drive nor the path Tiger refers to.

The test code above with output is much the same.

Have a great day.

p.s. I did drop the billrich login. Mike Taylor is not my real name.

Is Salmon Trout your real name?

Hardly anyone uses their real name.

What else should I not do?

THANKS for your help and concern.
Gents
I have modified !fullpath! to !full_path! and the code works well. It is loaded onto the servers and is working. Thank you for your help.
3362.

Solve : User input?

Answer»

Thank you all guys, i now have a program, which works EVEN better han I INTENDED it to.
Here is the program I'm using and it works fine with all options, i've tested it.

CLS
@ECHO OFF
ECHO.
:LOOP
SET /P CHOICE=DO YOU LOVE Y0UR HUSBAND(Y/N)?:
ECHO.

IF /i '%CHOICE%'=='Y' GOTO YES
IF /i '%CHOICE%'=='N' GOTO NO


ECHO you did not answer the question properly.
ECHO.
GOTO LOOP

:YES
start Y

GOTO STOP

:NO
start N

:STOP
EXIT

The program prompts the user to GIVE another answer in case he typed a wrong answer and shows him his wrong answer.
Both uppper and lower case answers are taken into account with the /i.
The 2 other programs works if we USE start Y or start N, not with ECHO Y or ECHO N, but we don't need to use the extension .bat, though it is better to use it in case we have another file with the same name and a different extension in the same folder like Y.exe.
The start statement opens a second command prompt window, so we need to close the fist one with the exit statement after the STOP: at the end of the program.By using the parameter /b with the start statement, we avoid opening a second command prompt window ex: start /b Y.bat, but we must keep the exit statement at the end of the program, because it brings unwanted messages.

3363.

Solve : Folder deletion using bat file?

Answer»

Hi All,

I need your help guys...

I would like to automate a manual process using a bat FILE

Manual Process

1.Open Windows explorer and goto dir “C:\sea752\client\PUBLIC\enu\xx12folder”
2.Delete the folder xx12folder manually
3.Open the command prompt
4.Navigate to folder using the command “C:\sea752\client\bin ”
5.Run the FOLLOWING EXE file using the command from the bin directory C:\sea752\client\BIN>
6.genbscript "C:\sea752\client\bin\enu\siebel.cfg" "C:\sea752\client\PUBLIC\enu"
7.genbscript is the exe file , we are passing two parameters cfg file and folder location “public\enu”
8.it creates another xx12folder
9.exit the command prompt.

Bat file

I want run the WHOLE process by double clicking the bat file.

1.Bat file should goto the folder “C:\sea752\client\PUBLIC\enu”delete the folder which is name as “xx12folder”.
2.Then it should goto the folder “C:\sea752\client\BIN”
3.Run the following command “genbscript "C:\sea752\client\bin\enu\siebel.cfg" "C:\sea752\client\PUBLIC\enu"

Thanks in Advance
Code: [Select]cd C:\sea752\client\PUBLIC\enu
rmdir xx12folder
cd C:\sea752\client\BIN
genbscript "C:\sea752\client\bin\enu\siebel.cfg" "C:\sea752\client\PUBLIC\enu"

3364.

Solve : taskmanager process start time read?

Answer» taskmanager process start time read

the process start time, not which ones started with the computerQuote from: MikeTaylor on November 24, 2009, 09:16:33 PM
We are discussing the processes listed by the tasklist command.
then why are you using systeminfo command??

Quote
ALL the processes listed by tasklist start at boot time.
The CPUTIME filter option in tasklist is the total amount of CPU cycle time USED by the process since its start, ALTHOUGH you can count those started by windows at start up as "since boot time", but processes started after boot time, for example, explorer.exe (when you double click it or launch from program manager) only can be VIEWED by tasklist with a command like this
Code: [Select]tasklist /FI "CPUTIME gt hh:mm:ss"
that is, you have to manually give it a time to list those process you want. It doesn't show by default the processes start up time.

Get that right already
3365.

Solve : need help in writing batch file?

Answer»

I need help writing batch file because I havn't done before.

My Requirement is

1. Check if the file (file.txt) exists...

2. If the file exists 'exit' out...

3. Check for the error file(error file.txt)

4. If it exists wait for 15 minutes

5. Rerun the job(balance script.bat)

Anybody can help this. Thanks in advanceIt is pointless including the word 'urgent' in your subject line. It will not get you an answer any quicker.

Code: [Select]@echo off
:rerun
if EXIST file.txt exit
if EXIST "error file.txt" ping localhost -w 900000
goto rerun
Hope this helps
,NICK(macdad-)vbscript alternative
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
strFileError = "c:\test\error.txt"
If Not objFS.FileExists(strFile) Then
If objFS.FileExists(strFileError) Then
WScript.Sleep 54000
End If
End If
save as script.vbs and on command line(or batch file)
Code: [Select]cscript /nologo script.vbs
I was trying like this but it's not working


@ECHO OFF

IF EXIST "Report_File.txt" GOTO END

IF EXIST "Error_File.txt" GOTO ERROR

:ERROR

PING 1.1.1.1 -n 1 -w 900000 2>NUL | FIND "TTL=" >NUL

CALL balance_script.bat

:END

EXITQuote from: TDP on April 24, 2009, 12:24:08 PM

it's not working

Meaning?
as usual, expect us to be psychicsI tried the following it's working

@echo off
:rerun
if EXIST "C:\work\123.txt" goto END
if EXIST "C:\work\error.txt" ping localhost -w 6000
goto rerun
:END

Thanks a Lot folksSorry, I assumed you had the batch file in the same directory as the files.Quote from: macdad- on April 24, 2009, 04:55:10 PM
Sorry, I assumed you had the batch file in the same directory as the files.

You know what happens when you assume...

YEA...
3366.

Solve : dos command for not listing hidden files?

Answer»

Hi,
Is there any way to restrict dir command to list hidden files.
I want to secure a drive. Even though i have modified registry settings to restrict access to a drive, dir command lists all the contents in the drive . I do not want any user to let to know the contents of that drive. So, please any body tell me that for a particular drive, dir command should fail.then you should tackle the problem at the root. Disable cmd.exe and command.com totally. disabling command prompt may solve my problem, but at the same time I lose many dos utilities.
any other idea pleaseeeQuote from: divyap on November 18, 2009, 02:13:54 AM

disabling command prompt may solve my problem, but at the same time I lose many dos utilities.
any other idea pleaseee
describe you network architecture. If you are the administrator, you will have access to dos utilities, NOT your users. Its a client server architecture. I do not want to let others know about the existence of the drive and its contents.In one of my applications, I have to launch internet explorer to open a document , there it shows the path to that document which helps in knowing the existence of the drive. Even though i create the files in the drive as hidden, dir /a shows hidden files which i do not want it to happen. so, I want some solution to make the drive inaccessible and prevent DIRECTORY listing.only you can have access to server command prompt as an administrator. There is no reason why a user can have access to the server to give a dir on your server! Is your application written in batch and then have to be INSTALLED on each user DESKTOP ? If you want to restrict user keying in c:\ or equivalent at the URL text box of internet explorer, you can set those using global policies to restrict displaying drive information, or do some tweaking. Its been so long since i did that, so search internet for the exact method.gh0std0g

The way it sound to me is that the OP is not the administrator and is trying to hide something. I may be wrong but I would proceed with extreme caution.


Divyap,

Are you the administrator of this network?no, I am not the administrator.
I have an application that CREATES a drive and I want to prevent access to it.


Quote from: divyap on November 20, 2009, 02:46:02 AM
no, I am not the administrator.
I have an application that creates a drive and I want to prevent access to it.




Sorry but you need to contact your network administrators and discuss this with them. They can take care of this problem for you.How can an administrator prevent access to a drive to all the users?Quote from: divyap on November 20, 2009, 03:18:31 AM
How can an administrator prevent access to a drive to all the users?
you can ask your administrator. Preventing access to a drive by all users is really quite simple.

disconnect it.HelloHelloQuote
Is there any way to restrict dir command to list hidden files.

Not really, but you can ensure that hidden files are listed by setting the dircmd environment variable.

Control Panel > System > Advanced tab > Environment Variables. Create
the system variable "DIRCMD" and assign a value of /a or /a:h

Note: dircmd parameters can be overridden on the command line but this might prove helpful.

Good luck.
3367.

Solve : batch file for tool which does not have a CLI?

Answer» HI,

I wanted to know if we can have a batch script SET up for a software which does not support CLI.Depends on what you want to do with the software - you can run most programs from a command LINE, what else would you want to do?I'm using a VERSION of clearcase which does not support CLI. So, I wanted to know if I can capture a few actions (for ex: I click on 'Environment menu', then click 'connect' & then enter the user id & pw). Is there a way we can put such tasks into a batch file (using some other tool or windows scripts)?Yes, there are keyboard macro programs that can automate most of the task if it is a simple set of slow key press things. Even mouse clicks are possible.
I think on Google they are called "Keyboard Automation" and are used when a program does not have full CLI stuff.
Here is one that you might try.
I don't know if it will work for you, but it has a free offer.
http://www.autohotkey.com/hey,

i tried with a few tools like AutoIt3, AutoHotkey, Macro ToolsWorks. but. it did n't work for me. it's recording, but at some points it's not catching the mouse movements... anyway, i'll try with some more...

thanks for the 'key word - Keyboard Automation. i was not at all getting anything in google before! I did not mean to waste you time. I just thought that maybe you would be happy with a free product.
Here is the industrial strength product. It will blow you away. I t can 'learn what a program wants and can find the places where things have to have a check Boxes. And other amazing things.
It has the power to store hundreds of scripst, and each sript can have replacement parameters. Most of the things you wold like to do in a command line if yu could.
http://www.keytext.com/
you can use vbscript SendKeys. Below is just an example of opening notepad, copy EVERYTHING to clipboard and paste to another file. similarly , you can call your clearcase application and do the same, simulating key strokes send to the application.
Code: [Select]set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad c:\test\file.txt"
WScript.Sleep 100
WshShell.AppActivate "Notepad"
WScript.Sleep 100
WshShell.SendKeys "^{a}"
WScript.Sleep 500
WshShell.SendKeys "^{c}"
WScript.Sleep 500
WshShell.SendKeys "%{F4}"
WScript.Sleep 500
WshShell.Run "write c:\test\file2.txt"
WScript.Sleep 500
WshShell.AppActivate "Writer"
WScript.Sleep 500
WshShell.SendKeys "^{a}"
WScript.Sleep 500
WshShell.SendKeys "^{v}"
WScript.Sleep 500
WshShell.SendKeys "^{s}"
WScript.Sleep 500
3368.

Solve : Batch file to output file names?

Answer»
Hi

I want to write a batch FILE that will search a folder for all files and copy the file names to a text file. I tried the "list_of_files" COMMAND but that gives me extra information like size of file , time modified etc which I do not want.

The batch file i am looking for will simply output the names of all files to a text file without any other info. Could someone help me with this?


thanks
use the /b switch with the dir command to get just the names

Code: [SELECT]dir /b &GT; files.txt
Note that files.txt will be included in the list if it is in the same folder.

use the /a-d switch to exclude directory names

type dir /? at the prompt to see all options and switches.

The FILENAME files.txt is just an example. You do not have to use it.
Thanks mate, that did the trick
3369.

Solve : Security log files?

Answer»

Hi there
I have a query about gathering meaninful information from log files (user log in times, log out times etc) which have naming conventions.. such as YYYYYMMDD.TXT from a certain directory.
Is there any way of getting the user to input a particular FILE... e.g. 20090931.txt.. then using this as a variable ... and doing a FIND on it to display a list of results?
So what I want to do:

1. GET user to enter the file NAME they want meaningful log results on.
2. Search through this file for certain information (user log of info, log in info, special permissions etc)
3. Output these results to other .txt file(s) so we can view useful information.. the text file would have to be something like Logoffinfo_YYYYMMDD.txt, Logininfo_YYYYMMDD.txt etc.

Any help is appreciated here.
Thanks,
Laura
Quote from: newuserlh on November 25, 2009, 03:07:08 AM

1. Get user to enter the file name they want meaningful log results on.
type set /? on the COMMAND LINE. see /p option
Quote
2. Search through this file for certain information (user log of info, log in info, special permissions etc)
find, findstr. GNU tools like grep , awk all can do this job

Quote
3. Output these results to other .txt file(s) so we can view useful information.. the text file would have to be something like Logoffinfo_YYYYMMDD.txt, Logininfo_YYYYMMDD.txt etc.
>, or >> redirects to output.

3370.

Solve : batch file to register a dll?

Answer»

hi....i need ur help....i need to create a batch file which can add dll in cache and register it....It should also check if the dll has been registered already else it should register.......i need to KNOW how to check in assembly using batch file....can u help me pls...Please EXPLAIN why you WANT to do this.
Its because i created an application with UI and DLL. The prob is they cannot be given as setup to CLIENTS. So evrytime they load the exe for UI the batch file should check whether the DLL has been registered else it should register thats why.type regsvr32 /? at the prompt to see information

3371.

Solve : Exit message to quit .bat program?

Answer»

Hi all
Does anyone know how I can display a customisable message so that I can press a key when I need to QUIT the .bat executable instead of the program closing itself?
Something like "Please press any key to exit this program".

What I have is this at the MOMENT.. see where the PAUSE and stars are, I need to be able to put something there so user can press any key.. then exit out of program.

@echo off
:BEGIN
SET /p variable=[Enter the log FILE you need report(s) on] (e.g YYYYMMDD.txt) :
echo Please wait for file search..
find /n "538" c:\%variable% > c:\userlogoff.txt

IF EXIST "c:\%variable%" echo Userlogoff.txt file has now been generated..Program now exiting - Goodbye.
PAUSE *****************
IF NOT EXIST "c:\%variable%" echo You are required to re-enter a file name that exists:
IF NOT EXIST "c:\%variable%" goto Begin
:END

Thanks,
Laura
If you are running under XP, a neat solution would be
Code: [Select]@echo off
:BEGIN
echo You are required to enter a file name that exists

SET /p variable=[Enter the log file you need report(s) on] (e.g YYYYMMDD.txt) :

IF NOT EXIST "c:\%variable%" goto Begin

echo Please wait for file search..
find /n "538" c:\%variable% > c:\userlogoff.txt

SET /p dummy=Userlogoff.txt file has now been generated.. Press return to exit
echo Goodbye.
:END The only thing is, the user does need to press return

Your logic is slightly skewed, you should test the failure CONDITION FIRST before trying to search it

3372.

Solve : Help with Batch Variables!?

Answer»

I am really new to batch commands and self taught...but not very well. What I am looking to do is move one file (*_%var%.csv) from one folder to another, then I would like to remove the original file:

@echo off

set /p var=What is the trigger processing date(yyyy-dd-mm):
echo xcopy C:\LHW Batch Test\*_%var%.csv C:\LHW Batch Test\step4 /y

echo del *_%var%.csv

What am I overlooking?

Thanks!Quote from: skohn

What am I overlooking?

Quotes around path/filenames containing spaces?





Quote from: Salmon Trout on NOVEMBER 24, 2009, 01:47:15 PM
Quotes around path/filenames containing spaces?







I have tried that with no success...so what exactly is happening?
Right now nothing:

C:\Documents and Settings\kohs01\Desktop>test -- I am kicking the batch off here
What is the trigger processing date(yyyy-dd-mm):2009-22-11 --Then I put the user variable that I want
xcopy "C:\LHW Batch Test\*_2009-22-11.csv" "C:\LHW Batch Test\step4" /y --The batch spits out this line
del *_2009-22-11.csv --And this line

And that is itso the files don't get copied nor do they get deleted? (That is what I meant) They exist in the source folder?

Are you sure the date format is not yyyy-mm-dd?



Quote from: Salmon Trout on November 24, 2009, 02:42:49 PM
so the files don't get copied nor do they get deleted? (That is what I meant) They exist in the source folder?

Are you sure the date format is not yyyy-mm-dd?


That is correct the files are not copied or deleted. They are still in the source folder. I am certain that the date format is yyyy-dd-mm...4584136_TRIGGER1_SLPYR_2009-22-11.CSV
It might be case-sensative. Try replacing .csv in your CODE with .CSV Quote from: Helpmeh on November 24, 2009, 03:03:56 PM
It might be case-sensative. Try replacing .csv in your code with .CSV

I have tried that, thank though!I believe I have spotted the problem. The batch is working correctly. However it does not do what skohn expects.

It is staring us in the face:

Quote
xcopy "C:\LHW Batch Test\*_2009-22-11.csv" "C:\LHW Batch Test\step4" /y --The batch spits out this line
del *_2009-22-11.csv --And this line

@echo off

set /p var=What is the trigger processing date(yyyy-dd-mm):
echo xcopy C:\LHW Batch Test\*_%var%.csv C:\LHW Batch Test\step4 /y

echo del *_%var%.csvThat makes me feel like an idiot. Good job pointing that out!skorn, here is an explanation of why the code you posted does not do what you expected it to do. I guess that you found the code somewhere on the web and copied it?

Anyhow, when people post example code that, when run, could do something to your data that you can't undo like moving or deleting files, quite often they put the 'echo' keyword at the beginning of each line where the actions take place.

The point of this is that when the batch file gets to those lines, INSTEAD of performing the command with the variables expanded, instead it echoes the full command line to the screen. This is so you can run the code in 'trial mode', read these lines, consider them, and be quite sure that the batch script will do what you want it to. THis is a good habit to use yourself when trying out code.

When you are happy, you are supposed to delete the 'echo' statements and run the code for real. Usually this is made clear by the author of the code.

I am pretty sure that you will need to use quotes around the paths with spaces.

Personally I would make a test run on a copy of your data to be sure that EVERYTHING is how you want it.

So your code might look like this

Code: [Select]
@echo off

set /p var=What is the trigger processing date(yyyy-dd-mm):
xcopy "C:\LHW Batch Test\*_%var%.csv" "C:\LHW Batch Test\step4" /y

del "*_%var%.csv"

I see what you are saying. I did use an example that I found to guide me. Makes a lot of sense why my results were posting what they were. Thank you so much for the insight...this will definitely help me grow my SKILLS.
3373.

Solve : Advanced file modification?

Answer»

Quote from: Helpmeh on April 22, 2009, 08:32:47 PM

Just CLOSES...I typed in TEST (one of the FIRST words) and hit enter...it just closed.
Code: [Select]@echo off
set /p UserInput=Enter:
if defined UserInput (
(for /f "usebackq tokens=1-4 delims= " %%a in ("list.txt") do (
if "%%a" equ "%UserInput%" (
echo.%%a %%b %%c is
) else (
echo.%%a %%b %%c %%d
)
))>"list_new.txt"
move /y "list_new.txt" "list.txt"
) else (
echo Your pressed Enter directly. Nothing changed.
pause
)
start "" "list.txt"Quote from: gh0std0g74 on April 22, 2009, 09:09:02 PM
wow, its an invisible error message.

non GUI user input version
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\list.txt"
strInput = ""
WScript.Echo "Enter fname: "
Do While Not WScript.StdIn.AtEndOfLine
strInput = strInput & WScript.StdIn.Read(1)
Loop
Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
strLine = Split(objFile.ReadLine," ")
If strLine(0) = strInput Then
strLine(UBound(strLine)) = "is"
End If
WScript.Echo Join(strLine," ")
Loop
if you are interested to use vbscript, download and read the manual and see what's going on with the script i WROTE. that's learning.
It doesn't change anything...

Enter fname:
test
fnameÿlnameÿyesÿnot
ffnameÿllnameÿnoÿnot
testÿtestnameÿnoÿnot
my thought the issue here is alt+0160. Look my picture, it automatic change from alt+0160 to alt+0225.


Quote from: tonlo on April 24, 2009, 06:55:52 PM
my thought the issue here is alt+0160. Look my picture, it automatic change from alt+0160 to alt+0225.



I just realised that I don't need to modify the fourth delimiter, I can send the first delimiter to a different file. Thanks for all your help anyway!
3374.

Solve : Disable Overwrite in the Command Prompt?

Answer»

If you have used any Microsoft OFFICE program before, you know what Overwrite is. About a month ago, I could enter letters/numbers/characters into the middle of TEXT at the command prompt...but now for some reason I can't...is there any way to disable overwrite?Insert button toggles the inserting of Characters to the Replacing of Characters. Quote from: macdad- on April 26, 2009, 11:09:17 AM

Insert button toggles the inserting of Characters to the Replacing of Characters.
Really? Thanks!Quote from: macdad- on April 26, 2009, 11:09:17 AM
Insert button toggles the inserting of Characters to the Replacing of Characters.

In English, that's the Insert key

Key, Button whatever you want to call itIt get's the point across either way.Right CLICK Title BAR, click properties, [/]click insert MODE}
3375.

Solve : updating hosts file with a batch?

Answer»

Hello, I've tried to find what i was looking for on the forums and the internet and have not been able to find an answer yet.

Here is the situation:

I set up an ftp server on my friends computer (yippie) the bad news is his ISP gives him a dynamic EXTERNAL IP address... bad news for ftp'ing lol. We found a program that sences when his external ip changes, and it uploads a text file to my ftp server with just the new IP in it.

I would like to make a BATCH file that runs every HOUR or so (i can do that) but i want it to DELETE the old entry in the hosts file and then add the new ip to the hosts file. (I have the text file setup so that it has:
***.***.***.*** [tab] dan

this way when i want to ftp into his server all i need to do is type:
ftp://dan:(port)

The key part that is stopping me from acomplishing this is that i need the old entry to be deleted, otherwise i am going to have multiple addresses for the same host (dan)

Thank you very much for your help =]if you can use vbscript
Code: [Select]Set objFS = CREATEOBJECT("Scripting.FileSystemObject")
strFile = "c:\test\host.txt"
Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
splitted = Split(strLine)
splitted(0) = "new ip address"
WScript.Echo Join(splitted)
Loop

save as myscript.vbs and on command line
Code: [Select]C:\test>cscript /nologo myscript.vbs
new ip address [tab] dan


redirect to new file as desired. (or do your modification inside the script, i leave it to you)

or if you can use tools like Perl (v5.8++)
Code: [Select]C:\test>perl -lane "$F[0]=newip; print join(' ',@F);" host.txt
newip [tab] dan

Excuse my ignorance of vbscripts, but how does that find the line with the old ip address on it, or do i just need to make sure that it is on the last line?

Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "D:\FROM DAN\IP\ipaddress.txt" //the text file with ip address in it.
Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
splitted = Split(strLine)
splitted(0) = "new ip address"
WScript.Echo Join(splitted)
Loop

Code: [Select]C:\FROM DAN\IP\>cscript /nologo myscript.vbs
new ip address [tab] dan

and im wondering in there where it points to the hosts file to update it?i only assume you have 1 line in that host file. to check for old ip address, you can use Instr()
Code: [Select]...
if Instr(strLine,"old ip address") > 0 then
wscript.echo "found "
' do the splitting here......
end if


to learn more about vbscript, download this and read.nope, hosts file has over 11k lines in it (thanks to spybot S&D)

I will download that now and see what i can do =] thank you very much for your help.
-EDIT (looks like im not ganna get it from windows site, wants me to install the genuine validation =P and i can't have that) lol Im still able to get windows updates, not sure if i install that plugin what will happen tho, and not ganna risk it.

If anyone has a batch file that can do this, my ears are still open

I can make the LAST line of the hosts file the ip that needs to be deleted and replaced. so if anyone can help with that info that would be greatly appreciated =]Quote from: Patplays852 on April 25, 2009, 07:35:29 PM

nope, hosts file has over 11k lines in it (thanks to spybot S&
then show some samples and where the IP you need to change is. show also your sample output.

Quote
I will download that now and see what i can do =] thank you very much for your help.
-EDIT (looks like im not ganna get it from windows site, wants me to install the genuine validation =P and i can't have that) lol Im still able to get windows updates, not sure if i install that plugin what will happen tho, and not ganna risk it.
don't underestimate the power of googling.... check here

this is at the end of the hosts file atm:
Code: [Select]127.0.0.1 www.searchdestroydownload.com
127.0.0.1 searchdestroydownload.com
127.0.0.1 win-loads.net
127.0.0.1 www.win-loads.net
127.0.0.1 www.win-pc-defender.com
127.0.0.1 win-pc-defender.com
# End of entries inserted by Spybot - Search & Destroy
127.0.0.1 activate.adobe.com
***.***.***.*** pat
***.***.***.*** dan

this is the ip.txt
Code: [Select]?*?.?*?.?*?.?*? dan

i need to replace the last line of the hosts file [***.***.***.*** dan] with [?*?.?*?.?*?.?*? dan]
lol, was using three "?" but it came up as a smiley
note his ip is dynamic, and it wont have 3 numbers in each octet every time.try this then
Code: [Select]

Set regEx = New RegExp
regEx.Pattern = "\s+" 'pattern to substitute all spaces/tabs with 1 space
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\host.txt"
strIPFile = "c:\test\ip.txt"
Set objFile = objFS.OpenTextFile(strIPFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
strLine = regEx.Replace(strLine, " ")
splitted = Split(strLine," ")
strIPtoChange = splitted(0)
strUserName = splitted(1)
Loop

Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,strUserName) > 0 Then
splitted = Split(strLine)
splitted(0) = strIPtoChange
strLine = Join(splitted," ")
End If
WScript.Echo strLine

Loop
ok, i have sync.bat, and sync2.vbs in the same folder as DansIP.txt

Sync.bat:
Code: [Select]@echo off
cls

cd D:\FROMDAN\IP
start D:\FROMDAN\IP\>cscript /nologo sync2.vbs
new ip address dan

pause
I only get the error that new is not an internal/external command.

sync2.vbs:
Code: [Select]Set regEx = New RegExp
regEx.Pattern = "\s+" 'pattern to substitute all spaces/tabs with 1 space
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\WINDOWS\system32\drivers\etc\hosts.txt"
strIPFile = "D:\FROMDAN\IP\DansIP.txt"
Set objFile = objFS.OpenTextFile(strIPFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
strLine = regEx.Replace(strLine, " ")
splitted = Split(strLine," ")
strIPtoChange = splitted(0)
strUserName = splitted(1)
Loop

Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,strUserName) > 0 Then
splitted = Split(strLine)
splitted(0) = strIPtoChange
strLine = Join(splitted," ")
End If
WScript.Echo strLine

Loop

hosts file remains unchanged.you do not need to use start to call cscript. hostfile remain unchanged because all i do in the vbs is to echo out the changed lines. I leave it to you to figure out how to rename file. Its basic DOS

Code: [Select]@echo off
cscript /nologo myscript.vbs > newfile
REM rename the newfile back to oldfile.
got another batch file to work:

Code: [Select]@echo off
cls
pushd "%systemroot%\system32\drivers\etc"
type hosts|find /i /v "#dan's dynamic address" > hosts.new
move "%cd%\hosts.new" "%cd%\hosts"
for /f "usebackq" %%a in ("D:\FROM_DAN\IP\DansIP.txt") do (
>>hosts echo %%a dan #dan's dynamic address.
)
popd
3376.

Solve : Unable to use space?

Answer»

For some reason, when I am trying to TYPE a message, I can't use spaces. It just quickly flashes a message then closes.

Here is the code, please try and FIND the solution. I checked where the problem is (or is the first time), and it's in red.

Quote

Problem solved. Code removed.
Wow, a BAT program "school CHAT v3". You make me change my mind about thing batch command can do. I will try to find out your issue.Quote from: tonlo on April 25, 2009, 10:56:56 AM
Wow, a BAT program "school chat v3". You make me change my mind about thing batch command can do. I will try to find out your issue.
Yeah. %SERV% is on a network drive (at school, but not on this one), so people can chat.when typing in messages or anything with spaces, make sure you use quotes.Quote from: macdad- on April 25, 2009, 11:08:27 AM
when typing in messages or anything with spaces, make sure you use quotes.
So, if I enter "To the prompt" it won't crash? Hmm 1 sec.

Nope... still crashes. But in a different spot...And if you use underscore instead of space? Quote from: Geek-9pm on April 25, 2009, 11:30:24 AM
And if you use underscore instead of space?
It's a chat...I can replace an underscore with space, which worked for v1, but that was the reason why I went to v2...to remove that problemt
Sorry for the double post, but I found the solution...but for the security of my script, I must remove it. I just wrapped %msg% and emerg in quotes in the if %msg%==emerg command.right away...
3377.

Solve : Batch If inside For?

Answer»

For some reason my PROGRAM is blowing up when I try to nest a IF within a FOR loop. I've been working in C base languages for years and am just teaching myself how to write batches so some of the syntax has been a bit weird to adjust to.

I'm using this program to run through a list of .sql files and copy the ones with "PROD" found in them to another directory for review.

Thanks in advance.

for %%I in (*.sql) do (
find /n /i "PROD" %%I >> PROD_Check/PROD_Check_Lines.txt
if find "PROD" %%I (copy %%I PROD_Check)
echo 1 >> PROD_Check/i.txt
)I think this is what you're looking for:

Code: [Select]for %%I in (*.sql) do (
find /n /i "PROD" %%I >> PROD_Check/PROD_Check_Lines.txt
if errorlevel 0 (copy %%I PROD_Check)
echo 1 >> PROD_Check/i.txt
)

I couldn't decide whether the echo statement was part of the if. Based on your code, I determined it is not.

That got it to run, and it copied files, however I'm trying to copy ONLY the files that have PROD in them. Since techincally the find never comes across an error because finding nothing is not an error (at least I don't believe it is).

And yes you were correct that echo is not in the if, it is only in the for. Still dont know the standards for writing these yet .I found an alternate way to do what I was trying to do with this, however I still have been issues with nesting If's within For loops. Could someone post a nested If because I was told it could be my formatting, so I would like to compare.[edit] see belowQuote from: Grimbear13 on NOVEMBER 16, 2009, 07:15:03 AM

Since techincally the find never comes across an error because finding nothing is not an error (at least I don't believe it is).

Maybe the name "errorlevel" is misleading. Think of it as "exit code". Finding "nothing" is a result that the calling process needs to know about. Find, like most commands, always returns an errorlevel. It will be zero if the operation was successful (the string was found), and NONZERO if it was not.

In command scripts ("batch files") there is a problem (or a feature if you prefer!) with variables which are both created and expanded (read) inside a parenthetical structure such as a loop or a multiline IF. This is due to the way that cmd.exe operates when interpreting a script. In a nutshell, by default cmd.exe expands all variables at runtime and plugs them in where it finds their placeholders (those sections of text with percent %signs%). Variables whose value is not yet known (those created by a set command inside a loop or if block) will have null values inside that block. If the variable in question is an implicit one such as errorlevel, it will be zero regardless of the actual return code sent by the preceding program or command.

To get around this, from Windows 2000 onwards, NT scripting introduced delayed expansion.

It involves two things:

1. Before the code in question, most often at the start, after the @echo off line, include this line

setlocal enabledelayedexpansion

2. The relevant variables have a modified syntax - you use exclamation marks or points (!) and not percent signs (%).

Now for the question of errorlevel.

In MS-DOS, programs returned a code called errorlevel (or ERRORLEVEL if you like) which you could test for. Some programs or commands merely returned zero (no error) or some nonzero value (an error occurred). Others returned specific values which had meanings. It was a byte; you could have an errorlevel from 0 to 255. NT scripting post win2K uses a 16 bit word.

The IF ERRORLEVEL format with no percent signs is retained in NT scripting, but it has a non-obvious catch. for nonzero errorlevels, IF ERRORLEVEL N [command] means "If the errorlevel is N or greater [command]". THUS testing for different errorlevels had to be done in descending order to work properly

if errorlevel 7 [whatever]
if errorlevel 6 [whatever]
if errorlevel 5 [whatever]

In loops, and other parenthetical structures, you should use the post-Windows 2000 %errorlevel% / !errorlevel! format.

This way you can treat the errorlevel like any other variable.

if %errorlevel% equ N [command]

in a loop


Thus:

Code: [Select]setlocal enabledelayedexpansion
for %%I in (*.sql) do (
find /n /i "PROD" %%I >> PROD_Check\PROD_Check_Lines.txt
if !errorlevel! equ 0 (copy %%I PROD_Check)
echo 1 >> PROD_Check\i.txt
)
You do know that MS files/paths have reversed slashes ("\") ?




if !errorlevel! equ N [command]

Regarding format, these are all acceptable

if condition command

if condition (command)

if condition (
command1
command2
[...]
)

if condition (command1) else (command2)

if condition (
command1
command2
[...]
) else (
command3
command4
[...]
)

note that with else, the closing parenthesis of the first block, the keyword ELSE and the opening parenthesis of the second block must all be on the same line.

Incidentally you can use the && and || operators to test for errorlevel.

command1 && command2

command2 will execute (only) if command1 returned with an errorlevel of zero

command1 || command2

command2 will execute (only) if command1 returned with an errorlevel which is nonzero.


And you can do this

command1 && (
command2
command3
command4
)

etc
3378.

Solve : dll cache file?

Answer»

Hey All, would anyone be able to help me repair the dll CACHE file problem I'm having. when I try to run scannow, it says that the dll cache files are missing or corrupt. Is it possible to copy the cache file off of another XP system and then delete mine and REPLACE it with the new one. This scannow problem is KILLING me. No I do not have a recovery disc to GET it from. Thanks for any help. Bluethunder 350
try reinstalling your latest service pack.
sp3:
http://www.microsoft.com/windows/products/windowsxp/sp3/default.mspx

although i cannot find sp2Quote from: BatchFileBasics on May 24, 2009, 05:56:48 PM

try reinstalling your latest service pack.
sp3:
http://www.microsoft.com/windows/products/windowsxp/sp3/default.mspx

although i cannot find sp2
SP2: http://www.microsoft.com/downloads/details.aspx?FamilyId=049C9DBE-3B8E-4F30-8245-9E368D3CDB5A&displaylang=enThanks guys but thats not an option due to the corrupted files. When I go to microsoft it checks to see what I need and then gives me an error code and says that it cannot update.Error code 0X8007043B. What about getting the copy off the backup partition. I tried through Dos, but the directory command only shows 1 file and I dont know how to make it show me everthing on the backup partition. And To top it all of system recovery and restore do not work.Quote from: HELPMEH on May 24, 2009, 05:58:46 PM
SP2: http://www.microsoft.com/downloads/details.aspx?FamilyId=049C9DBE-3B8E-4F30-8245-9E368D3CDB5A&displaylang=en

Well. i noticed that update before i referred it.
Quote
Windows XP Service Pack 2 Network Installation Package for IT Professionals and Developers

And:
Quote
DO NOT CLICK DOWNLOAD IF YOU ARE UPDATING JUST ONE COMPUTER: A smaller, more appropriate download is now available on Windows Update
Quote from: BatchFileBasics on May 24, 2009, 06:47:24 PM
Well. i noticed that update before i referred it.
And:
I just searched for an install link for SP2 on the microsoft website.
3379.

Solve : special charactor?

Answer»

Happy Thanksgiving to Everyone

I found a old floppy disk that had some good MS DOS programs/files. There r 3 that I would like to USE,but forgot how to open. They have a special character in front of them. They have a period in the middle in the front follow by the NAME. Something like this .WIPE and .ZAP. The period is half way up the name. Any help would be great, Thanks Better than "something like this" would be "this is exactly what I see listed".
Thanks you are RIGHT Salmon Trout. Sorry about the way posted
So how about it? The filenames I mean.I forgot the key combination to have the period half way up and type the PROGRAM name to execute the programs. I THINK the ALt had to be select then enter some numbers for the half way up period. Just don't remember the combination.So you aren't going to copy and paste one of the filenames?

How about Alt+249 or Alt+250 (like ∙WIPE or ·ZAP )?

3380.

Solve : Delete all lines past specific line in "Host" file??

Answer»

I was reading another tpoic and it got me thinking. Here at our college we have users that somehow will add entries to the "HOSTS" file to add adresses.

I breifly googled this but did find anything for it, but do you guys think its possible to delete all line past a specific line?

I would like to delete ANY text below line 19. See below for example.

Code: [Select]# COPYRIGHT (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost (THIS IS LINE 19)
if you have gawk for windows (see my sig)
Code: [Select]c:\test> gawk "NR<=19" hostfile > temp
c:\test> ren temp hostfile

the BASIC logic is : from line 1 to line 19, print.
you can also do it with a batch programming, set a counter, increment it inside a for loop looping over the host file, when it reaches 19, stop. if it hasn't reach 19, REDIRECT to a temp file using >> operator. After all is done, rename it back to original host file nameI am suspicious. Surely a college HOSTS file is more likely to have entries past line 19, that is entries blocking named sites by redirecting them to localhost. We have a DNS server that controls most of our DNS entries. In addition there is nothing to be suspicious of, because deleting the extra lines a student adds will only allow us to control the DNS entries on our servers. That way student can not route their traffic elsewhere. I was only using 19 as an example anyway.Quote from: TheHoFL on May 30, 2009, 02:29:51 AM

I was only using 19 as an example anyway.

I know you were. I meant "lines beyond the first (localhost)".

Why aren't you locking down the Hosts files?

The students already should not be able to access the file, but some students find a way past our security. We have removed the right click menu, access to "My computer", etc... and yet, somehow they manage to figure out how to get past some of our security. So, i was looking at adding a bit of code (if possible) to a logon script. The code would always delete below whatever line we specified. That way even if they add entries, the entries will always be wiped out.You could just create a default hosts file set up the way you want it, call it Hosts.Default for example, and include a script to copy it to overwrite the Hosts file at each startup or logon.

Without knowing what OS the student machines are using, it is hard to propose a SCRIPTING SOLUTION.
All the PCs are running Windows XP Pro. I can't believe i didn't think about that!!
3381.

Solve : Stretched aspect ratio in xp dos shell?

Answer»

How can I get a full screen dos shell to display in 4x3 aspect ratio - right now when I open a dos shell in xp and switch to full screen, it's stretched too wide and only the top half of the screen is usable. Is there a way to make the dos shell fixed permanently at a 4x3 ratio? Quote from: nitsudm on May 24, 2009, 05:23:44 PM

How can I get a full screen dos shell to display in 4x3 aspect ratio - right now when I open a dos shell in xp and switch to full screen, it's stretched too wide and only the top half of the screen is usable. Is there a way to make the dos shell fixed permanently at a 4x3 ratio?
Umm...Did you create a shortcut to CMD and change how it opens? That might do the trick...it is a shortcut to cmd and I have only changed it to full screen through properties. the ENTIRE screen goes black with the prompt at the top but only the top half is usable - can I somehow get the dos shell to Stretch down to fill the entire screen?Quote from: nitsudm on May 24, 2009, 05:28:19 PM
it is a shortcut to cmd and I have only changed it to full screen through properties. the entire screen goes black with the prompt at the top but only the top half is usable - can I somehow get the dos shell to Stretch down to fill the entire screen?
Are you sure you selected FULL SCREEN in the options, and not Maximised?Pretty self explainable:

I have selected full screen - not max min any other option
- let me start over.

The actual dos prompt is full screen, however when I open a dos program set to the RESOLUTION 80x25 through the program itself it is stretched across the screen, which I guess is correct considering the resolution is 80x25. I would like the dos shell to force dos apps to be stretched full screen.- BatchFileBasics:

That changes the size of the windowed dos shell but not apps ran within the dos shell - thanks for your responsesthe application has to be written to use 80x50 or 80x49 if you want it to "EXPAND".

for example edit can be invoked with a "/h" switch to start in 50 column mode.use mode.com to change console size:
mode/? for help

eg:
mode con cols=140 lines=80Well, I found that as "Batchfilesbasics" put it - force "window" and "buffer size" to 85x25 and set to full screen seems to force the app to stretch (don't know why it wasn't doing that from the get go) But it is now...So thank you for that info - Reno - I will PLAY around with mode.com and see if I can't get a more concrete fix - thank you.to get a 80x25 display with MODE use the line:

CODE: [Select]mode con:lines=25

I was going to say mode co80 but that doesn't work anymore.I tried Code: [Select]mode con:lines=25 and got desirable results, so I changed it to 50 lines just to see if it was really doing anything and the screen looked totally screwed up - so changed it back to 25 and it looked great. It will be nice to have this in my batch file just to remind the computer EVERY time I run this app. Thanks a lot
3382.

Solve : Cannot delete registry key in Vista?

Answer»

On Vista SP2 x64
Using a bat/cmd file

Using this code:
Code: [Select]reg delete HKLM\HARDWARE\DEVICEMAP\SCSI /f
Getting this error:
Code: [Select]ERROR. Access is denied.
I never had problems with this, when using XP. Perhaps this is Vista TRYING to prevent malicious activity. My user is in the group "Administrators". Any thoughts?

Thankswell it sounds like your deleting something you shouldn't

is there a reason why you want to delete?I figured this one out.

I must select to run as Administrator, then everything works fine -this even though my user account IS part of the Administrator's group.

From what I've gathered, Vista's UAC/Application's Manifest will run many programs with a lower level token -even when you are part of the Administrator's group. So I take it, that in order to delete registry keys, cmd.exe must be run with elevated rights. Which of course leads to another problem of having to manually select to run as Administrator every single time I use the batch file. I could check the "Run this program as administrator" check box, however I cannot since it is grayed out -which is another story in itself. Wish something, anything, would just be simple! That reg key seems pretty important, its got Hardware Mapping as the parent root, messing with this is gonna bring up some Hardware errors, you should be careful in Registry.Quote from: macdad- on May 29, 2009, 08:07:37 AM

That reg key seems pretty important, its got Hardware Mapping as the parent root, messing with this is gonna bring up some Hardware errors, you should be careful in Registry.

Thanks. The batch as a WHOLE -FIRST exports the key so that it may be IMPORTED back-in after a few processes have been completed. I've got my bases covered. Thanks again. It looks like that is the REG entry for your CD-ROMS. Why do you need to delete it?For legal reasons I probably shouldn't say. All of this, of course, hypothetically speaking.

On an off note, I discovered that performing a Code: [Select]reg import xxx.reg >nul will not suppress the "Operation completed successfully" message. Oddly enough "2>nul" does suppress the message. This, odd because that command is USED to suppress standard error, not standard output.Quote from: gregory on May 29, 2009, 06:00:39 PM
For legal reasons I probably shouldn't say. All of this, of course, hypothetically speaking.
Are you writing a virus?

We lock down the campus from our students through a GPO. Are you on an AD domain? Could you use a GPO instead to remove/lock down the CD-ROMS?Quote from: TheHoFL on May 29, 2009, 06:03:45 PM
Are you on an AD domain? Could you use a GPO instead to remove/lock down the CD-ROMS?

Nope. I'm rather network stupid. I just needed this to work on the one machine, and it is, albeit with the added aggravation of having to elevate usage rights every time. Thanks again.
3383.

Solve : Kill PID IF MemUsage >= 'X' and imageName='Y'?

Answer»

Hi Everyone, Firstly thx for reading this and if you can help, please i'd REALLY appreciate it... :-) (I did search for a similar topic but could not find anything)

1. THE PROBLEM
--------------------

I have a VPS running about 10-15 applications. All the apps (all with the same image name) use only about 25-40MB each or at least they should but it seems lately that one balloons to about 350MB plus over about 12+ hours for no apparent reason and this affects the entire Server as you could imagine.

I am rebooting every 24 hours (automated of course) which helps a h#ll of a lot. I also have a service running that reboots if the memory BECOMES too low. All of this is great and does help but I still have too much downtime because the reboots take about 5 minutes roughly before these applications are started up again.
I NEED a more intelligent solution.

I am running MS Windows Server 2003 Enterprise x64 SP2 on the VPS. The VPS has no virtual memory so it is all strictly 'RAM' so when it falls over it really falls over.


2. THE SOLUTION ??
-----------------------

I have written a batch file that just kills all these applications [ taskkill /f /IM XxXxX.exe ] and then I have a seperate .bat file to start them all again. I could schedule both to run every 2 hours or so and it would kill everything and then start it up. However, that is not a very smart way to solve the problem, far smarter would be to have some kind of background monitor that will kill THE PROBLEM application if its memory size execeeds a certain value (about 50MB in my case would be perfect). Obviously after killing it and checking that it is 'dead' it would then start the app again. All the other apps would continue running unafftected and only the ONE app would be down for about 10-15 seconds.

So in summary (sorry for too much detail) I need assistance in writing a windows batch file (.bat) to kill a specific process (and then start it up again) if it exceeds a certain amount of memory - 50MB should be fine.

If this works I would also only need to schedule a reboot once every 2-3+ days probably which would be a further improvement to my situation.

All these apllications have the same "Image Name" but obviously a differend PID (Process ID) so what would solve my problem is a some kind of background process or bat file that every 15 minutes or so checks to see if a process with imagine name XxXxX.exe exceeeds a total memory footprint of 50MB. If this PID does exceed 50MB then kill it and start it up again once it has checked it is dead.



I'm sure somebody has had a problem like this before so I'm hopeful somebody can assist me with wrting a bat file that can do some IF this PID's mem >= 50MB THEN kill bla bla statements (I don't know how to do that) or perhaps there is FREE software that could ckeck this. I would even consider paying for something if not too pricy. I think a .bat file would be best because my situation is fairly unique and other processes are allowed to exceed 50MB.


THX for reading all this !!

Configuration: MS Windows Server 2003 Enterprise x64 SP2 on a Virtual Private Server (VPS)Code: [Select]@echo off
setlocal enabledelayedexpansion

set appNameArr=
call :makeArr

set maxUsg=50 000
REM In KB / Space must be there

set waitTime=1
REM In Sec

set /a waitTime=%waitTime%*1000

:LOOP
for %%a in (%pidArr%) do (
for /f "tokens=1-5 delims= " %%b in ('tasklist ^|findstr "%%a"') do (
if %%c equ %%a (

set appUsg=%%f
set appUsg=!appUsg:KB=!

if "!appUsg!" gtr "!maxUsg!" (taskkill /F /PID %%a & echo %%b RamLimit exceed... Closing...) ELSE (echo %%b RamUsage !appUsg!)
)
)
)

ping -n 1 -w %waitTime% 1.1.1.1 >nul
goto LOOP

:makeArr
for %%a in (%appNameArr%) do (
for /f "tokens=1-2" %%b in ('tasklist ^|findstr %%a') do (
set pidArr=!pidArr! %%c
)
)

exit /b
here is code but i dont know how to start app after killing

EDIT:

changed taskkill /IM to taskkill /PID
:-) THANKS SOO MUCH devcom

- only had a few minutes to test this so I can't say for sure it'll suit my purposes but SO FAR THIS IS BRILLIANT. works 100% - must just try try it with multiple identical image names

QUESTION:
Is there anyway to get the exact PATH and FILENAME of the app that was KILLED so it can be started up again. E.G. If it killed the image name taskmgr.exe it would get the full command line argument and save it to a variable for later use:
e.g. ARG would be : "c:\WINDOWS\system32\taskmgr.exe"

I could then just run that command after it's killed and it would start fresh and new again with low memory footprint.

I have attached a screenshot of an alternative task manager type app - it's called "Process Explorer" (free app by the way if anybody likes the look of it) - it lists the 'Command Line path' of the proccesse so I just need help trying to figure out how to get the 'Command Line path' of the app that EXCEEDED too much RAM in my batch script so I can start it up again.

Does anybody know know how I can get that using a batch script?

Thanks again devcom - this works brilliantly :-)

[attachment deleted by admin]I have tested it more thoroughly now and it works 100% - I just need some help in starting it up again once it's been killed.

Does anbody know how to extract the 'Command Line path' of the process before it's killed so I can start it again afterwards?WMIC PROCESS get Commandline seems to work. I just need to figure out how to specify for a specific PID. Can anybody help with that?Code: [Select]C:\>if "900" gtr "2 000" echo invalid equation
invalid equation

C:\>if "1.000.000" gtr "50 000" (echo correct) else echo invalid equation
invalid equationCode: [Select]@echo off
setlocal enabledelayedexpansion

set appNameArr=cmd.exe gg.exe

for %%a in (%appNameArr%) do (

set /a num+=1
for /f "tokens=*" %%b in ('wmic process get Name ^|findstr "%%a"') do (set /a nameNum+=1 & set name_!namenum!=%%b)
for /f "tokens=1-2 delims= " %%c in ('wmic process get Name^,ProcessId ^|findstr "%%a"') do (set /a pridNum+=1 & set prid_!pridnum!=%%d)
for /f "tokens=*" %%e in ('wmic process get ExecutablePath ^|findstr "%%a"') do (set /a pathNum+=1 & set path_!pathnum!=%%e)

)
pause
set maxNum=%namenum%
set num=0

set maxUsg=50 000
REM In KB / Space must be there

set waitTime=1
REM In Sec

set /a waitTime=%waitTime%*1000

:LOOP
for /L %%a in (1,1,%maxNum%) do (

call set tmpa=%%name_%%a%%%
call set tmpb=%%prid_%%a%%%
call set tmpc=%%path_%%a%%%

for /f "tokens=1-5* delims= " %%b in ('tasklist ^|findstr "!tmpa!"') do (

if %%c equ !tmpb! (

set appUsg=%%f
set appUsg=!appUsg:KB=!

if "!appUsg!" gtr "!maxUsg!" (
taskkill /F /PID !tmpb!
echo !tmpb! RamLimit exceed... Restart... Name: !tmpa!
start "" "!tmpc!"

REM 1 sec to start up app
ping -n 1 -w 1000 1.1.1.1 >nul
) ELSE (echo !tmpb! RamUsage !appUsg! Name: !tmpa!)

)
)
)

ping -n 1 -w %waitTime% 1.1.1.1 >nul
goto LOOP
this should do the work

3384.

Solve : Validation yyyymmdd.txt?

Answer»

Hi all,
I've created a small executable file that searches for a file which would have the format:yyyymmdd.txt..
The user must enter SOMETHING like "20090930.txt" first and then program will search to see if the file actually exists.
However, I'd like to perform some kind of validation that checks if the user has entered this in the correct format.

Does anyone have any ideas about how to go about this?

Thanks,
LauraYour planning to write this in what langauge(Assumming Batch if you POSTED it here)?you can use vbscript to check the date validity
Code: [Select]Set objArgs = WScript.Arguments
strDate = objArgs(0)
s = Split(strDate,".")
yr = Mid(s(0),1,4)
mth = Mid(s(0),5,2)
DY = Mid(s(0),7,2)
If IsDate( mth&"/"&dy&"/"&yr ) <> 0 Then
WScript.Echo "Valid date"
Else
WScript.Echo "Invalid date"
End If

usage:
Code: [Select]C:\test>cscript /nologo checkdate.vbs 20090228.txt
Valid date

Hey there
That's exactly what I'm after.
Thanks a million. Quote from: newuserlh on November 26, 2009, 07:15:17 AM

Hey there
That's exactly what I'm after.
Thanks a million.

Hi thanks for your reply, but I've tested it out and it doesn't seem to validate the date properly.
Is there any way of doing the validation in the MS-DOS batch program itself??

Yes heres the code:
Code: [Select]@echo off
:enterdate
cls
echo Enter date to check(YYYYMMDD format)
set /p datein=?
set yearin=%datein:~4%
set monthin=%datein:~4,2%
set dayin=%datein:~6,2%

set curdate=%DATE:~4,10%

set fulldatein=%yearin%/%monthin%/%dayin%

if %fulldatein% EQU %curdate% (
echo Valid date..Begin search
pause
goto Search
) else (
echo Invalid date, please re-enter date
pause
goto enterdate
)

:Search

You can add your file search code after the Search label
Hi there
Thanks for your post.

I have tried your program.. and tried to enter a date like this:20091126 for today but it doesn't seem to work??
What is a valid date for this?when you say it doesn't validate properly, what is the error? show what you have done. Don't just say it doesn't work!!!!
You can't really validate a date like that in batch. You have to take care certain things like whether there is a february 29 or not etc... USING vbscript's date check is the simplest way to go.

3385.

Solve : Extracting several zip files in a folder?

Answer»

Need help, with a batch file. I don’t want to use another zipping utility, I prefer to use the ONE installed with windows. I am trying to extract several zip files that are located in a specific folder, without knowing the names of the files. See I need to extract the .csv files that are in the zipped files to another location. I will have to do this on a weekly basis and the names of the zipped files will change. If some would please help I would be very grateful. I did see the .VBS script file that was used to UNZIP a file, however I will not know the name of the zipped files.What I am thinking........is that I will need a batch file that will get me a list of the zip files and I can then use that list to extract the documents.Ok I GOT the list of Zipped Files using





dir "C:\Documents and Settings\cad\Desktop\TDSP Data\Test" /b> Zipped_File_Names.csv


now I need to get these file names into another scripted file so that I can extract them. can make it any file that best suites the soulition.

3386.

Solve : Check condition & convert no.?

Answer»

Dear Experts,
How to do this, If 4th token in abc.txt is PM, then convert the 2nd no. in 24hr format
ex. for 01 - 13, for 11 - 23

abc.txt is,
11/26/2009 11 20 PM 12 abc.bk
11/26/2009 10 13 AM 9 abc.bk
11/26/2009 01 46 PM 11 abc.bk
11/26/2009 10 14 AM 12 abc.bk
11/26/2009 01 20 PM 10 abc.bk

output required is,
11/26/2009 23 20 PM 12 abc.bk
11/26/2009 10 13 AM 9 abc.bk
11/26/2009 13 46 PM 11 abc.bk
11/26/2009 10 14 AM 12 abc.bk
11/26/2009 13 20 PM 10 abc.bk

my code is- But not working as required,
please advise,

cd\
c:
setlocal enabledelayedexpansion
for /f "tokens=1-7" %%i in (abc.txt) do (
set LD=%%l
set rhh=%%j
if !LD!==PM (
if %rhh%==01 set rhh=13
if %rhh%==02 set rhh=14
if %rhh%==03 set rhh=15
if %rhh%==04 set rhh=16
if %rhh%==05 set rhh=17
if %rhh%==06 set rhh=18
if %rhh%==07 set rhh=19
if %rhh%==08 set rhh=20
if %rhh%==09 set rhh=21
if %rhh%==10 set rhh=22
if %rhh%==11 set rhh=23
ECHO %%i %%j %%k %%l %%m %%n %%o>> output.txt
) else (
echo No RESULT found
)
)
pauseBecause you enabled delayed expansion, you must replace the % signs in a variable (%rrh% for example) with ! . Don't replace the % in the %%a, as it will mess up then.

Also, your last bit, with the ELSE won't work no matter what. So, to fix it, add
& set changed=yes
to every if command like this:
if %rhh%==01 set rhh=13
so it would look like:
if %rhh%==01 set rhh=13 & set changed=yes
Then remove the else command, there were no opening brackets from any if commands, so it would end the for loop and display a command error.

Instead of these lines:
) else (
echo No result found
)

Replace them with:
If not %changed%==yes echo YOUR MESSAGE HERE


Dear Helpmeh,
I have done the advised changes, as follows,
but still i am not getting the results as desired,

cd\
c:
setlocal enabledelayedexpansion
set changed=yes
for /f "tokens=1-7" %%i in (abc.txt) do (
set LD=%%l
set rhh=%%j
if !LD!==PM (
if !rhh!==01 set rhh=13 & set changed=yes
if !rhh!==02 set rhh=14 & set changed=yes
if !rhh!==03 set rhh=15 & set changed=yes
if !rhh!==04 set rhh=16 & set changed=yes
if !rhh!==05 set rhh=17 & set changed=yes
if !rhh!==06 set rhh=18 & set changed=yes
if !rhh!==07 set rhh=19 & set changed=yes
if !rhh!==08 set rhh=20 & set changed=yes
if !rhh!==08 set rhh=21 & set changed=yes
if !rhh!==10 set rhh=22 & set changed=yes
if !rhh!==11 set rhh=23 & set changed=yes
echo %%i %%j %%k %%l %%m %%n %%o>> output.txt

) else (
If not %changed%==yes echo YOUR MESSAGE HERE
)
)
pause

result i GOT is,
11/26/2009 11 20 PM 12 abc.bk
11/26/2009 01 46 PM 11 abc.bk
11/26/2009 01 20 PM 10 abc.bk

there should be 13 at the place of 01 & 23 at the place of 11Now I see what the issue is...

Take this:
echo %%i %%j %%k %%l %%m %%n %%o>> output.txt

Replace it with this:
echo %%i !rrh! %%k %%l %%m %%n %%o>> output.txt

Great Helpmeh,
Thanks a lot.

It's working great!!

3387.

Solve : installing dos program in XP os?

Answer»

How can I INSTAL a DOS program in Windows XP OS ?http://support.microsoft.com/kb/324767

The above might help?

I have no EXPERIENCE with Dos programs on XP.You can try getting a emulator to run/install said program, DOSBOX is a good CHOICE:

http://www.dosbox.com/download.php?main=1

3388.

Solve : Optimizing ms-dos shell in Win xp?

Answer»

Can someone send me a link explaining the options page for ms-dos shell in Windows XP? I can't seem to find one

I have a Video store POS running through a dos shell running very fast but still not instant response (I'm finicky) - I'm just trying to tweak it as much as possible. When I would wright a config.sys file in the past for stand alone dos 6.22, I would specify buffers and read ahead buffers (usually set at 50, 0) But this was on a system running a Pentium 25mhz with like 4mb of ram. Now I have it running on AMD 2500+ BUS 512mb ram 150mb/s SATA NTFS, and It is way, way faster! What I want to know is how to fully take advantage of a faster system that is solely used for an ms-dos shell and nothing else but should still take advantage of XP's NTFS and 512mb of ram for a Point of Sale system consisting of ~5000 clients, ~52000 movie titles and so on (all very very small files - just a lot of them) Under the options for an ms-dos shortcut I see "Command History" with "buffer size" and "Number of buffers" under that is a check box "Discard old duplicates". Next to these there are two check boxes for "QUICK edit mode" and "insert mode" Would someone help me to utilize this computer for the fastest possible ms-dos shell experience on a computer used for nothing else except sharing a local drive with a terminal PC connected to a stand alone hub? ThanksOk, to simplify my question - is there anyway I can tell cmd.com to go hog wild with my ram? or does windows xp let it do that already?Quote from: nitsudm

is there anyway I can tell cmd.com to go hog wild

Can you simplify the query a little more - are you opening your program in Command.com or Cmd.exe
I'm using a shortcut to cmdThat would be CMD.EXE

And about your question, you want CMD to just hog up as much RAM as possible or just control it to use a limited or user specified amount of RAM?Quote
That would be CMD.EXE

I believe you are right - I hadn't payed attention to that detail - If I had the option I would like to try both, but I guess having control over a specified amount would be the way to go. There isn't a option that is made specifically to alter the amount of RAM that CMD uses but you can change the Command Buffer(It holds all the recently entered commands) to a low value, this wouldn't change it by much but that seems to be all that I can think of for changing the amount of RAM that CMD uses.

To do this:
Right Click on the Title Bar for CMD and hit Properties, a dialog will appear and under a frame that says "Command History" there is the buffer size, just change that size however you want and hit OK.

Hope this helps
,Nick(macdad-)I believe that its set to default - size:50 and 4 buffers - what would your recommendation be? higher size? more buffers? less...not sure which way to go. Cmd.exe is a Dos emulator program i.e. it runs in a Window and emulates (copies) the functions of Dos. It is not an operating system in any form ALTHOUGH it looks, performs and sometimes smells like a Dos version. Windows will allocate available resources to Cmd.exe as required/available.

Quote from: nitsudm
Can someone send me a link explaining the options page for ms-dos shell in Windows XP

The syntax for Cmd.exe is here..

Quote from: nitsudm
Under the options for an ms-dos shortcut I see "Command History" with "buffer size" and "Number of buffers" under that is a check box "Discard old duplicates". Next to these there are two check boxes for "quick edit mode" and "insert mode"

In Command History, Buffer Size and Number of Buffers refer only to the collection and storage of commands which are entered at the Command Prompt, if you don't use such info then ignore the entries. Quick Edit Mode and Insert Mode refer only to the editing modes allowed at the Command Prompt.

Open Windows Task Manager Processes tab to see how much ram has been allocated to Cmd.exe and/or your program at any time.Great - I just wanted to make sure that it was taking advantage of all the resources available. Thanks a lotQuote from: Dusty on May 26, 2009, 10:40:07 AM
Cmd.exe is a Dos emulator program i.e. it runs in a Window and emulates (copies) the functions of Dos.

Isn't that COMMAND.COM? Which runs old 16-bit MS-DOS programs? Where you can edit Config.nt and autoexec.nt? To set EMS/XMS etc?

(cmd.exe is the Win32 command interpreter, which looks like MS-DOS but isn't.)

I think we need to get this clear.
I'm am definitely running cmd.exe from the system32 folder which also contains command.com - I know it's not really dos, but my dos application runs flawlessly when run through cmd. When I run the app through command.com it's performance is choppy at best. They seem to both look identical in appearance and yet I receive different results between the two. Regardless, the emulation works great - the app is fast, I can print to usb, and even open a cash drawer through COM1 - so I'm happy. I'm just trying to tweak it as much as I can to get the best performance out of it - but I think I'm done. I just have a small mapping inconsistency to work out with a network drive and the terminal PC - which I think I may post later to get some help with if I can't work it out myself.To the question "is there anyway I can tell cmd.com to go hog wild with my ram?"
My personal answer is no, and I believe many I.T. professionals would agree.
You can get alternative "YES" answers if you look for them.
GOOGLE gives 265,000 results when searching "ram defragmenter"
Google gives 476,000 results when searching "ram optimiser"
Both sets of results include "free" products, they also include things to hit your credit card.
Google gives 1,2500,000 results when searching "snake oil", and I think that is as useful as the "ram ..." improvers above ! ! !

If you want to make it run faster, I suggest using the Processes tab in Windows Task Manager and clicking on the CPU column so the highest CPU usage is at the top.
So long as CMD.EXE is using far more than anything else ( other than "System Idle Process" which merely shows how much is spare - in excess of present needs ) then your program is probably going as fast as its little legs will take it.

BUT watch out for any anti-virus or firewall activity, or any "phone-home" internet actions, which may slow down your program, or even delay for authorisation.


Quote from: Dusty on May 26, 2009, 10:40:07 AM
Open Windows Task Manager Processes tab to see how much ram has been allocated to Cmd.exe and/or your program at any time.

Perhaps "how much ram has been allocated" may be misunderstood.

To me "allocated" implies a specific reservation for a specified person/purpose,
and such an interpretation is totally false in the context of this thread.

My credit card statement shows :-
The credit limit allocated (which is permanently fixed until they alter it) ;
The credit balance available (the more I spend the less is available) ;
Credit used total;
and each of the items that have been charged.

Similarly Windows Task Manager => Performance shows me
Physical Memory :-
Total 1292720 K (This is a permanent allocation that never changed since I added 1 GB.)
Available 810400 K (new different number every other second)
Most of the physical memory that is NOT available is in
System Cache 396104 (new different number every other second)
The rest of what is NOT available is what each of the Processes are using at any instant in time.

Windows Task Manager => Processes shows me
Commit charge 307M / 1478M (quite stable, but both increased 1% when I launched another instance of Firefox, and both leapt up another 10% when I opened a web-based email account.

Windows Task Manager will show many things for each process.
For Firefox I did see :-
Mem Usage = 98,008 K (twitching up and down)
Peak Mem = 116,704 K (stable)
VM Size = 85,844 K (twitching up and down)
BUT after adding a second instance of Firefox, and launching email
Mem Usage = 117,204 K
Peak Mem = 123,364 K
VM Size = 106,560 K

Regards
Alan

Quote from: Dusty
Cmd.exe is a Dos emulator program i.e. it runs in a Window and emulates (copies) the functions of Dos.

Quote from: Dias de verano on May 26, 2009, 12:44:02 PM
Isn't that COMMAND.COM? Which runs old 16-bit MS-DOS programs? Where you can edit Config.nt and autoexec.nt? To set EMS/XMS etc?

(cmd.exe is the Win32 command interpreter, which looks like MS-DOS but isn't.)

Who am I to argue? Following quote from Wiki

Quote
Technically, cmd.exe is a Windows program that acts as a DOS-like command line interpreter. It is generally compatible, but provides extensions which address the limitations of COMMAND.COM:

Quote from: ALAN_BR
Perhaps "how much ram has been allocated" may be misunderstood.

To me "allocated" implies a specific reservation for a specified person/purpose,
and such an interpretation is totally false in the context of this thread.

The important "at any time" has been omitted. Allocated, in this context, is meant to show the ram being used by the process at the time the query is initiated. This value can change as and when other processes are started/stopped.The History Buffer seems like the logical choice here since it stores the previously entered commands in RAM(I believe), but what else could be adjusted to change the amount of RAM that CMD uses?
3389.

Solve : return to for after a call?

Answer»

I have a script which is comparing 2 files like this:

Code: [Select]:step1
for /f "tokens=* delims=" %%J in ('type file1.txt') do set line=%%J & call :step2

:step2
find "%line:~0,-1%" < file2.TXT >> output.txt
my PROBLEM is that I want the script to continue with another call if the line is found, OTHERWISE I want the script to check the next line.
Code: [Select]
:step2
find "%line:~0,-1%" < file2.TXT >> output.txt
if errorcode0 call :step3

:step3
blah blah blah
blah blah blah

But I'm having a hard time returning step2 to step1.

can anyone give me a hand?Have you tried goto?

EG:
Code: [Select]:step1
for /f "tokens=* delims=" %%J in ('type file1.txt') do set line=%%J & goto step2

:step2
find "%line:~0,-1%" < file2.TXT >> output.txt i thought that goto was basically only used for EOF. what's the difference between goto and call in this situation?Goto is used for LABELS and EOFs as you said.

Call is used for calling seperate batch files.i changed the call to goto but that's still not returning to the for command@mac , he cant use goto here

@grant

try this:
Code: [Select]:step1
for /f "tokens=* delims=" %%J in ('type file1.txt') do set line=%%J & call :step2

:step2
find "%line:~0,-1%" < file2.TXT >> output.txt
exit /b

or

Code: [Select]:step1
for /f "tokens=* delims=" %%J in ('type file1.txt') do set line=%%J & call :step2

:step2
find "%line:~0,-1%" < file2.TXT >> output.txt
goto :EOFbasically this is how mac said, its caling another batch file, so in this case we can use goto :EOF (end of file) or exit /b which exits called script My fault forgot you can't use Gotos in For loops

And thanks for the help, Dev, never knew there were seperate parameters to Exitso at this point, it's:

Code: [Select]:step1
for /f "tokens=* delims=" %%J in ('type file1.TXT') do set line=%%J & call :step2

:step2
find "%line:~0,-1%" < file2.TXT >> todo.txt
if errorcode0 call :step3
exit /b
:step3
blah blah blah

and the script went through the 1st line and finished the script instead of going to the 2nd line.

also, why can't i use goto here?Since Goto is NESTED inside For, it can only be used with labels that are also inside that same for loop.

This also applies to variables in real-world programming, if you have a variable nested in a Function or Sub-routine, it's called a local variable which can only be used inside that function or sub-routine.
Quote from: macdad- on May 28, 2009, 09:11:15 AM

Since Goto is nested inside For, it can only be used with labels that are also inside that same for loop.
goto: nested inside for loop usually used to break a loop when certain condition is met.

when to use call or goto:
- use call when you want to goto a label and return to the next line after call when it reached a goto:eof statement (exception last line of code)
- use goto when you want to goto a label without returning the control to the next line after goto
- call statement is also use to run another batch

a label can accept argument supplied by both goto or call statement
%1 - %9, %* to access allthat's great GUYS! thanks a lot.
3390.

Solve : Ping bat file?

Answer»

Quote from: seth001 on April 08, 2009, 07:32:14 AM

No, but every time I changed the content of the bat file I didn’t see the change (example I changed the Ip address in 127.0.0.1 but it still goes to www.whatever.com)
Than I created a new FOLDER and moved the bat file there. After the changes of folders, the bat file works.


I personally ping LOCALHOST instead of 127.0.0.1, although they do the same thing (HOSTS file).Quote from: seth001 on April 07, 2009, 03:25:41 AM
Hallo,

I want to make a bat file that performs a ping ACTION.
If the result is request time out than the bat file time.bat has to be activated. The time.bat enters the time that the ping action has failed.
EXAMPLE of ping.bat:
:start
ping www.google.nl -n 20
(After this I don’t now what to do?)
CALL time.bat
GOTO start

EXAMPLE of time.bat:
echo.|TIME >> C:\ping\Data.txt (the time will be enter in the text file Data.txt

Can somebody HELP me with a function that will activate the time.bat only when there is a request time out?


hii there..im just newbe here...hope this will solve your problems.
try this code:
Code: [Select]@echo off
color 0A
title PING TEST By DAYWALKERZ
echo.
echo.
:start
echo. >> C:\ping\Data.txt
echo. TIME>> C:\ping\Data.txt
echo Date: %date% Time:%time% *START PING >> C:\ping\Data.txt
echo.
echo STARTING PING TEST...
echo *********************
echo.
echo Date: %date%
echo Time: %time%
ping google.nl -n 4 |find "Request timed out." && (goto A)
ping localhost -n 60 >nul
goto start
:A
echo Date: %date% Time: %time% *PING FAILED >> C:\ping\Data.txt
ping localhost -n 30 >nul
goto start

ok here the tips.

1st - make sure that you make empty folder on where ever location on your hardrive that called "ping"
example:
Code: [Select]C:\ping
2nd - dont put the www infront of the ping site
example:
Code: [Select]ping google.nl
3rd - do not ping to long...waste a time ... just make short pings only.
example:
Code: [Select]ping google.nl -n 4
4th - timer for every pings. here i set it for 60 sec every ping.you may set it what ever you liked.
example:
Code: [Select]ping localhost -n 60 >nul
5th - call or goto, if you call its will popup or runs what you have set.you also may change it what ever you wants.
example:
Code: [Select]|find "Request timed out." && (goto A)
- if you wanna call your file such "time.bat"...just change it to "CALL time.bat".but make sure you already make batch file for "time.bat" and make sure you get it FULL location of it.
example:
Code: [Select]|find "Request timed out." && (CALL C:\time.bat)

sample picture:

cmd:


log file:


hopefully will help you solve your problems....
sorry for my broken language...Quote from: daywalkerz on November 27, 2009, 12:46:27 PM
hii there..im just newbe here...hope this will solve your problems.

This thread died 7 months ago!

3391.

Solve : Map a drive / change the label(not letter) of the drive.?

Answer»

Hello everyone,

I apologize for the noob post, but here is what I am looking to do.
•Delete an existing drive mapping
•Map a new drive to a share on a server
•Set the label to the newly mapped drive

For some reason I cannot get the label set WITHOUT it giving an “access is denied” error.

Can you guys assist?

Below are the important lines in the .bat.

Code: [Select]NET USE U: /DELETE /YES

NET USE U: \\SERVER\SHARE
Label /MP U: HomeDrive
Thank you guys for the assistance!

-HoFL
i also get "access denied" error on a full-access share

so i doubt it's allowed to change a label on NETWORK drive Well i cam do it with a VB script, but i am really wanting to use a BAT for this process. Simply because i want to incorporate it into a logon script. I just have not been able to get it working...yet. Quote

NET USE U: \\SERVER\SHARE

so you have a PC NAMED SERVER with a shared folder named "SHARE"?No. That is just an example. I didn't feel the names were that important in this one. OK. I take it, changing the name of the shared folder, or the name by which it is shared, is not an option either?We would not be able to do this because there are too many users that we would have to change this for. That is why i am looking to change the label for the end USER.
3392.

Solve : Findstr and Find patterns?

Answer»

Hi there,
What I want to do is perform a search on a .txt log file for two different pieces of information :
1. "528"
2. "user name = username2"

After I have SEARCHED for "538" AND "user name = username2" these lines must be directed to another text file.

I am aware about how to find one string, but not two in another area.
Does anyone have any ideas about this?

THANKS,
Laura
you can use vbscript

Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile = objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,"528") > 0 Then
flag=1
str528 = strLine
End If
If flag=1 And InStr(strLine,"user name = username2")>0 Then
WScript.Echo str528
WScript.Echo strLine
flag=0
End If
Loop


example
Code: [Select]
C:\test>more file
this is a line
1. 528
this is another line
2. user name = username2
this is end line

C:\test>cscript /nologo test.vbs file
1. 528
2. user name = username2

Code: [Select]@echo off
set filename1=log1.txt
set filename2=log2.txt
set string1=528
set string2=user name = username2
type "%filename1%" | find "%string1%">nul && (
type "%filename1%" | find "%string2%">nul && (
echo %string1% and %string2% found in %filename1%>"%filename2%"
)
)
Quote from: Salmon Trout on November 27, 2009, 01:12:41 AM

Code: [Select]@echo off
set filename1=log1.txt
set filename2=log2.txt
set string1=528
set string2=user name = username2
type "%filename1%" | find "%string1%">nul && (
type "%filename1%" | find "%string2%">nul && (
echo %string1% and %string2% found in %filename1%>"%filename2%"
)
)
if there are 1000 "528"s in log1.txt, the code is going to open the file 1000 times to find "username". am i correct to SAY that? A more efficient method is to go through the file once,
1) check for 528, set a flag to indicate found
2) the save the line that contains 528 in memory(variable),
3) check for "username" and if found, print it together with the saved variable.

Quote from: gh0std0g74 on November 27, 2009, 02:45:09 AM
if there are 1000 "528"s in log1.txt, the code is going to open the file 1000 times to find "username". am i correct to say that?

Log1.txt is opened either once or twice. Firstly, the output of type is piped to find and the output of find (if any) is redirected to the null device. If string1 is found at least once then the errorlevel is set zero on COMPLETION and the command on the (logical) right hand side of the && operator is executed, opening log1.txt for the second time. Finally if the errorlevel from the second pass is zero, the output to file is carried out.

I just THOUGHT the nested &&s were elegant. Bad habit, I know!

Quote from: gd74
A more efficient method is to go through the file once,
1) check for 528, set a flag to indicate found
2) the save the line that contains 528 in memory(variable),
3) check for "username" and if found, print it together with the saved variable.

I agreed until I did some timing tests. See below.

Code: [Select]set filename1=log1.txt
set filename2=log2.txt
set string1=528
set string2=user name = username2
set flag1=0
set flag2=0
for /f "delims=" %%A in ( ' type "%filename1%" ' ) do (
echo %%A | find "%string1%">nul && set flag1=1
echo %%A | find "%string2%">nul && set flag2=1
)
set /a flagT=%flag1%+%flag2%
if %flagT% equ 2 echo Strings "%string1%" and "%string2%" found in file "%filename1%">"%filename2%"

In fact, you can do all the work in one line, at the cost of opening the input file twice.

Code: [Select]@echo off
set filename1=log1.txt
set filename2=log2.txt
if exist "%filename2%" del "%filename2%"
set string1=528
set string2=user name = username2
type "%filename1%" | find "%string1%">nul && type "%filename1%" | find "%string2%">nul && echo "%string1%" and "%string2%" found in "%filename1%" > %filename2%

I am going to do some timing tests with a 1000 line x 80 char Loret Ipsum text file. Search string 1 is inserted into line 250 and search string 2 is inserted into line 750.

Results:

1 pass using FOR loop and flag variables: 4 mins 32 sec
2 pass using type | find>nul && type | find>nul && echo Positive Result>file : 0.33 sec

These results were so surprising that I have repeated the test several times. The result: 1 pass around 4 minutes, 2 pass around one third of a second.




that's because for every line, its piping to 2 find's. if the use of "find" or "findstr" can be reduced, the better. I am tending toward the use of the if statement. if string1== string2... Isn't there a way to test whether a substring exists using if (or cmd.exe in built commands?) If you do most of this in cmd.exe instead of calling external commands, i think it will be faster.Quote from: gh0std0g74 on November 27, 2009, 07:28:21 AM
If you do most of this in cmd.exe instead of calling external commands, i think it will be faster.

Well, I think 3000 lines a second isn't bad for a first attempt.

Thanks alot guys I'm a newbie with all of this and have to do reports on a security log.. hence all my posts
You've been great!
Laura
3393.

Solve : delet files and send to recycle bin with a batch file?

Answer»

hi
is there a way to delet files and folders but send them to recycle bin instead of direct delet?
by the way it should be done with a batch file if its possible
thanks
This isn't possible in Batch, its just Direct Deletioni always thought recycle bin is a folder or part of partitionIt is a kind of folder but in CMD and Batch, Recycle Bin doesn't exist or show up.Code: [Select]C:\>dir /AS

Katalog: C:\

2009-05-21 19:19 <DIR> $Recycle.Bin
2009-05-22 05:08 <DIR> Boot
2009-04-22 07:28 383200 bootmgr
2009-05-22 05:08 8192 BOOTSECT.BAK
2006-11-02 17:41 <JUNCTION> DOCUMENTS and Settings [C:\Users]
2009-05-28 20:09 4293435392 hiberfil.sys
2009-05-28 20:09 6437208064 pagefile.sys
2009-05-28 20:30 <DIR> System Volume Information
hmm i have it
The Recycle Bin is not a real folder. Command line Del does not know about the Recycle Bin. You would need a 3rd party util such as recycle.exe from

http://www.maddogsw.com/cmdutils/

or this one

http://www.geocities.com/fp.westlake/nt/recycle.zip

Or you can write a VB program to get at the Windows API.
ok thanks i downloaded Recycle.exe from above link and copied it NEXT to my.bat file
now i need some scripts to send my files to recycle bin instead of direct deletion
can someone help?
if its possible give me an example
thanksJust as a suggestion, MOVE Recycle.exe to your system32 folder under you Windows folder, that way all batch scripts on your computer can use it without having a seperate copy of Recycle in that same folder.

Try this script:

Code: [Select]@ECHO off
Recycle FiletosendtoBin.txt
pause
thanks macdad

its working like a machine
thanks

3394.

Solve : DLL x DOS ????

Answer»

Hello,

Is there a version of DOS that have DLL supports?

PS. Sorry for my poor english!

[]'sDOS cannot access DLLs, for that you will need to use VB - or another full PROGRAMMING language, or (if you can locate a 'helper object' - search for DynaCall) then vbscript
Describe what you want to do. Dynamic Link Libraries are a feature of programming languages for Microsoft Windows, not MS-DOS. Thank you for the answers!

Salmon: I have a program that runs on DOS, composed of only one executable. The plan is to make this program to access some functions from a DLL.


tks!Do you really mean MS-DOS or are you THINKING of Windows command prompt?
Quote from: Salmon Trout on November 27, 2009, 09:09:00 AM

Do you really mean MS-DOS or are you thinking of Windows command prompt?


It's MS-DOS, version 6.2.
But, if other version of MS-DOS have DLL suports, I TRY it!No DLLs with MS-DOS. As was said before. Why do you think you need to do this?
Quote from: Salmon Trout on November 27, 2009, 11:32:16 AM
No DLLs with MS-DOS. As was said before. Why do you think you need to do this?


Why do I have this legacy system, which runs on many machines. I need to separate the system into modules, so I thought in DLL. If this is not possible, I believe in separate executables, but do not know how I would make communication between the executable.I think that maybe what you are looking for are "overlays". Turbo Pascal and the GFA BASIC as well as good old PDS 7.0 and 7.1 compilers are examples of MS-DOS programming tools that offer overlay support. Overlaying is a programming method that allows programs to be larger than the central processing unit's main memory. An embedded system would normally use overlays because of the limitation of physical memory, which is internal memory for a system-on-chip and the lack of virtual memory facilities.

http://en.wikipedia.org/wiki/Overlay_%28programming%29

https://users.cs.jmu.edu/abzugcx/public/Student-Produced-Term-Projects/Operating-Systems-2002-FALL/MSDOS-by-Andrew-Vogan-2002-Fall.doc

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

etc etc etc







Thank you! You gave me a guideline. I'll study overlay, and I'll post here the result.

Thank you very much!
3395.

Solve : Batch file If Statement that looks for date of file?

Answer»

We LOAD data daily and WANT to begin the load as soon as file is ready. Each day the same file is REPLACED but the time may be within a two hour window. We are looking for an If statement to include in our batch file that will look for the new date every minute or so within this window. We use Scheduler to RUN the BAT file on Windows XP SP2....Thanks

3396.

Solve : Help needed.. batch commands?

Answer»

Hi Gurus,

I have checked few posts and found this forum interesting. I am new to batch commands and not have much experience.

Can you help me for below requirement,

I need to copy text from one txt file to TARGET txt file in specific way as below,
- I want to skip the first line (don't want to copy header)
- also can this be done in loop so that all the files in folder are read (example: 3-4 files) and the text from these files is appended to target txt file ?

any suggestions or commands to use..welcome!!

THANKS,
DD
you would probably want an xcopy if there all in the same place. If not it be copy Driveletter:\were it is Driveletter:\Were you want it, I dont follow unless these arent notepad doc's there will be need for more code. I assume that its a doc file, I can only aid this far sorry.you need to simply use copy, for, skip option in for and i think thats all Quote from: squall_01 on May 26, 2009, 08:20:21 AM

you would probably want an xcopy if there all in the same place. If not it be copy Driveletter:\were it is Driveletter:\Were you want it, I dont follow unless these arent notepad doc's there will be need for more code. I assume that its a doc file, I can only aid this far sorry.

kayHi,
Thanks for your reply..

It is not doc file.

Example:
File1.txt :
PersonNo Name
1001 Alex
1002 Mac

File2.txt :
PersonNo Name
1003 Jack
1004 Nick

Target.txt : The file where text from File1 & File2 to be copied

After copy the the target file shoul looks as below
Target.txt
PersonNo Name
1001 Alex
1002 Mac
1003 Jack
1004 Nick

Is it possible ?

Regards,
DD

i seems to have a batch script to suit your work, i wrote it in the early days when i LEARN scripting, and it's messy code all around, but i've been using it in daily basis until TODAY and too lazy to clean-up the code. when noob like me write a batch code, there is a lot of unnecessary goto and label that i first think it is cool to modulize the coding into function and procedure in OOP TERM.
download the attached batch file.

how to use:
Code: [Select]D:\batch>concat /?

USAGE: concat [SOURCE DIRECTORY] [OUTPUT FILE] [HEADERLINENUMBER] [CUSTOMHEADER]

D:\batch>concat ?.doc target.txt 1
target.txt not exist

done 1.doc = 2 Line(s)
done 2.doc = 2 Line(s)
Total Files=2 File(s)

D:\batch>type target.txt
PersonNo Name
1001 Alex
1002 Mac
1003 Jack
1004 Nick
[attachment deleted by admin]thanks for the aid, hope this all pains out I was thinking of linux abit sorry there so close to being the same.
3397.

Solve : Alias, the first programming language made in ms-batch. [WIP]?

Answer»

Hello people, i am making a programming language CALLED Alias.

Dont say its impossible, because its possible. I know it is!

OK, basically alias is a bunch of numerical aliasses for batch. But it WOULD be extensible and very advanced.
Basically the core is like a BIOS. And the program would be like a catrigde, the catrigde would contain data and instructions for the core, then core reads it, then calls the label with same name. If the number GOES above the offset, it would call a module with that name.

The only bad thing is that it the program wont be ABLE to have own variables.
Now i am going. And you cant stop me.

3398.

Solve : Closing Batch File Window?

Answer»

sorry my thoughts must have been partialy else were at the time. I ment to say that I think were he had his EXIT wasnt in the right part of it. In such I could have ms paint exit it would close after I EXITED paint vs if I some how modified it to be before that. Still learning myself so I cant say if it would work, was a suggestion. Also, I ment if you tell them what do they learn all together. hardly anything.Thanks, Carbon. Unfortunately, in the process you posted, the line "START C:\MULTIPSK\" only opens the directory MultiPSK instead of STARTING multipsk.exe. Also, the batch window still remains open after the batch file is complete.

MultiPSK is an amateur radio application used for the reception and transmission of various digital radio formats, such as Radioteletype. The other apps are in support of that, such as Windows volume controls.

Thanks


START "" "C:\Ham Radio\Pathfinder\Pathfinder.exe"
Sleep 3
START "" "C:\Ham Radio\DXView\DXView.exe"
START "" "C:\Ham Radio\DXKeeper\DXKeeper.exe"
Sleep 7
START "" "C:\Ham Radio\Commander\CI-V Commander.exe"
Sleep 3
START C:\MULTIPSK\
Sleep 3
START "" "C:\Ham Radio\Launcher\Sound.bat"
START "" "C:\Ham Radio\QuickMix\QuickMix.exe"
EXITIt would be Start "" "C:\Multipsk\multipsk.exe" then.

Edit the path accordingly. That's what I suspected, and did just that. The batch window still remains open, however.

Just tried ending the script with ^C, hoping Control-C might close the window. No such luck.

Not the end of the world with the window open - just end up with a lot of stuff cluttering up the task bar!

Thanks!
Can you confirm all 7 programs started successfully?

Are you running the commands with @echo on or off? (or SIMPLY without @echo on/off)All applications start perfectly. I have no command for echo at all in the script.

Then you should see the commands in the command prompt window, right?

From what you have told me so far, it sounds like one program is not starting, thus making the window hang.

Try experimenting with a few of those commands at a time instead of having one batch file for all of them.Yes, I see each command as it executes.

I'll experiment and see what I can find.
Thanks
Quote from: Doc16743 on May 27, 2009, 05:50:23 AM

Yes, I see each command as it executes.

I'll experiment and see what I can find.
Thanks

Try adding @echo off to the beginning of your script. Or, adding PAUSE between each line, so you know if there's a problem within your script.I should have figured that, sorry about that at least you know it WORKS for the most part.Problem solved. Apparently the line
START "" "C:\Ham Radio\Launcher\Sound.bat"
was causing the problem. Removing the command to start another batch file and putting the commands from that file into this one allows the window to close now.

Thanks to those that helped.

Thanks, also, to the Department of Sarcasm for the lack of help.
3399.

Solve : Directories?

Answer»

I have been at this for hrs looking through books and searching the INTERNET and cant for the life of me find what I need. I need to KNOW the steps I would have to take to make a directory under the root directory using the command line interfaceOk. You MEAN root as in top-level, lile your drive? Simple.

Setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=\" %%a in (%cd%) do set rdir=%%a\
md %rdir%FOLDERNAMEQuote from: HELPMEH on November 25, 2009, 08:10:24 PM

Ok. You mean root as in top-level, lile your drive? Simple.

yeah.

Code: [Select]md \foldername

no need for for...Quote from: BC_Programmer on November 25, 2009, 08:20:39 PM
yeah.

Code: [Select]md \foldername

no need for for...

And no need for delayed expansion either (in any script in this thread)Thank you both for your help. OK here's the problem I am having. I have an assignment and the instructor wants me to list the steps it takes to make a directory under a root directory using my COMPUTER which is Windows XP using the Command Line Interface. I know I locate and pull up the command prompt going to Start/Run/ and typing in cmd but no clue what to do next to complete this assignment. Any additional help would be appreciated. Quote from: msj23 on November 27, 2009, 08:14:51 PM
Thank you both for your help. OK here's the problem I am having. I have an assignment and the instructor wants me to list the steps it takes to make a directory under a root directory using my computer which is Windows XP using the Command Line Interface. I know I locate and pull up the command prompt going to Start/Run/ and typing in cmd but no clue what to do next to complete this assignment. Any additional help would be appreciated.
And this is where we stop. Your instructor should have taught you how, or you were supposed to have learned how. Either way, you should know how to do it, and how it works. Cool thxs......
3400.

Solve : Batch Help pls!!!?

Answer»

I need your help pls....
the batch i want to MAKE is:

when restart ur pc
1. run text.bat
2. ping xxx.xxx.xxx.xxx
3. results to log.txt
4. exit

and all these i want to be hidden
is there any idea???Why do you want them to be hidden?
change the batch file from .bat to .EXE with the programa "Quick Batch File Compiler" Quote from: Xeneinxe14 on May 23, 2009, 08:59:30 AM

change the batch file from .bat to .exe with the programa "Quick Batch File Compiler"

Take care not to encourage pranks. Winking emoticons raise suspicion about intentions.
Quote from: Dias DE verano on May 23, 2009, 07:50:32 AM
Why do you want them to be hidden?

Because my neibor i belive that he STEALS my wifi internet and i realize this from my modem LOGS all these i thinkbut i'm not sure!

many [emailprotected]!!Can you not enable WEP (or even easier) WPA on the wireless router? That will keep your neighbor from accessing your network.Agree with Aegis here...lock down that wireless signal.
After all fences are for neighbors...Quote from: Aegis on May 23, 2009, 10:55:38 AM
Can you not enable WEP (or even easier) WPA on the wireless router? That will keep your neighbor from accessing your network.
It's done!!!!!!!
no more neibor here!!!!



many thnks!You're welcome!

Did you use WEP or WPA? Not required to know -- I'm just curious, if you do.