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.

6201.

Solve : Starting Independent Processes via DOS Command Line?

Answer»

Hi all.

I need to be able to start a process via the command line, however that process should not stop even if the calling DOS window instance is killed.

I've tried all kinds of variations USING things like:

Code: [Select]C:\>START my_batch_file
and

Code: [Select]C:\>START /b my_batch_file
The batch file will run (and continue to run) but when I close the DOS window, the batch process dies with it.

Is there any way that one can start said batch file and have it continue running until - well - forever?

Cheers,

ZeroAh - I forgot the useful technical bits...

This will be running on Windows Server 2003 Standard, using whatever DOS interpreter is installed standard there. My development environment is Window XP Pro.Quote

This will be running on Windows Server 2003 Standard, using whatever DOS interpreter is installed standard there.

You've left DOS behind, pal! You're in NT territory now...

What is in the batch file? Have you tried something like this...

Code: [Select]start "" "some-executable.exe" "parameter 1" "parameter 2" "etc"

start "title" "path-to-executable""parameter 1""parameter 2"....

"Title" can be a null string but should not be omitted...

Example:-

Code: [Select]@ECHO off
start "" "C:\Program Files\Internet Explorer\IEXPLORE.EXE"
exit

IEXPLORE will continue running after the batch has finished.

Unless you want it hidden, like the batch file is doing something but you cant see it......Yeah, I'm using:

Code: [Select]C:\>START [application name and parameters here]

The problem I'm having is that the process the START command is creating will stop if the original CMD instance is CLOSED or stopped. I'm TRYING to figure out if there's a way to spawn a completely new and independent process.

I think the problem I am having is with my environment - it is a Java web server that's making the call to the command line. contrex's solution works fine under normal circumstances. I just think I've got abnormal circumstances...

Thanks for all your suggestions!
6202.

Solve : Linear Displacement..?

Answer»

To start of right away, Somebody asked me to make something to prompt the FOLLOWING text:
I <3 CMD
So i did.. But, each line of chars is followed by a blank one, atleast so it seems..

I tried it in 2 diffrent ways, 1st using ECHO on each line, 2nd using TYPE in relation to a TXT file.

Check link for image:
http://img295.imageshack.us/img295/2616/ilovecmduj7.jpg

Any idea's / explanation would be really appreciated, as usual.what code did you use to generate it ?Maybe it's because in the screen font, the asterisk * is at the top of the character position so under it is blank space. Use a capital X and there will be a better appearance.




The code:

color 1F
TITLE I Love CMD
cls
@ECHO OFF
ECHO *
ECHO ******* ** ******* ********* **** **** *******
ECHO ******* ** ******** ********** **** **** *********
ECHO ** ** ** ** ** ** ** ** ** **
ECHO ** ** ** ** ** **** ** ** **
ECHO ** ** ******** ** ** ** ** ** **
ECHO ** ** ******** ** ** ** ** ** **
ECHO ** ** ** ** ** ** ** **
ECHO ** ** ** ** ** ** ** **
ECHO ****** ** ******** ********** ** ** *********
ECHO ****** ** ******* ********* ** ** *******
ECHO *
pause
exit

its known what its supposed to say but when i copyed/pasted it from the batch to here, this was the result :/ but in the batch it looks just fine.Your problem is the line spacing in CMD.
sorry, it was not in the spacing.
it was simply to long .. since cmd doesnt run maximized, except if you want to count FULLSCREEN.., each line had a few charachters to much ergo placing those on the next line, these being spaces HENCE not dissplayed and hard to just notice when you dont know this.., so only in that way ill say its in the spacing :p.. thanks for all the help though.

6203.

Solve : reset themes?

Answer»

i have a bunch of premade themes, but could i APPLY them using COMMAND prompt.Themes as in backgroudn pictures, WINDOWS themes (CHANGES the look of TOOLBAR and stuff) or screensavers?

6204.

Solve : search 2 files with same name?

Answer»

Hi,
in the folowing batch, I would compare if the file is the same in the source DIRECTORY and in the destination directory.

with the commande : copy c:\TEMP\*.pdf c:\psipi\rde\30

Note that *.pdf is not ever the same. So I would know that if the 2 *.pdf files are same, the loop make a rename with an extension *_1 or *_2.pdf
Thanks a lot for the help

MY BATCH :

@ECHO OFF
CLS

SET RSOURCE=%1
ECHO REPERTOIRE SOURCE=%RSOURCE%

SET FICHIER=%2
ECHO FICHEIR=%FICHIER%

SET RDESTINATION=%3
ECHO REPERTOIRE DESTINATION=%RDESTINATION%

FOR /F "tokens=1,2* delims=." %%G IN ("%FICHIER%") DO CALL :SPLIT %%H %%G
GOTO :SKIP

REM **************************************************************
:SPLIT
SET EXTENSION=%1
ECHO EXTENSION=%EXTENSION%
SET RACINE=%2
ECHO RACINE=%RACINE%
REM **************************************************************
GOTO :EOF
:SKIP

SET SOURCE=%FICHIER%
ECHO SOURCE=%SOURCE%

SET BACKUP=%RACINE%.%EXTENSION%
ECHO BACKUP=%BACKUP%

CD %RDESTINATION%
IF NOT EXIST %BACKUP% GOTO :FIN

SET INDEX=0
REM ***********************************************************
:LOOP
SET /A INDEX+=1
SET BACKUP=%RACINE%_%INDEX%.%EXTENSION%
ECHO %BACKUP%
IF EXIST %BACKUP% GOTO :LOOP

REM **********************************************************
:FIN
ECHO %BACKUP%



REM #################################################################################################
ECHO FICHIER=%FICHIER%
ECHO SOURCE=%SOURCE%
ECHO BACKUP=%BACKUP%

IF NOT %FICHIER%==%BACKUP% RENAME %FICHIER% %BACKUP%
COPY %RSOURCE%\%SOURCE% %FICHIER%
REM #################################################################################################
cd..
GOTO :EOF

REM **********************************************************
:EOF

6205.

Solve : View MBR Data from DOS????

Answer» ANYONE know if you can view the contents of the MBR data of a HD through a DOS command of some sort or any special software???

Working on an issue with Ghost 2003 and a Hard Drive with 4 partitions where it complains that there is not enough free space on the MBR to create a virtual partition needed for Ghost operation. If you dump the 4th partition and go back to 3 partitions, Ghost will work ... Just curious as to how jam packed the MBR is to not allow for the 4th needed partition and if some fluff can be removed to allow for it to squeeze in to the MBR. Have been tempted to just go the work around route of install a second HD and install Ghost on that drive to then be able to clone the drive with 4 partitions from a virtual partition (swap) off of the 2nd physical drive, but if that is not needed, I'd LIKE to avoid it and learn more about making changes to the MBR if permiited to do so... I do know that a mistake in the MBR would be very bad, so I would copy the data from the 4 partitions elsewhere while I tinker to see if it can fit.There is an older program that will do just this called MBRWiz...see if you can find it on the web if not let me know and i'll DIG it out of my archives...

It's a dangerous tool when not used properly if you know what i mean but i had good luck with it.

If MEMORY serves me correct i believe depending on the file SYSTEM the MBR is limited to 64K, but don't quote me on that one. It's been awhile.Try:

http://mbrwizard.tripod.com/

http://mbr.bigr.net/MBRWiz153.zip

http://www.geocities.com/mbrwizard/index2.html
6206.

Solve : Net Start crashes Dos 6.22 with Himem.sys loaded?

Answer»

I need to GET this working. I am running dos 6.22 in virtual PC 2007. I have all my drivers installed, etc but when i RUN "NET start" the system hangs after showing the nic info. If i remove himem.sys from config.sys it works great. Any ideas?

config.sys
Code: [Select]DEVICE=C:\VMADD\VMADD386.SYS
DEVICE=C:\WINDOWS\HIMEM.SYS
DEVICE=C:\WINDOWS\EMM386.EXE RAM I=B100-B7FF I=C600-C7FF I=CC00-CFFF I=E600-EFFF FRAME=D000
DOS=HIGH,UMB
DEVICEHIGH=C:\WINDOWS\SMARTDRV.EXE /DOUBLE_BUFFER
DEVICEHIGH=C:\WINDOWS\IFSHLP.SYS
STACKS=9,256
REM **********************************************
REM **** DOS Virtual Machine Additions *****
REM **********************************************
DEVICEHIGH=C:\VMADD\CDROM.SYS /D:IDECD001 /L:E
LASTDRIVE=Z
DEVICEHIGH=C:\WINDOWS\DC21X4.DOS /I:C:\WINDOWS

autoexec.bat
Code: [Select]LOADHIGH C:\WINDOWS\SMARTDRV.EXE /L
@ECHO OFF
PROMPT $p$g
PATH C:\WINDOWS;C:\DOS
SET TEMP=C:\DOS
@REM **********************************************
@REM **** DOS Virtual Machine Additions *****
@REM **********************************************
LOADHIGHG c:\vmadd\fshare.exe
LOADHIGH c:\DOS\MSCDEX.EXE /D:IDECD001 /L:E /M:8
LOADHIGHG c:\vmadd\idle.com
LOADHIGH c:\vmadd\mouse.com
rem LOADHIGH C:\WINDOWS\net start

6207.

Solve : Need help accessing cdrom drive in config.sys?

Answer»

I need to make a boot floppy that grants cdrom access in the beginning of config.sys

Normally to access a cdrom from a bootable dos floppy, an entry needs to be added to both config.sys (which binds a driver to the cdrom) and then one in autoexec.bat (which binds a drive letter to the cdrom).

My problem is I need to give the cdrom a driver AND give it a drive letter BEFORE autoexec.bat comes into play (at the top of config.sys no less) this way I'll be ABLE to have my config.sys lines use the cdrom path for their data.

What I've tried:
Config.sys in the A:\ drive with a cd in the cdrom drive with information on the cd located "D:\NETNET\3C90X\NTSTS.DOS"
---------
Test1:
DEVICEHIGH=A:\OAKCDROM.SYS /D:MSCD001
install A:\MSCDEX.EXE /D:MSCD001 /L: D

DEVICEHIGH=D:\NETNET\3C90X\NTSTS.DOS
set? a= did it load the above with no ERRORS?
(can't access the D drive.. so this didn't work)
(Turns out "install" lines RUN AFTER all other config.sys lines.. so this doesn't help)
---------
Test2:
DEVICEHIGH=A:\OAKCDROM.SYS /D:MSCD001
DEVICEHIGH=A:\MSCDEX.EXE /D:MSCD001 /L: D

DEVICEHIGH=D:\NETNET\3C90X\NTSTS.DOS
set? a= did it load the above with no errors?
(freezes after oakcdrom.sys line)
---------
Test3:
DEVICEHIGH=A:\OAKCDROM.SYS /D:MSCD001
DEVICE=A:\MSCDEX.EXE /D:MSCD001 /L: D

DEVICEHIGH=D:\NETNET\3C90X\NTSTS.DOS
set? a= did it load the above with no errors?
(freezes after oakcdrom.sys line)


The only other idea I have at this point is from a thread online I read, there was mention of a dos shim that allows one to load drivers from autoexec.bat.. HOWEVER no mention of said shim's name or a url to said shim (and I've looked all over and had no luck in my search for one thus far)

So thats where I'm at.. There has to be some way to do this. Any advice on how I can accomplish this would be much appreciated.

6208.

Solve : convert decimal to hexa?

Answer»

Hello everybody

I have got problem with converting decimal number to hexa.

I need to convert some entered number in batch file and print it's hexa value without some SHELL in MSDOS.

For EXAMPLE, I enter number 10 via command set /P Par1=Enter decimal number:
and i need to print via echo command its hexa value 0A and SAVE this value to enviromnent variable.
Is possible something such to make in MSDOS? I found nothing in MSDOS.

My second way:
Then I tried to create the small program in C which convert decimal value to hexa. The decimal value is input parameter of this program and returned value is hexa value (char *).

I know that I can find out this returned value from env variable %ERRORLEVEL% ,but i need to return string value (with integer returned value - no problem). When I return hexa value, %ERRORLEVEL% contain some number maybe pointer adrress.

Can somebody help me to resolve this problem. I can not use some shell.

Thanks








6209.

Solve : Hidden file?

Answer»

I want to make a file to be hidden. How can I do it in DOS??attrib +h file10x How about showing (super)hidden files on dir command then?well to show the file again its attrib -h fileQuote from: NiTeCr4Lr on April 25, 2007, 02:43:28 PM

How about showing (super)hidden files on dir command then?

You can find this out yourself!!! Just type DIR /? at the prompt and then READ the help text.

It is good to help people but they MUST learn to help themselves at some point. EVERYBODY who wants to use the command line should read a good tutorial and do plenty of experiments. This is a subject where an ENQUIRING mind is absolutely needed!

You use DIR with the /A switch. A is for Attribute.

DIR /AH shows all hidden files or folders. Other SWITCHES are /AS (system files) /AR (read only) /AD (only show directories) /AA (show files ready for ARCHIVING). They can be accumulated thus DIR /AHRS.

Use a minus sign to indicate the opposite so e.g. DIR /A-D will exclude directories from DIR's listing.



6210.

Solve : Update bat file contents?

Answer»

I search and found many close examples, so posting this request, easy for some people here Im sure.

We have a group of FILES, mostly .bat files that have passwords in them (yes, I KNOW) and every month the passwords need to be updated.

I WOULD LIKE a batch FILE that takes the new password as a parameter then updates the old one in all the files.

I have this working for most files, but some of our .bat files have special characters in them which are not getting put into the new file.

Example .bat file:

set server=value
set user=value
set password=value
set db=value

pushd %~dp0

CALL "SQLCMD.EXE" -S %server% -U %user% -P %password% -d %db% -Q "%db%.dbo.reSETpartition"

popd

6211.

Solve : File managing White use of batch files?

Answer»

I have WINDOWS XP SP2.
Is it possible to create a FILE with a limited size.
I also want that the file is automatically CLEANED after 24hour.
I would like to do that with build in windows options.(Without any other PROGRAM that I need to install.)
Is this possible?

Thanks in advance

Jonas
a batch file need to run whole the time and you ll have a black window.
or can you create a hidden batch file?
then my batch file would be:(I would have to save it into Programs/startup)

@echo off
cls
:Begin
If exist E:/printer/temp del /s /q E:/printer/temp
MD E:/printer/temp
WAIT -t 3600
GOTO Begin

Is this a good batch file? (accept that I don't know how you can SET a delay time.and its not hidden)I just learned how to create a batch file sow my apologies if its very bad.

I want to use E:/printer/temp as a temporary file were we can copie documents that we have to print on the main computer.
The printer sharing doesn't work but file sharing does.

Sow that's my explanation for my request.Is this info that can be use for wrong purpose ?
If this is true I'll remove this topic wright away.

6212.

Solve : Change Computer Name from DOS Shell ????

Answer»

I was wondering if there was a way to change a computer name from the DOS shell over the network to another computer by communicating by IP and not by NAME ... Reason why I ask is because we have 3 cash registers which are running XP Embedded OS, and I have to change the system names to POS(x)- Location, and we have 3 systems that are not named in this standard of POS(x) where x = lane ID - Location such as POS3-LEBANON.

All the communications happen through UNC calls by IP, so the name is not important to the operation of the systems, but is important if trying to VNC into the systems by Nme and not IP, so I would like to CORRECT this remotely over the network through a DOS Shell if possible vs having to shut down the register lane to change the system name.

Also I am unsure as to if the name can be changed over the network without a reboot??? SINCE when going through the GUI to change the system name, it always wants to reboot after....

MAYBE this can not be DONE, and i just need to shut down the lanes and do it the normal way through the GUI, and reboot...

6213.

Solve : How can we Modify a .sql file without changing the timestamp?

Answer» HI all,

I have a folder of say 500 .sql files. I am planning to modify the CONTENT of all the files in ONE shot. But i dont want to change the Created, Modified or Accessed timestamp of the file.

Is this possible.

There should be some TOOL which when given with 2 folder with source (Source files) n destination folder (Modified files) automatically reads the all the 3 timestamp from source file name and apply it to the same file in destination folder.

Let me know if someone can help.

Thanx
Raj
6214.

Solve : con & prn??

Answer»

in cmd, and windows.. why does TYPING 'con' or 'prn' = blank ?

like if i named a file or folder prn or con , it would just revert back to its original title.
if i tryed it from write to create a new file i mean , it would come back.. "cannot create the C:\documents and settings\%username%\desktop\con file. is this because of the same flaw that makes "this app can break" work?

also , clock\$ returns "the system cannot find the file specified" why? CON and PRN go way back to the wild and wooly days of DOS where they were reserved device names. The tradition has been carried forward thru all the iterations of Windows. The more things change....

Quote

MS-DOS supports five standard character devices which can be used by name as read or write destinations (according to their capacities).

(1) CON (Console=monitor/keyboard)
COPY textfile.txt CON
Copies textfile.txt to CON (output=monitor display), so displaying textfile.txt contents (similar to TYPE).

COPY CON textfile.txt
Copies line(s) of text typed at CON (the keyboard) to textfile.txt. To finish text entry, press Ctrl Z then RETURN . USEFUL for creating small text files.

(2) PRN (Printer)
COPY /b textfile.txt PRN
Copies textfile.txt to PRN (your standard printer). By default, COPY to devices is ASCII-based (terminates on Ctrl Z ), so /b(=binary) is used if the file to be printed contains intermediate Ctrl Z characters.

(3) AUX (Auxiliary device)
Not normally used in Batch files.

(4) CLOCK$ (System clock)
Not normally used in Batch files.

(5) NUL ("Bit bucket")
COPY c:\src\*.* c:\dest\*.*&GT;NUL
Copies files from c:\src to c:\dest with all the progress messages from COPY sent to NUL. Characters sent to NUL are merely discarded, so redirection to NUL is useful to suppress unwanted messages.

Other devices supported usually include:
COM1 First serial port (often connected to modem)
LPT1 First parallel port (an alias for PRN)

...courtesy Allenware.com

Quote from: Diablo416 on April 26, 2007, 02:59:09 PM
also , clock\$ returns "the system cannot find the file specified" why?

Please explain a bit more what you're trying to do here.
6215.

Solve : New Account on a flash drive?

Answer»

is it possible to make a NEW account on a flash drive,
and if so can i do it through batch files. My OS is XP-2002, just let me know if you need more info on my computerYou might be able to use the local users management tool (LUSRMGR.MSC) from the Start==>Run box.

This will work on XP Pro, don't know about XP Home.

Good luck.
your RIGHT, i have home, and it doesnt support it. i WANTED to do this so i could make an admin account with out a password, so if i forget my, because if u havent read my previous posts, my user accounts menu doesnt work, so i can't make a back-up DISK for my password.
unless you know how to do that through batch, that would be great.

6216.

Solve : Need just the pathname?

Answer»

I've got a bat file that will QUERY the registry for a setting and it gets string just fine, but the string data includes a filename and I want just the pathname from that.

Code: [Select]for /f "skip=2 tokens=3*" %%G in ('reg query "HKLM\SOFTWARE\ROCKSTAR Games\GTA San ANDREAS\Installation" /v Exepath') do set GAMEPATH="%%G %%H"This returns where the exe is, in my case "D:\Rockstar Games\GTA San Andreas\gta_sa.exe" but not everyone has GTASA installed in the same place, so I need just the "D:\Rockstar Games\GTA San Andreas".
try adding a second set that removes the exe name. SOMETHING LIKE this

Code: [Select]set gamepath=%gamepath:gta_sa.exe=%

I think that should do it.Worked perfectly, thanks.

6217.

Solve : MOVE command with network drives?

Answer»

Hi, I am trying to create a batch file that will move files/documents from multiple locations on a shared network drive into one directory (EITHER local or networked).

I tried using the move command, but it doesn't seem to work when I am using mapped network drives.

Is there a way that I can set this up so I have a series of command lines moving individual files from those various network DIRECTORIES into one directory?

Thanks,
PatrickIf you have full rights to those network directories the move command should work with no problems. However, if you only have read rights the move command would FAIL, but you should be able to use the copy command.

If you do have full rights, mind posting the command you're using to copy the files and have you tried moving the files outside of a batch file?Yes, I do have full rights to those directories. I tried running the command outside of the batch file and I keep getting the message: "The System Cannot find the file specified".

Here is the command line I am using:

move \\Ykgnwt\GNWT Share\Records Management\ARCS TEMPLATE\Information Systems\6003 - Information Services - General\6003-01 - General - 2_0_D\I P 2003 to 2006 (Draft).doc C:\

move \\Ykgnwt\GNWT Share\Records Management\ARCS TEMPLATE\Information Systems\6003 - Information Services - General\6003-01 - General - 2_0_D\test doc.doc G:\TESTING (directory does exist)

I'm thinking I am not entering the UNC correctly. Am I able to execute the move command by not being in the same directory that the file in question is?

Thanks a lot,
PatrickIt looks like you have SPACES, long file names, uncommon characters, etc. I'd first SUGGEST you surround your network path with quotes, for example:

move "\\Ykgnwt\GNWT Share\Records Management\ARCS TEMPLATE\Information Systems\6003 - Information Services - General\6003-01 - General - 2_0_D\I P 2003 to 2006 (Draft).doc" C:\

Give that a shot. In all honesty I've never used the move command over a network so I'll have to try and play around with that myself. However, if all else fails you could use the net use command and map the drive and then move the files from the mapped drive to your location.

For example,

net use f: \\hope\inc

Above command would map path to F:

From there you could copy the files from F: to C:
Hi! Not sure if this wil be too useful but try giving this a go -

Open notepad

Type in the following -

xcopy "(insert the directory of your shared drive)\*.*" (Insert the drive you want the stuff copyed to) /s

so for example it could look like -

xcopy "C:\Documents and Settings\J\Shared\*.*" D:\Copyed /s

Then save the file as 'whatever you wanna call it' .bat

Hope that helps instead of the move command, you probably already know this but the infos there if you need it Worked like a charm once I put the quotes around the network path.

Thanks a lot for your help.

PatrickYou're welcome and thank you for the follow up.

6218.

Solve : Copying Mulitiple Files in Order?

Answer»

Hi,

I have been given a task at work to move a number of files from one computer to another. The start computer runs on DOS and only has a floppy drive. The files I need all end in a certain extension and there is over 10 megs worth so it will not all fit on 1 disk. I copied all the files I needed (*.sum) and I was hoping that once the first disk was full I could just pop in another and it would carry on copying them across. Unfortunately it just stopped. I can't jsut try that again as it will copy all the files I have already copied across and won't get to the new ones.

Is there a way of saying that I want to copy all files of a certain extension, from the last file that was MOVED to SAY another PREDETERMINED file, in the order that they are listed, to the floppy drive.

Many thanks.You can use the Xcopy and Attrib commands to copy files onto multiple diskettes, providing no single file is larger than the total size of the diskette. In that case, you have to use the Backup command or other Backup utility.

The Attrib command is used to set all archive bits on. When a file is copied, the bit is turned off. Each time Xcopy does not have enough room to copy the next file, you will get a "Disk Full" message. Put in another blank disk and REPEAT the Xcopy command. The archive bit keeps the previously copied files from being copied again.

Xcopy copies the files in alphabetical order.

For example, to copy all the .sum files in the C:\DOCS DIRECTORY onto floppies, type:

This presumes that the floppy drive is drive A, if not change as appropriate.

Prepare a set of blank floppies. I suggest you stick labels on them.

do this once...

C:\DOCS>attrib +a *.sum

repeat until done...

C:\DOCS>xcopy *.sum A: /m

When each disk is full, remove it and write eg a number on the label to remind you later which disk is which.

6219.

Solve : Listing lines which appear in FILE1.TXT but not FILE2.TXT?

Answer»

Hello,

Is there any way I can get a listing of text lines which do appear in FILE1.TXT but not in FILE2.TXT ?

For example, if FILE1.TXT contains the following text....

C:\January
C:\February
C:\March
C:\April
C:\May
C:\June

....and FILE2.TXT contains the following text....

C:\June
C:\May
C:\March
C:\February
C:\January

....then the output listing would be, for example....

C:\April


THANK YOU FOR YOUR TIME,
James

P.S. I am using Windows XP [Version 5.1.2600] cmd.exe

Thanks,
JamesNormally files to be compared should be in sequence (not calendar sequence but ascii or unicode sequence). Batch code has no random or direct i/o only sequential which can only be used in the CONFINES of a loop which the user cannot directly control.

With XP, I would suggest a Windows Script using the dictionary object.

Check out these Four Guys

Good luck.

Quote

Normally files to be compared should be in sequence (not calendar sequence but ascii or unicode sequence). Batch code has no random or direct i/o only sequential which can only be used in the confines of a loop which the user cannot directly control.

I am unsure of the RELEVANCE of these remarks?

Code: [Select] @echo off

REM Quick hack...
REM diffline.cmd
REM syntax diffline file1 file2

REM in a loop, read every line in file 1

for /F "delims==" %%a in (%1) do (

REM and try to find it in file 2
REM echo the line if NOT found

type %2 | find "%%a"> nul || echo %%a

)

REM in a loop, read every line in file 2

for /F "delims==" %%a in (%2) do (

REM and try to find it in file 1
REM echo the line if NOT found

type %1 | find "%%a"> nul || echo %%a

)




Code: [Select]
I:\test>type file1.txt
C:\January
C:\February
C:\March
C:\April
C:\May
C:\June

I:\test>type file2.txt
C:\June
C:\May
C:\March
C:\February
C:\January

I:\test>diffline file1.txt file2.txt
C:\April

I:\test>


Code: [Select]I:\test>diffline file1.txt file2.txt > diff.txt

I:\test>type diff.txt
C:\April

I:\test>

Thanks contrex. That's brilliant.

One further slight complication / question... :-)

Is there any way to get it working if FILE1.TXT contains a double-quote character? Find.exe reports an error SAYING "Parameter format not correct" if its search string contains double-quote.

Not to worry if this isn't possible, because I have a utility (called FRT.EXE -- Find and Replace Text) which can pre-processs the files by SUBSTITUTING all double-quotes (hex 22) with two single-quotes:-
Code: [Select] @echo off
REM Quick hack
FRT.EXE -C %1 \x22 ''
FRT.EXE -C %2 \x22 ''
for /F "delims=" %%L in (%1) do (type %2|FIND.EXE "%%L">nul || echo %%L)
Thanks again,
JamesHi contrex,

I did find a small bug in the above code, regarding listing text lines which appear in FILE1.TXT but not FILE2.TXT.

The good news is I've fixed the bug. See new version below, which also handles double-quotes without needing any pre-processing :-

Code: [Select]C:\> type diffline2.bat
@for /F "delims=" %%L in (%1) do @( set DIFF_LINE1=%%L& set DIFF_LINE1=!DIFF_LINE1:"=DOUBLEQUOTE!
set DIFF_FOUND=0
for /F "delims=" %%M in (%2) do @( set DIFF_LINE2=%%M& set DIFF_LINE2=!DIFF_LINE2:"=DOUBLEQUOTE!
if "!DIFF_LINE1!"=="!DIFF_LINE2!" set DIFF_FOUND=1
)
if !DIFF_FOUND!==0 echo %%L
)


C:\> type file1.txt
C:\DIR1
C:\DIR12
C:\DIR123

C:\> type file2.txt
C:\DIR1
C:\DIR123

C:\> diffline2 file1.txt file2.txt
C:\DIR12

C:\>

NOTE that this batch file MUST be run with cmd.exe "/V" flag, because it requires "delayed environment variable expansion". Batch file will NOT work correctly without cmd.exe "/V" flag.

Batch file tested using Windows XP [Version 5.1.2600].

Best regards,
JamesThis batch file can also be used to list lines which are output from 'COMMAND1' but not output from 'COMMAND2'. For example:-

Code: [Select]C:\> DIR /b folder1
alpha.txt
beta.txt
gamma.txt

C:\> DIR /b folder2
alpha.txt
gamma.txt

C:\> diffline2 '"DIR /b folder1"' '"DIR /b folder2"'
beta.txt

C:\>

(Note batch file must be run with cmd.exe "/V" flag, because it requires "delayed environment variable expansion"..)

Regards,
JamesFound another couple of bugs in the above DIFFLINE2.BAT :-

(1) Failed to work correctly for text line STARTING with ";" (simi-colon)
(2) Failed to work correctly for text line containing "!" (explanation mark)

I've fixed the first of these bugs. See DIFFLINE3.BAT below. Cannot fix second bug. Work-around is to pre-processs files by substituting all explanation marks with another character.

Code: [Select]D:\> type DIFFLINE3.BAT
@echo off
REM **** DIFFLINE VERSION 3 (1st May 2007)
REM **** List text lines which appear in "%1" but not in "%2"
REM **** MUST be run using "CMD /V" to enable delayed environment variable expansion
REM **** FAILS to work correctly if text lines contain "!" (explanation mark characters)

for /F "eol= delims=" %%L in (%1) do ( set DIFF_LINE1=%%L& set DIFF_LINE1=!DIFF_LINE1:"=DOUBLEQUOTE!
set DIFF_FOUND=0
for /F "eol= delims=" %%M in (%2) do ( set DIFF_LINE2=%%M& set DIFF_LINE2=!DIFF_LINE2:"=DOUBLEQUOTE!
if "!DIFF_LINE1!"=="!DIFF_LINE2!" set DIFF_FOUND=1
)
if !DIFF_FOUND!==0 echo %%L
)


D:\> type test1.txt
;
;;;
!
!!
!!!
"
"""
&
&&
&&&
<
<<<
|
||
|||
>
>>>
;!"&<|>
;!"&<|>.
;!"&<|>..

D:\> type test2.txt
;
;;
;;;
!
!!!
"
""
"""
&
&&&
<
<<
<<<
|
|||
>
>>
>>>
;!"&<|>
;!"&<|>..

D:\> DIFFLINE3 test1.txt test2.txt
&&
||
;"&<|>.

D:\> DIFFLINE3 test2.txt test1.txt
;;
""
<<
>>

D:\>

Regards,
James
6220.

Solve : .bat file to create desktop shortcut?

Answer»

Sorry, but it has been a long day, and my brain (apparently) is spent. I have created a file on our server and I want to send a .bat file to my employees that will create a desktop shortcut on their individual machines. Here is what I have tried:

xcopy s:\common\blah.lnk c:\docume~1\alluse~1\desktop\blah.lnk /y

and

xcopy s:\common\blah.lnk c:\docume~1\alluse~1\deskto~1\blah.lnk /y

I have also tried the copy from the s:\ drive using the actual file and copying it as a .lnk and that hasn't worked EITHER.

The file is actually a database, so I don't want to copy the file itself, just the link.

Thanks!!

By the WAY, our OS is XP if that makes a difference.
Maybe this will help:

CODE: [Select]xcopy s:\common\blah.lnk c:\docume~1\%username%\desktop\blah.lnk /y

Just curious, but why XCOPY? Would not COPY work just as well?

Hmm, I tried that and it didn't like it either. I think it has something to do with .lnk files. I've never tried doing this before with just the shortcut file. This database is only going to be used for about a month and I was hoping to get away from having to build installation files.

FYI, the only reason I used XCOPY instead of COPY is because of force of HABIT. Awhile back I had to set up a program to copy files across our WAN to keep a website updated and it wouldn't work with COPY. I switched to XCOPY and it worked and I have kind of been using it exclusively since then.As an FYI, I went the MSI route instead. If anyone does KNOW how to do what I originally asked about, I would be interested in knowing.

Thanks!
Maybe it would work with some " ".
So, try something like:
xcopy s:\common\blah.lnk "c:\docume~1\alluse~1\desktop\blah.lnk" /y
or
xcopy s:\common\blah.lnk "c:\documents and settings\all users\desktop" /y
Hmm, hadn't thought about using " "". Unfortunately, neither of those ways worked either. Thanks for the suggestion though!Oh, well... Maybe you need to tell us something else. Like: s: is a network share mapping? And question no 2: what error message do you receive?

6221.

Solve : Moving certain file sizes?

Answer»

How would you make a Batch file that moves any file over a certain size to another location?Q: How would you make a Batch file that moves any file over a certain size to another location?
A: We can do it with VBS, if Operational System is Microsoft (XP/2000/2003 etc.)
May be you know. VBS is simple script language (Same Visual Basic SYNTAX)
1. step is execute dir command in to file,
2.step file reading and file moving\deleting

Same process script read to filename and delete for LAST 3 days file . Script is below. Have you changed it?

'on error resume next
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("%comspec% /k dir /b \\server1\C\project\QUALITY\ >> \\server1\C\project\QUALITY\dir.txt")


Wscript.sleep 6000
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
GUN=Weekday(CurrentDate)
hesap=Mid(gun,1,3)
dene =InStr(hesap,1,".")
'Wscript.Echo dene
datex=date-3
tarx=Month(datex)
tary=day(datex)
tarz=year(datex)
tar1=len(Month(datex))
tar2=len(day(datex))
if tar1=1 then tarx="0"&tarx
if tar2=1 then tary="0"&tary
time1=time-0.01
bsaat=mid(time1,1,2)∣(time1,4,2)∣(time1,7,2)
silme=tarz&tarx&tary
'Wscript.Echo silme



Set objTextFile = objFSO.OpenTextFile (" \\server1\C\project\dir.txt", ForReading)


Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")
i=i+1
'Wscript.Echo silme &" : "∣(arrServiceList(0),1,8)
sildosya= arrServiceList(0)
dosdos=mid(arrServiceList(0),1,8)
if silme=dosdos then
silsil=" \\server1\C\project\QUALITY\" & sildosya
yoket="%comspec% /c del " & silsil
Set objExecObject = objShell.Exec(yoket)
end if

Loop
objTextFile.close
Set objExecObject = objShell.Exec("%comspec% /c del \\server1\C\project\QUALITY\dir.txt")But can it be done in a Batch file (because I already have the program that I want to use, but I haven't added this bit YET)?I know you can move files but do you want to move files of a specific size like above 2mb?Quote from: Carbon Dudeoxide on May 01, 2007, 12:27:23 AM

I know you can move files but do you want to move files of a specific size like above 2mb?
Yes (well, above 200kb, actually). So, you got any ideas?I dunno, hang tight and maybe someone else will have the answer to that.
Does it have to be above 200kb, why not the name of the file instead?Quote from: Carbon Dudeoxide on May 01, 2007, 12:47:28 AM
I dunno, hang tight and maybe someone else will have the answer to that.
Does it have to be above 200kb, why not the name of the file instead?

I can't use the file name because the point of my program is for the user to just open the batch file and VOILA, instead of having to access to the folder and renaming every file that needs to be renamed (as it is now, I manually changed the name of the ONLY large file, but it won't work on other computers).the below is an example script. change the for loop parameters to suit your needs
Code: [Select]
for /F "tokens=4* skip=4 delims= " %%A in ('dir /A-D') do (
REM files greater than 40 bytes
if %%A GTR 40 (
echo %%B %%A
rem your move command here
)
)

Thanks. Can you explain what the code means (The command prompt explanation for FOR is a bit too complicated...)?delims mean delimiters so "delims= " mean i am going to use spaces as my delimiter from the dir /A-D output. each "field" separated by the delimiter i call them tokens, so tokens=4* means i am going to get token number 4 onwards, which from the dir /A-D output, is the size in bytes at token 4. Then in the for loop, when i echo %%A , it will the bytes, and if i echo the next token , denoted by %%B, it will be the filename.
I hope you understand what i am saying.
6222.

Solve : changing file type of everything in a folder?

Answer»

How WOULD you change the entire contents of a folder into the same file type using command prompt?

By the way, everything in the folder is simply a file, it DOESN'T have a file extension.Do you mean like changing .exe's to a folder in a specific place?What I mean is that changing everything (let's call one of them A) in one folder to ANOTHER file type (i.e. from .gif to .bmp).

I can change individual files by doing:

Code: [Select]C:\FOLDER\A.gif > C:\FOLDER\A.bmp
And I try this:
Code: [Select]C:\FOLDER\*.* > C:\FOLDER\*.bmp


You seem to be confused about the difference between a file type and a file extension.

A GIF image type file usually has the extension gif, and a Windows Bitmap type file usually has the extension bmp, but if you change the extension of a GIF file to bmp, it does not magically become a bitmap file. It is still a GIF file, but now with the wrong extension. Load it into an image editor, and the editor may well give an error message.

You could change a file's extension from GIF to mp3, but that does not mean you'll hear a PRETTY tune when you try to play it.

If you want to convert a GIF file to a BMP file, you have to convert it with image processing software.

Only a few file types can be changed by changing the extension. You can change a txt file to a doc file and it would still be READABLE.

You can change (for example) all the txt files in a folder to doc files by renaming them with the ren command thus:-

ren *.txt *.doc

You can rename all of the files in a folder to doc files by renaming them thus

ren *.* *.doc

But some may not be readable in Microsoft Word!


Whoops! Question was already answered, sorry.

Do you want everything to have the same extension? If so this should work, if not more info is needed.

Code: [Select]for /F "delims=" %%a in ('dir /b c:\blah') do ren "c:\blah\%%a" "%%a.ext"

You'll have to edit the paths of course.Thanks contrex, it worked. And thanks for your help as well, profit, but I like it simple.

6223.

Solve : Two questions about Auto Shutdown code?

Answer»

Hi, I has questions about the auto shutdown thing in command prompt, so if you'd please be kind enough to answer em, that'd be grand

Alright.

1. I tried to shutdown my computer at a certain time by creating a shortcut with the code Shutdown -s -t 00 -f, and then scheduled it to run at 11. Well, come 1, it was still on...and when I opened the shortcut it shutdown right, but when you run it from the scheduler it apparently opens a ms-dos box then closes it at the speed of light, anyone know why?

2. When i tried messing around with different forms of the shutdown code, like shutdown -t 60 or shutdown -c "Installing Effres.exe", it didnt work that way......it just shutdown completely with no changes as to how it shuts down.........What'd I do wrong here?

Oh and I have Windows XP Service 2 by the way. Thanks in advance!When I to replicate your code and double-click it, it just showed the code (i.e. it didn't execute).

I think this is because you can't use shutdown in a batch file (correct me if I'm wrong, more experienced people). I used the same code directly into Command Prompt, it worked.

But you said that it worked when you double-clicked it, only not in schedule? When I schedule it, it does the same thing as double-clicking = showing the code, not executing.For a batch file, use this:

Code: [Select]shutdown -s -f -t "00"
That works for me.Quote from: Carbon Dudeoxide on April 20, 2007, 07:41:12 PM

For a batch file, use this:

Code: [Select]shutdown -s -f -t "00"
That works for me.

It doesn't work when you put it in a batch file and try to OPEN it. It just repeatadly displays the code.Quote from: Dark Blade on April 20, 2007, 07:55:48 PM
It doesn't work when you put it in a batch file and try to open it. It just repeatadly displays the code.

What do you mean by "displays the code"? Do you mean loading it into notepad? Are you double clicking the batch file? How do you normally run batch FILES?

This is what I use to shut down my computer. I have been using it every day for about 2 years in a batch file. Works every time. No quotes around the time parameter either. Actually I always use the .cmd extension rather than .bat these days to get the advantages of Windows XP's cmd.exe. i wonder if this makes a difference?

Code: [Select]shutdown -s -t 01 -c Code: [Select]shutdown -s -t 01 -c
You don't actually need to have -c (that displays a MESSAGE). But it might work differently in .cmd.

Nope. I tried that, it does that same as .bat.

Quote
What do you mean by "displays the code"? Do you mean loading it into notepad? Are you double clicking the batch file? How do you normally run batch files?
I save the code as a batch file, and when I open it (double click), displays:
Code: [Select]shutdown -s -t 30
shutdown -s -t 30
shutdown -s -t 30
shutdown -s -t 30
shutdown -s -t 30
shutdown -s -t 30

And just says that a lot.

Just to make sure, are you typing the code in notepad, saving it to the desktop as name.bat and double clicking 'name.bat' ?Quote from: Dark Blade on April 21, 2007, 05:55:59 PM
You don't actually need to have -c (that displays a message). But it might work differently in .cmd.

I accidentally cut off the rest of the line. It should read

shutdown -s -t 01 -c "System closing down!"

Quote
I accidentally cut off the rest of the line. It should read

shutdown -s -t 01 -c "System closing down!"
OK.

Quote
Just to make sure, are you typing the code in notepad, saving it to the desktop as name.bat and double clicking 'name.bat' ?

Yep. I do that, and it does exactly what I said before (even if I save it as .cmd, not .bat).A long shot...

http://www.aumha.org/win5/a/shtdwnxp.php

In fact that page is full of shutdown problem tips.

It seems a shutdown batch file can hang sometimes for example as here, but there are other causes. Google for "shutdown batch hangs"

Quote
USING SHUTDOWN SCRIPTS & 802.1x AUTHENTICATION PROTOCOL. This combination can cause Win XP to take in excess of 10 minutes to shutdown normally. (IEEE 802.1x is an authentication standard for both wireless networks and wired Ethernet networks.) Here’s how the dominoes fall: The 802.1x authentication protocol stops after the user logs off. Shutdown scripts run after the user logs off. If the script is on a network share and the connection is no longer available (since authentication has terminated), the script can’t run. The default time-out for shutdown scripts is 10 minutes. So the computer sits there 10 minutes before continuing with its shutdown.

Anyone know how to give said batch file a trigger, such as when a specified file is accessed? All,

Try using the following to shutdown Windows XP from an MS-DOS batch file:-

start shutdown.exe -s -f -t 0

Works for me.

Hope that helps,
James
6224.

Solve : How to creating empty file??

Answer»

Helo everybody

I have one question.

How can I create empty file via command line in MSDOS ?

Thanks

Code: [SELECT]copy con "(where-ever i.e. C:\)"\(file name).(file TYPE)
E.G.
copy con "C\Documents and Settings\%username%\Desktop\file.txt"but I dont want to open console for editing, only create empty file with 0 bytes.

If you want a really empty file (0 bytes) then do
REM>MyFileName.Ext

GrahamCode: [Select]cd (where-ever you want the files to go)
copy con (file name).(file type)
E.G.
cd "C:\Documents and Settings\%username%\Desktop"
copy con file1.txt
copy con file2.txt
copy con file3.txt
There is probably another way to automatically add a number to the file, but I don't know it.

N.B. You have to press ^Z to create the file
e.g. copy con (file thing here)
(press this now:)^Z (shift-Z)Code: [Select]echo.>> "%userprofile%\desktop\hi.txt"
see if that worksDoesn't >> add text to the file though?Hello

I THINK that REM command RECORDS commnet. I tried it but i don't show any file

echo command puts two character into file, result of echo.>file.txt is file with 2 bytes

Metalpalo
type nul > Drive:\Folder\Filename.Extension

Code: [Select]I:\test\zzz>type nul > zero.txt

I:\test\zzz>dir
Volume in drive I is Various
Volume Serial Number is 4040-A645

Directory of I:\test\zzz

04/05/2007 11:32 <DIR> ..
04/05/2007 11:32 <DIR> .
04/05/2007 11:32 0 zero.txt
1 File(s) 0 bytes
2 Dir(s) 24,466,706,432 bytes free
Sorry guys, rem>filename is a trick that no longer works (Im afraid I go back to DOS 2 days)

The type NUL trick does WORK though
Graham

6225.

Solve : Want to make filename UPPERCASE?

Answer»

Hi all,

I currently have a batch file that copies my new music from a folder on my desktop...., into my other computers..., which works great. I have a LOT of my old stuffs filenames labelled in uppercase, and would like to continue to keep everything new entered in uppercase. At the moment I have to CHANGE everything manually.

Is there a piece of command that would automatically change the filenames in the folder to all uppercase.

Thanks in advance.


Current CODE in file:

copy G:\music\*.wav \\Audio\share\Erics_audio\musicbackup\

move G:\music\*.wav \\Audio\share\Erics_audio2\main\

del G:\music\*.pk
Sorry me again,

I should have said a piece of command that would convert any filenames to uppercase....., just before they are copied to the other computers.

thanksUnfortunatey I couldn't find anything like this I could USE in batch either.

I downloaded a program called multifilerenamer.exe from Sourceforge.net.

It worked out better than I had expected, but I would still like a case changing batch script to downshift my stuff.

Code: [Select]@echo off
setlocal enabledelayedexpansion
set U=ABCDEFGHIJKLMNOPQRSTUVWXYZ
set l=abcdefghijklmnopqrstuvwxyz
for /f "tokens=*" %%a in ('dir /b /a-d *.txt') do (
set filename=%%a
for /l %%b in (0,1,25) do call :u !l:~%%b,1! !u:~%%b,1!
echo Renaming %%a
rem rename "%%a" "!filename!"

goto :eof
:u
set "filename=!filename:%1=%2!")

6226.

Solve : What does FOR do??

Answer»

Can someone explain what the Command Prompt command FOR does?

I've tried reading the help file for it, but it is a BIT too complicated for me.Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

%variable SPECIFIES a replaceable PARAMETER.
(set) Specifies a set of one or more files. WILDCARDS may be USED
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable INSTEAD of
%variable.

6227.

Solve : I want some help with Focusing?

Answer»

I know that it is not possible to focus a window in dos,
but i do know its possible in vbs. so if some one can help me to create a vb script that makes the window with title name "Diablo II" get focused and i also want to know the command for running vbs scripts from batch. correct my SPELLING it sucks :/

//oGeLaM!Perhaps you could be more specific in what you are trying to do. VBScript has no native way of creating a window. It can however create OBJECTS which may or may not have a focus property.

There are technologies for creating windows. HTML Applications (HTA) use a combination of HTML and VBScript that is interpreted within Windows; no browser needed. Powershell can also create windows within the .NET framework. The HTA interpreter comes with windows, however Powershell is a download that also requires the .NET framework to be installed.

Just as batch files need the command/cmd processor, VBScript requires either the wscript or cscript processor.

To get you started, this very basic HTA will create a window, focus it, and put the title Diablo II in the title bar:

Code: [Select]<html>
<!--
-->
<head>
<title>Diablo II</title>
</head>
<SCRIPT LANGUAGE="VBScript">
Sub Window_onLoad()
window.focus
End Sub
</SCRIPT>
<body>
</body>

Save the script with a HTA extension and run from the command prompt.

Good luck.

The nice thing about scripts is there is none of that PESKY compiling and LINKING associated with programming languages.

6228.

Solve : XP Search command?

Answer»

Hi there,

Would it at all be possible to create a batch file in XP that would do a search in a specified location for any files that have a 'created/modified' date older that say a month. And then delete the files found.
Any help greatly appreciated.
Craig.Write dir COMMAND output to a file.
Then search the file using findstr command and get the file name.
Use delete command to delete the file.

Hope this helps
JothishTry XXCOPY (a freeware for personal use)

http://www.xxcopy.com/

It is a general purpose file management tool that can copy,
delete, list, etc. The command syntax is compatible with
that of XCOPY. It offers a wide variety of file-selection
mechanisms that includes file size, file date, AGE, attributes,
etc. just to name a few.

E.g.,

xxcopy "c:\My Documents\*.doc /rs/s/db#30 // 30 days or older
xxcopy c:\ /rs/s/db:1998-04-30 // files made Apr,98 or before Hi chaps, thanks for your replies.

xxcopy seems to do just the trick. although i would also like to be able to do it in a batch file also.
Is it possible to use dir to list files of a certain age? then i COULD output to another folder and delete.you can call xxcopy from a batch file if you put the xxcopy executable somewhere on your PATH.

6229.

Solve : Need help in fetching datas from a log file?

Answer»

hi GUYS,
i have to search two words in a log file like as follows
LOG FILE looks like:
...............
....................
2007 Mar 16 15:37:18:156 GMT +5 BW.SiebelServices-SiebelServices DEBUG [BW-User] - EAI-DEBUG |TPP_APPLICATION|1598352|Siebel_Dispatcher_Main |PROC1006|Process started.. Input Siebel XML Data:






79909


1-T20-152
03

01




...............
....................
i will be searching for two words that i made in bold one is static (Siebel_Dispatcher_Main) and other is dynamic (i.e in the orderid tag.....)
My requirement is fetch the line from Siebel_Dispatcher_Main till the first occurence of the orderid that i will pass....

Thanks in Advance
Jothishmy advice is not using batch to do such file processing. (though it still can be done)
you can use vbscript if you know it, or other better LANGUAGES that can do better file processing.
If you can use GNU awk, Gawk, the solution is as simple as...
Code: [Select]awk '/Siebel_Dispatcher_Main/,/<\/OrderId>/ {print }' file
Thanks YAR........the thing is i am doing this in client machine so they wont give permission to install? Help me in doingthis in batch commands

Thanks in Advance
Jothish

6230.

Solve : Need a help?

Answer» HAI friends

i need a help from you .

my problem is i need to copy a files and folders from network clients to my server .like network backup purpose .Each and every restart inned to copy a files new CHANGES in thats folder .

for example following folders i ned to TAKE all clients and save to client NAMES individuly

C:\Program Files\Microsoft Visual SourceSafe

C:\Program Files\Microsoft SQL Server

C:\Documents and Settings\All Users


This all save to \\192.168.100.22\backup ( This is netowkr shared folder )

how to make a batch FILE pls help me i am very new for this

kartook

6231.

Solve : i need simple help?

Answer»

ok if its POSSIBLE, and it should be, i want to make a message (any noticable message) to APPEAR on my computer via a batch file. I want it so it will do the regular tasks i have the it programmed to do only pop up with a message i make when it is in the MIDDLE of executing all the tasks. If you're using MS-DOS, you're probably limited to the echo statement. If you have a windows machine, SOMETHING like msg %username% message might work for you. The latter requires a response to dismiss the window but the batch file continues to execute.

ok i GUESS it will have to do i was just hoping for more, because nobody even reads the echo. Thank you for informing me though

6232.

Solve : Anybody have a good DOS 'Insert' script??

Answer»

I was wondering if anyone had created an insert script that could do the following:

1) Open a file
2) Find a particular line of text in a file.
3) insert either before or after a line (or more than one line from another file).
4) save the file and exit

Any help would be appreciated. Up until now I have been able to work around this problem, but I think it is going to be a big requirement very soon.

Thanks, Ken
Hi Ken,

I was looking for an answer to this very same question myself. I was able to find a solution to my problem by editting the append function. Specifically, I needed to insert (or append) a string to the beginning of each line in a .csv file to create a NEW field. Here is what I have:

::append str file line -- appends a string to a SPECIFIC line in a text file
:: -- str [in] - string to be appended
:: -- file [in] - file name to append the string to
:: -- line [in] - line number to append the string to, first line is 1, omit for last line
::$source http://www.dostips.com
rem SETLOCAL ENABLEEXTENSIONS
rem SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL
set ap=%~1
set f=%~2
set c=%~3
if not defined c (
set c=0
for /f %%a in ('find /v /c ""^<"%f%"') do set c=%%a
)
(for /f "tokens=1,* delims=:" %%a in ('findstr /n /v "$$"^<"%f%"') do (
if not "%%a"=="%c%" (echo.%ap%%%b >> "file2.csv") ELSE (echo.%%b >> "file3.csv")
))>"%temp%.\t0815.txt"
EXIT /b %ERRORLEVEL%

I call this bat file with the following:
append.bat "14," file1.csv 0

Hope it helps.
Jacquieif you can afford to install GNU awk (or sed) , all that batch code can be simplified to :
Code: [Select]#insert before a line
awk '/<My Tag>/ { print "new text" } {print}' file
# insert after
awk '/<My Tag>/ { print $0; print "new text";NEXT } {print} ' file

6233.

Solve : FOR LOOP questions?

Answer»

Can someone tell me how to use for in MS-DOS FOR LOOP
I writed a BAT to copy other computers files to my computer
But i don't konw how to use it ...

i used James2000's code to stoploop but it doesn't work.

i have forty-four computers.

Code: [Select]@echo off

set computer=s302-s0
set id=1

counting from net use \\%computer%%id% "password" /user:"%computer%%id%\admin"
md z:\form1\%computer%%id%
xcopy "\\%computer%%id%\d$\temp\*.*" "z:\form1\%computer%%id%\"

if %id%==9 goto stoploop
set /A id=%id%+1
goto startloop

:stoploop
echo Finished !
Does anyone know? The stoploop seems to be HANGING in OUTER space.

Code: [Select]@echo off

set computer=s302-s0

for /l %%x in (1,1,44) do (
net use \\%computer%%%x "password" /user:"%computer%%%x\admin"
md z:\form1\%computer%%%x
xcopy "\\%computer%%%x\d$\temp\*.*" "z:\form1\%computer%%%x\"
)
echo Finished !

HAPPY coding.

PS. Is the password really password?

Thank you Sidewinder.

But i have another question, it is the the computer's netbios name.

Because computer 1 to 9 Netbios is s302-s01. When go to computer 10. Its name is s302-s10 .

So i want to use TWO for loop ^^"

Does it ok ?

Code: [Select]@echo off

set computer=s302-s


for /l %%x in (1,1,9) do (
net use \\%computer%0%%x "password" /user:"%computer%0%%x\admin"
md z:\form1\%computer%0%%x
xcopy "\\%computer%0%%x\d$\temp\*.*" "z:\form1\%computer%0%%x\"
)

for /l %%x in (10,1,44) do (
net use \\%computer%%%x "password" /user:"%computer%%%x\admin"
md z:\form1\%computer%%%x
xcopy "\\%computer%%%x\d$\temp\*.*" "z:\form1\%computer%%%x\"
)

echo Finished !

6234.

Solve : MAC address??

Answer»

Is there a DOS code sow you can see your MAC adress?
Or maybe I should create a batchfile.
I've TRIED to find it in Vista but I didn't mantion to find it.

Thanks in advance

JonasTry the COMMAND prompt. Start/run/command then ipconfig /allThanks I had tried ipconfig but I didn't know there were more possibilities with ipconfig.
Now I've tried ipconfig /?.
Now I know them all.
Thanks again for helping me out."getmac" works just fine

6235.

Solve : FOR question (related to folder creation)?

Answer»

Whenever I run this I can see it copying the log files but it then creates a file named new folder instead of a folder. How to I modify this to CREATE the destination folder for me? Or do I have to create the destination folder before I run this?

Also, can you tell me why the second variable %%G has to be in quotes in order for this to work?

Thanks,

CODE: [Select]@FOR /R "C:\Program Files\" %%G IN (*.log) DO COPY /y "%%G" "C:\Documents and Settings\Comp\Desktop\New Folder"
Quote

can you tell me why the second variable %%G has to be in quotes in order for this to work?

The quotes ACCOUNT for any embedded special characters and/or spaces in the path/file names.

If all the files are bring copied to the same destination, use MD to create a directory prior to the FOR.

Your logic doesn't show it, but if you needed multiple destination DIRECTORIES, you'd need to create directories within the FOR loop

Good LUCK. Ok, thanks for explaining that. Didn't even cross my mind to use md to create the dir.
6236.

Solve : Pb with Findstr and applying filters on extention file?

Answer»

hello everybody,

i ll try to explain my problem in english, but i m french...so....
well,

i m trying to make a little batch to check extention file and once i got this information i have to check in each of files with the specific extention if there a string called " debut" or "FIN"
but i don't know how to reach my aim.

i ALREADY got this part:

Code: [Select]
if "%1%"=="" echo you have to WRITE wich extention you have to check.Like test.bat 117 && goto er_stx

if not "%1%"=="" goto vf_file

:vf_file
del out.txt
echo extention file to check is %1%
dir /B *.%1% > out.txt
echo Following Process will be checked:
FOR /F %%i in (out.txt) do @echo %%i

REM this following command doesn't WORKS but i don't know how to setup the findstr options.

REM FOR /F %%i in (out.txt) do findstr /f out.txt /c:"Debut" >> procs_ok.csv REM or .xls

goto fin

:fin
echo Batch file is ending.
pause
exit

:er_stx
echo Batch is ending due to a syntax error
exit


and once this thing is done i have to complete an .xls file with the repport file " procs_ok.csv

i ve tried to be as clear as possible,
sorry if my english is not so good than i think !!!!

so if anyone have a idea, i m listening !!!

thanx,

regards.
you can just use findstr like this
Code: [Select]c:\> findstr "yoursearchstring" *.txt
c:\> findstr "yourstring" *.dat
hi,
i've try what you said but it still doesn't work i i don't know why...
i've also try
this
Code: [Select]findstr /F:out.txt /I ^".*" >> prcs_ok.txt
and it print the files of the file out.txt containing characters in the cmd prompt but it's not sent in the procs_ok.txt,

i have another idea to apply filter,
i've seen that some process repport files had sometimes twice the same word in it,so i would like to apply a filter on the first word of the last line.
but apparently i'm not friendly with the findstr cmd....
so if anyone have an idea....i'm still open !!

thanx,

Regards.

6237.

Solve : need Help "Copy"?

Answer» NEED help, i want to COPY all the D: DRIVE .txt files to C:\folder\

how to WRITE in cmd.exe?

Hope can help you.

Code: [Select]XCOPY "d:\*.txt" "c:\folder\"
6238.

Solve : "Find" does not work?

Answer»

Hello I am programming a batch file for windows XP. The programma has to copy and UNZIP a file if the zip file on the netwerk (F:) is newer then the file on the computer (C:). This is what I have untill now, the function FC RETURNS if the files are the same "FC: geen verschillen gevonden". And with the Find function i try to find that. But i think the find function doesn't work. What is needed to get it working? Or is there a other way, to do this?

Greetz Champy

---

@ECHO OFF
IF NOT EXIST f: goto stop

FC "F:\data\Besturing\Standaard\Capway S7 libary\capway.zip" "C:\Program Files\Siemens\Step7\S7LIBS\capway.zip"

find "FC: geen verschillen gevonden"

if errorlevel 0 goto stop

xcopy /d "F:\data\Besturing\Standaard\Capway S7 libary\capway.zip" "C:\Program Files\Siemens\Step7\S7LIBS"

unzip -o "C:\Program Files\Siemens\Step7\S7LIBS\capway.zip" -d "C:\Program Files\Siemens\Step7\S7LIBS"

regedit /s "C:\Program Files\Siemens\Step7\S7LIBS\capway\s7comm.reg"

:stop

exit

----You don't need a Find command. The errorlevel will indicate whether the files are equal or not.

Code: [Select]@ECHO OFF
IF NOT EXIST f: goto stop

FC "F:\data\Besturing\Standaard\Capway S7 libary\capway.zip" "C:\Program Files\Siemens\Step7\S7LIBS\capway.zip"
if errorlevel 1 goto next
goto stop

:next
xcopy /d "F:\data\Besturing\Standaard\Capway S7 libary\capway.zip" "C:\Program Files\Siemens\Step7\S7LIBS"
unzip -o "C:\Program Files\Siemens\Step7\S7LIBS\capway.zip" -d "C:\Program Files\Siemens\Step7\S7LIBS"
regedit /s "C:\Program Files\Siemens\Step7\S7LIBS\capway\s7comm.reg"

:stop

exit

Not sure what your logic is, but as WRITTEN, if and only if the files from the compare are unequal are the xcopy, unzip, and regedit commands executed.

Good luck. Thanks,

I didn't know that, and it wasn't simple to find some examples of the FC command.

The logic:

There is a library for a programm on the network, wich is updated by only 1 PERSON. The other 8 users have to download it wenn it is updated. So the file only needs to be copied, UNZIPPED and registered if the file on the netwerk is different to the file on the computer. It can happen that the file is not updated for several months, then it isn't neccisarily that it copy's and unzips at startup.

6239.

Solve : Delete some directories question?

Answer»

I use deltree this command to delete some directories in other computer's DOCUMENTS and SETTINGS

such as user directory. their name like these

s20041337, s20051426, s20051605 ...

But TWO FOR LOOP can't work in here. Someone can help me, Please.

Code: [Select]@echo on

set admin=admin
set PASSWD=passwd
set computer=s302-s
set link=s200

for /l %%x in (10,1,44) do (
net use \\%computer%%%x "%passwd%" /user:"%computer%%%x\%admin%"
for /l %%y in (10001,1,61622) do (RD "\\%computer%%%x\c$\Documents and Settings\%link%%%y" /s /q )
net use \\%computer%%%x /delete
)

6240.

Solve : Creating List file from a directory and comparing it with another list?

Answer»

I have not USED Batch process to a very extensive way and Now I have few requirement to do so.Please help me to figure out the code.

Below is what Iam trying to do :

Step1 : From a alltel FTP SITE I need to MOVE all the files in one directory called ManualImport to the local server which is \\server1\source and create a list file called maplist.txt which will have all the files in the Directory.
Code :
@echo off
cd \\server1\source
dir \\server1\source /b /a-d > maplist.txt

Step2 : In the local folder \\sever1\source there is already a list file called orignal_import_list.txt which has a list of files.Now COMPARE the orignal_import_list.txt with the maplist.txt and

Step3: If orignal_import_list.txt doesn't have any files in the maplist.txt then we need to remove it from orignal_import_list.txt

Please help me with this


I hope this should be easily possible :

Step1 : In the local folder \\sever1\source there is already a list file called orignal_import_list.txt which has a list of files names in it.Now compare the orignal_import_list.txt with the files in the folder \\sever2\source and
Step3: If orignal_import_list.txt doesn't have any files names in the \\sever2\source then we need to remove it from orignal_import_list.txt

Please help me with thisAny LUCK...

6241.

Solve : Problems with braces in batch files?

Answer»

Hi all,

I'm having a hard time with some () in a batch file. The problem is the following:

"test.bat" looks like this:

------------------------------------------------------------------------------------
@ECHO off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

call test2.bat "C:\Temp\Batch Test (bat)\test\test.txt"
------------------------------------------------------------------------------------

all it does is calling test2.bat which does the following:

------------------------------------------------------------------------------------
@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

set arg=%~1

if "!arg:~0,1!" == "/" (
echo ##### passed argument starts with a "/"
) else if "!arg:~-1!" == "\" (
echo ##### arg ends with a "\"
) else if exist "%~1" (
set ext=%~x1
if /i "!ext!" == ".txt" (
echo ##### is a text file
) else (
pushd %~dp1
dir
popd
)
) else (
echo ##### ERROR: %~1 not supported
)
------------------------------------------------------------------------------------


when I execute test.bat i get the following error: "\test\ was unexpected at this time."

So far the problem seems to be first if statement ( if "!arg:~0,1!" == "/" ( ).

In order to fix this I tried to remove the braces as soon as test2.bat gets the argument

set arg=!arg:^(=!
set arg=!arg:^)=!
set arg=!arg: =!

Unfortunately this does not help at all.

What am I doing WRONG? How can I make this work? Unfortunately the argument is GIVEN so I have to change the code, not the argument.

Thanks a lot

ACKH

Searching alt.msdos.batch.nt suggests failure to handle parentheses in file & folder names correctly is a BUG in NT command interpreter.

These: () are "parentheses"
these: [] are "BRACKETS"
these: {} are "braces"


Alright, thanks for your answer and for the technical terms. Seems that I have to find another way to get this done.

Regards,

ACKHUntil yesterday I thought they were braces also! It seems that a folder name that contains parentheses is a bad idea for batch processing and leads to much confusion. You say that renaming the folder is not an option?

I also had a problem running a batch script that had any kind of parentheses it is.
Have you tried using the DOS version of the folder?
DIR /X will give you the simple version to try.Thanks for your answers. It seems to me that parentheses are a problem whenever delayed environment variable expansion is used. Whenever I use it (for example "set TEST=!TEST! %%w" in a for loop) problems occur. What I did now was rewrite the script without delayed expansion which finally works.

Thanks and regards,

ACKHAppendix:
Whenever I call a batch file that has parentheses in its full file name (e.g. call "c:\test\hello (test)\example.bat") with arguments (e.g. call "c:\test\hello (test)\example.bat" /test D:\test) from another batch file i run into problems. This really seems to be a bug (as mentioned above).

6242.

Solve : DOS programs won't work under Windows XP?

Answer»

Excellent !

Seperate hardware configuratioins however are a well kept XP secret for testing new configs and not having your main setup FUBARED...Quote

Excellent !

Seperate hardware configuratioins however are a well kept XP secret for testing new configs and not having your main setup FUBARED...

That word makes me laughu know my problem is a bit different ,i have had problem SINCE the very first TIME i RAN pascal in command prompt and it doesn't work in fullscreen mode
any ideas?
im running windows xp sp2 and my cpu is intelHow about a new THREAD for your UNIQUE issues?
6243.

Solve : Accept File Name To Delete From User in DOS?

Answer»

Hi Everybody,

I am basically trying to DELETE files by accepting user input ie. Name of the FILE to be deleted and then delete that file.

Can someone guide me as to how this MIGHT be accomplished IN DOS?

I am on WIN XP . and will write a bacth file to do this.

Regards,

Jhedstry this
set /p filename=Name of file to delete:
del %filename%

you may need to change to the relevant directory first
Graham

6244.

Solve : Unzip using Batch Command?

Answer»

Hi Friends,

I am searching for a batch file command to unzip one ZIP file and to store the same in a specified location. I was able to find the batch command to extract one zip file, by opening the winzip file using batch command. But I was not able to save the same in a specified location. Anyone please help me.This is what you want
winzip32 -e [options] filename[.zip] folder

To place the contents of the zip into a different location.

I have pasted the winzip commandline info below
Graham



WinZip
Below is some information about the undocumented command line options for using the WinZip program module, winzip32.exe.
WinZip SUPPORTS command line options to add and extract from files. Be sure to read the Notes section below for additional important information.
Adding Files
The command format is:
winzip32 [-min] action [options] filename[.zip] files

where:
-min specifies that WinZip should run minimized. If -min is specified, it must be the first command line parameter.
action
-a for add, -f for freshen, -u for update, and -m for move. You must specify one (and only one) of these actions. The actions correspond to the actions described in the section titled "Add dialog box options" in the online manual.
options
-r corresponds to the Include subfolders checkbox in the Add dialog and causes WinZip to add files from subfolders. Folder information is stored for files added from subfolders. If you add -p, WinZip will store folder information for all files added, not just for files from subfolders; the folder information will begin with the folder specified on the command line.
-ex, -en, -ef, -es, and -e0 determine the compression method: EXTRA, Normal, Fast, Super fast, and no compression. The default is "Normal". -hs includes hidden and system files. USE -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password".
filename.zip
Specifies the name of the Zip file involved. Be sure to use the full filename (including the folder).
files
Is a list of one or more files, or the @ character followed by the filename containing a list of files to add, one filename per line. Wildcards (e.g. *.bak) are allowed.
Extracting Files
The command format is:
winzip32 -e [options] filename[.zip] folder

where -e is required.
options
-o and -j stand for "Overwrite existing files without prompting" and "Junk pathnames", respectively. Unless -j is specified, folder information is used. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password".


filename.zip
Specifies the name of the Zip file involved. Be sure to specify the full filename (including the folder).
folder
Is the name of the folder to which the files are extracted. If the folder does not exist it is created.
Notes
• VERY IMPORTANT: always specify complete filenames, including the full folder name and drive letter, for all file IDs.
• To run WinZip in a minimized inactive icon use the "-min" option. When specified this option must be the first option.
• Only operations involving the built-in zip and unzip are supported.
• Enclose long filenames in quotes.
• When using a list ("@") file, no leading or trailing spaces should appear in file IDs in the list.
• The action and each option must be SEPARATED by at least one space.
• WinZip can be used to compress files with cc:Mail . Change the compress= line in the [cc:Mail] section of the appropriate WMAIL.INI files to specify the full path for WinZip followed by "-a %1 @%2". For example, if WinZip is installed in your c:\winzip folder, specify
compress=c:\winzip\winzip.exe -a %1 @%2

6245.

Solve : net send in a batch file??

Answer»

Hey all!

I am trying to make a batch file with a net send command in it, to make a little fun with my brother and friends.
But i have no idea on how to make the dos prompt write the line.

This is what i had in mind for them
"START cmd.exe
for /L %i IN (1,1,999) DO net send * YOU JUST GOT OWNED!"

Thank you for you help!set CMDLINE=%*
brings what you type in dos prompt in the var "cmdline"

hope it helps
uliDepending on what OS you are using, you shouldn't even have to start cmd.exe. Just try...
Code: [SELECT]net send computerNameorUser "message"where computerNameorUser is EITHER the COMPUTER name or the user of that computer.

Maybe that is what you are looking for.Thank you Uli, that is exactly what i needed
i cant get it to work tho, can you tell me what to excact write in the .bat file to make it work? (sorry IM a NOOB at this )Not hijacking, adding to:

How can you input a variable into the message?
like ask the user a question, set it as a variable, and set it and some other prewritten text into the message?Hey HDL_CinC_Dragon, you should start a new thread that way, you do not get confused and we do not get confused.HDL_CinC_Dragon,

Environment variables are always resolved in the shell program:

Code: [Select]set /p name=Enter your name:
echo %name% is a member of CH

Xsix,

Open up notepad, enter the line:

Code: [Select]for /L %i IN (1,1,999) DO net send * "YOU JUST GOT OWNED!"

Save your file with a bat extension, and either run from the command prompt or find your file in Windows Explorer and double click.

It's bad enough we have to worry about viruses, trojans and other crap, now we have to watch out from our own relatives. :-?Quote

Hey HDL_CinC_Dragon, you should start a new thread that way, you do not get confused and we do not get confused.

Sorry. Next time ill just start a new topic.

Quote
HDL_CinC_Dragon,

Environment variables are always resolved in the shell program:

Code: [Select]set /p name=Enter your name:
echo %name% is a member of CH

Thanks Quote
Xsix,

Open up notepad, enter the line:

Code: [Select]for /L %i IN (1,1,999) DO net send * "YOU JUST GOT OWNED!"

Save your file with a bat extension, and either run from the command prompt or find your file in Windows Explorer and double click.

It's bad enough we have to worry about viruses, trojans and other crap, now we have to watch out from our own relatives. :-?

Dident work? Can it run in windows xp? i tryed both methods you suggested;
Double Click: Opens up the windows and closes down so fast i almost cant even see it.
Run from the cmd: It displays the line in the cmd, but it dosent run it/use it. :/My error From a batch file, you need double percent symbols:

for /L %%i IN (1,1,999) DO net send * "YOU JUST GOT OWNED!"

To run from the command prompt, use single percent symbols:

for /L %i IN (1,1,999) DO net send * "YOU JUST GOT OWNED!"

8-)

Next time please try for something constructive.working
Thank you very much Sidewinder rofl i just tested Code: [Select]for /L %%i IN (1,1,999) DO net send * "Testing" on my home computer and it sent the message "Testing" to every computer i dont even know how many times... but I can tell you it sent 15m/s (messages per second) for a pretty interesting amount of time lol. Luckily only mine and my moms computer were online now i gotta close em all.... one at a time... :sigh:
6246.

Solve : Batch to Trigger Modem to Dial Cell Phone?

Answer» WORKING on a batch that runs in a loop to test systems, then trigger a modem event to call my cell phone, then hang up after 10 seconds.... Any suggestions on how to get my 56k PCI US Robotics Modem to dial thru a batch or a free or inexpensive program that can be added to my batch to launch and prank me when there is a failure to be notified about.

My plan is to share a fax line with a system monitoring other servers and systems, and when a fault is detected, dial my cell phone. For the fact that I know that no one would ever call me from the fax number, and my cell phone has caller id... it would work perfect to alert me to remote in asap to see whats gone wrong from anywhere that has a cell signal.

I was thinking of using a really old copy of Kermit, but it doesnt have the ability to dial and hang up after 10 seconds.

Thanks... DaveFound a solution...Figured I would share it in case anyone else wants to do something like this. Here is what I have done.

1.) Took a Pentium II system running Windows 2000 Pro and it has a 56k modem installed.
2.) Created a Dial-Up configuration for what would normally be used for dialing into an ISP, but instead replaced the ISP DUN number with my cell phone number.
3.) Used a Macro RECORDER called JitBit Macro Recorder ( http://www.jitbit.com/macrorecorder.aspx ) that I purchased to record the process of what normally would be to dial up to an ISP DUN service, but its calling out to my cell phone. I then wait about 10 seconds and tell the computer that I want to cancel the call to my cell phone. I then compiled this macro into an EXE, which can be executed anytime on this system ( from within a batch ).
4.) Added a line branching off a goto statement in my batch to execute CallMe.EXE ( JitBit Macro )
5.) Saved Batch and started batch that runs in a loop.


This Pentium II system is then able to monitor servers and if a failure CONDITION is met, it triggers execution of the CallMe.exe custom ( mouse/Keyboard event macro ) and I get the phone call...

No more getting calls from end users hours after a failure. Now I get it within minutes, and can respond quickly to resolve the problems before the users start to see the problems.

Thanks for looking this post over and CONSIDERING ideas.... Dave

6247.

Solve : how to write bat file incl many commands??

Answer»

I have such commands in ORDER to test the printer under DOS.
I want to write a bat file ,so that i need not to enter so many commands.
I simply divided them into 3 groups.
1&2 group is the pre-setting.3rd group is to activate printer.

I want to MAKE a bat file that:
1.setup (the command line appeare that let user see, then the SENTENCE 9600bps set completed)
2.beep buzzer
3.print

I have a autpexe.bat file
i put the command call this.bat

How to write this,may i have a starting/sample code?


#1.) Setup baud rate to 9600bps and etc
-----------------------------------------
-o 3fb 83 >hit enter
-o 3f8 0c >enter
-o 3fb 03 >enter


#2.) Send command1 to printer:
-----------------------------
-o 3f8 1e >enter ( beep the buzzer)


#3.) Send command2 to printer:
-----------------------------
-o 3f8 1b >enter
-o 3f8 3F >enter
-o 3f8 0a >enter
-o 3f8 00 >enter (RESET printer hardware and then self print)Sry,forgot to state.I have a program call debug to execute.

Can i write these inside my printer.bat? Just a try

debug /o 3fb 83
/o 3f8 0c
/o 3fb 03

echo.
echo.
echo.
echo. 9600bps baud rate set completed
echo.
echo.
pause
try this for the setup section

:: create the debug file
> setup.dbg echo o 3fb 83
>> setup.dbg echo o 3f8 0c
>> setup.dbg echo o 3fb 03
>> setup.dbg echo q
:: execute it
debug < setup.dbg

echo.
echo.
echo.
echo. 9600bps baud rate set completed
echo.
echo.
pause


and do the same thing for the other sections

Graham


bad command or line.
I try under DOS.
Is there a code that allow us to create.
so that user need not to hit enter and type so many command line?
that is what i wonder.

6248.

Solve : Batch to read from file?

Answer»

On another project I am working on, I am looking for a way to READ a ascii text file say Token.TXT and pass that ascii data read in ENTIRETY until EOF to a VARIABLE to be tested.

The Token.TXT file would have either PASS or FAILURE in it, and I need my batch to read the ASCII and pass it to a variable, then an IF statement and ELSE statement. So if the ASCII equals FAILURE then trigger the Failure event, otherwise anything else read in, which would only be PASS would go back to Passed at the beginning of the batch and run in a loop.

Such as:

(*** Somehow pass the read in ascii from Token.TXT to variable VARIABLE ) "Dont know how to do this"

REM Then perform the following test of the ASCII and goto Failure or Passed

IF VARIABLE = "FAILURE" {
goto Failure
}

ELSE {
goto Passed
}

Going to use this for testing services. The services condition causes a PASS or FAILURE Token.TXT file to be written to a folder. The batch that I am WRITING will once a minute run a loop to test the ASCII text in the Token.TXT file.

Thanks for your help in advance!!!

Dave

Not sure which of your machines you're planning on using this:

Code: [Select]@echo off
for /f "tokens=1-2*" %%i in (token.txt) do (
if %%i==PASS (goto pass) else (goto FAIL)
)

You could also use find or findstr, using the errorlevel to determine which logic to execute.

Code: [Select]find /i "pass" token.txt
if errorlevel 1 goto fail
if errorlevel 0 goto pass

As your requirements become more complex, you'll find that batch code lacks the functionality you need. 8-)

Thanks again Sidewinder [smiley=thumbsup.gif] that works.

I was thinking it was going to be more complex with having to define to read to EOF. And have to pass a string value to a variable then compare. But this works very well. You are definately a master of batch programming.

Thanks for your help!!!

6249.

Solve : Couple little questions?

Answer»

I searched using the search box and USED several different words to try and find each subject but had no luck.

My first question:
What is the command to get the profile name that you are logged in as on that computer?

My second question:
Is there a way to scan your LAN for computer names that are connected to your LAN?

My third question:
Is it possible to generate a random integer in a batch file?

My fourth question:
How can I group different arguments in an If statement? I know in Java its || LIKE this: Code: [Select]If (number == 1 || number == 5 || number == 10) where "||" means "or"1 It is in the var %userprofile% .
2. net view (might work)
4. If "%number%" == "1" (
If "%number%" == "5" (
If "%number%" == "10" (
echo do something...
goto :eof
)
)
)

group it like this should work.

hope it helps
uli3] Use this pseudo system variable :
%RANDOM% - expands to a random decimal number between 0 and 32767

4] uli -- your structure will only work if %number% is 1 and 5 and 10. This should cope with OR

:: If number == 1 || number == 5 || number == 10
If "%number%" == "1" GoTo GotIt
If "%number%" == "5" GoTo GotIt
If "%number%" == "10" GoTo GotIt
:: Else
GoTo NotIt
:: EndIf
:GotIt
echo do something...
GoTo :eof
:NotIt
GoTo :eof


GrahamOh, sorry. Thanks for correcting my mistake.

uliQuote

1 It is in the var %userprofile% .
2. net view (might work)
4. If "%number%" == "1" (
If "%number%" == "5" (
If "%number%" == "10" (
echo do something...
goto :eof
)
)
)

group it like this should work.

hope it helps
uli

1) %userProfile% works except it shows the whole path name (C:\Docs...\username). Is there a way to have it only say the username?
2) net view works nicely. thanks

Quote
3] Use this pseudo system variable :
%RANDOM% - expands to a random decimal number between 0 and 32767

4] uli -- your structure will only work if %number% is 1 and 5 and 10. This should cope with OR

:: If number == 1 || number == 5 || number == 10
If "%number%" == "1" GoTo GotIt
If "%number%" == "5" GoTo GotIt
If "%number%" == "10" GoTo GotIt
:: Else
GoTo NotIt
:: EndIf
:GotIt
echo do something...
GoTo :eof
:NotIt
GoTo :eof


Graham
3) thanks, is there a way to limit to be between 2 CERTAIN numbers? like maybe 50 and 100? or maybe 0 and 100? or something of that nature?
4) is there an actual Else statement in batch programming? so that if the arguments in the previous if statements are false it just does whatever is under the else statement?


sorry for being so needy guys....this WEBSITE might be helpful:
http://www.ss64.com/nt/

1. %username%

type set to see the defined variables.

3 & 4 is explained here:

http://www.ss64.com/nt/if.html

hope it helps
uli


Thanks Uli, the username thing is exactly what I was looking for


the Else statement thing appears to only work if you download the resource kit
and theres nothing about %Random% on the siteHeres another one, now this one may sound a bit silly but:

How do you add an integer variable and an integer together? I cant seem to work it out... maybe im setting my variable wrong in the first place?
Code: [Select]set Dollars=0is there some sort of prefix I need to include?
6250.

Solve : Replace text string in file?

Answer»

Okay so my goal is to edit two particular lines in an INI file. The cmd file will be ran on xp clients. The line in QUESTION will be replaced w/ the %userprofile% var. Just doing some searching on google I've found a way to replace one line successfully, but I'm stuck on replacing two. Here is the code I'm using for just the one line:


for /f "delims=" %%a in (%temp%\appsrv.ini) do (
call :PROCESS "%%a"
)

goto :EOF
:PROCESS
set LINE=%~1
if /i "%LINE%"=="LogFileWin32=c:\documents and settings\\Application Data\ICAClient\wfcwin32.log" set LINE=LogFileWin32=%userprofile%\Application Data\ICAClient\wfcwin32.log
echo %LINE%>>"%userprofile%\application data\ICAClient\APPSRV.INI"
:EOf

This works perfectly, but for the life of me I cannot figure out how to make it replace a second line within the same ini file. Any help you fine people could offer would be appricated. If it would be easier simply mathing a string (eg "c:\docs & settings\user") to replace rather than the exact line of text (as it is now) is fine by me tooConsidering that any given line can either meet one condition or another condition or neither, can you not simply add another if condition:

Code: [Select]for /f "delims=" %%a in (%temp%\appsrv.ini) do (
call :PROCESS "%%a"
)

goto :EOF
:PROCESS
set LINE=%~1
if /i "%LINE%"=="LogFileWin32=%userprofile%\Application Data\ICAClient\wfcwin32.log" (
set LINE=LogFileWin32=%userprofile%\Application Data\ICAClient\wfcwin32.log
echo %LINE%>>"%userprofile%\application data\ICAClient\APPSRV.INI"
)
if specifications for second condition (

)

Hope this HELPS 8-)Your code didn't quite work as expected (maybe I just used it WRONG, I'm not the greatest at this SORT of thing) but it did give me enough ideas to go on. Here's what I ended up using, in my testing it seems to work perfectly. Thanks for all your help!


Code: [Select]for /f "delims=" %%a in (%temp%\appsrv.ini) do (
call :PROCESS "%%a"
)
goto :EOF
:PROCESS
set LINE=%~1
if /i "%LINE%"=="LogFileWin32=C:\Documents and Settings\<edit>\Application Data\ICAClient\wfcwin32.log" set LINE=LogFileWin32=%userprofile%\Application Data\ICAClient\wfcwin32.log
if /i "%LINE%"=="PersistentCachePath=C:\Documents and Settings\<edit>\Application Data\ICAClient\Cache" set LINE=PersistentCachePath=%userprofile%\Application Data\ICAClient\Cache
echo %LINE%>>"%userprofile%\application data\ICAClient\APPSRV.INI"
:EOF