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.

1551.

Solve : Need help with 2 batch files?

Answer» OK, I need to make 2 batch FILES in DOS, and I'm not really handy with DOS, so if you could help me out...

The first one: A batch who merges the content of 2 .txt files, into a new .txt file, and then saves it into a specific  directory (if the directory already exists, the batch stops), and then it sorts the content of the new file (A-Z), and then it saves that into a new .txt. And the file paths have to be entered when you open the batch.

The second: A batch who merges the content of all specified .txt files into a new .txt file, and saves it to a specific directory (if it already exits, stop). The file paths have to be entered when you open the batch.

It's COMPLICATED (I think), tnx

i think you should lern somethink about COPY SET (SORT?) and IF commandif you have some UNIX tools installed, 'sed' and 'cut' would do nicely here.

1552.

Solve : Rename files with Date and then copy them in batch file?

Answer»

Hi i have a Batch FILE that does not work . Its meant to RENAME the files to the current date and then copy them to an archive folder

Its not renameing them to the current date


echo off

cd "E:\Projects\Extract Files\ROI\"

Set FileDate=%date:/=%

ren  dicbcon.in dicbcon%Filedate_%.in
ren  dicbdet.in dicbdet%Filedate_%.in
ren  dicbtot.in dicbtot%Filedate_%.in

copy *.in "E:\Projects\Extract Files\ROI\Archive"


Endecho off
for /f "skip=1 tokens=2-4 DELIMS=(-)" %%a in ('echo.^|date') do (
 set A=%%a&set B=%%b&set C=%%c)
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
 for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
  set mm=%%d&set dd=%%e&set yy=%%f))
   set DATE1=%dd%-%mm%-%yy%
   set date2=%yy%%mm%%dd%

i think its help full

put becarful for the date format on the system u USE
for eg
Thu 03/27/2008
or 03/27/2008
u should fix the code or the date format u got

1553.

Solve : From Bad To Worse?

Answer»

I have an old PC (PII, 500), originally had 98 on it, but wanted to network with my other PCs in the house, so I recently loaded 2000 Windows and Office.  All was fine (as a standalone, not networked) until I loaded McAfee Suite on it and all of the sudden started getting fatal errors anytime I went into I-Explore.  I unloaded the McAffee and it improved some but still got intermittent IExplore errors.  No errors when offline but after varying amounts of time on-line, I will eventually get an error and it either closes Explorer or reboots completely.  Out of desperation, I tried installing XP today and all sorts of new trouble started.  XP INSTALL failed due to numerous "Can't find such-and-such...."errors and now is locked in a continuous loop of "Can't find Command.com" and FORCES reboot.  Nothing I have been able to do with my old 2K Restore disk or XP Install disk gets me past this.  I am willing to reformat the HD and completely start over but can't get to a DOS command.  Any thoughts as to how to get passed it's desire to finish the aborted XP Install?  Is there a bootable disk I can download on-line (using another PC) that will allow me to reformat everything and start fresh?  Any help would be appreciated.  BTW - the PC is a no-name and I have no documentation for it.  Thanks...JHBoth the Win2K and the XPCD's should be bootable...make sure to enable the CDRom as the first BOOT device.
Then in setup you should have the option to delete any existing partitions and re-create them and do a clean install...Thanks - but done that.  It only comes up as far as telling me it cannot find Command.com, regardless of which device I have forced it to look at.  I have even tried forcing it to my floppy, using an older restore disk for 98 - just to see if it does anything different, it reads it but then errors out saying it can't find the required file.  The only screen it consistently comes to is something to the effect that it failed install, can't find the necessary file, install orignal disk and press "r" to repair.  I put in the XP disk press "r" (or anything else) and it reboots and comes right back to that same screen - endless loop and no apparent way around it.  I have shut down my HD's to ensure it forces a read off the CDROM and/ or floppy, but same result.

I am getting a LITTLE foggy on some of the screens so if thee is something spcific to try, I can certianly give it a go.  Thanks again.  p.s. - would buying a new HD and starting from scratch get around this?Well, I  might have been a bit premature.  I was able to get the Win2K disk to read and got into the repair option.  I am CHOOSING to reformat the HD and will start over - hopefully whatever it was that got introduced with the McAffee suite will be wiped out and I can get back to where I started - just a lot of time to go through getting all the updates again.  Thanks for the help and if things don't go as planned, I'll probably ask a few more ??No problem ...let us know how it goes...
For a full Protection strategy here is mine:

AVG Free
Spybot Search and Destroy
AdAware
AVG Anti-Spyware
Stinger
CCleaner

All of the above are FREE and will not bog down the system as some of the "Protection" Suites will.

Many here also recommend Comodo for a free firewall program to round out the package.

Good Luck and Welcome to CH !

1554.

Solve : Inputting username and password on one line?

Answer»

hi,

I want to be able to input the username and password within dos on one LINE. Basically, whenver i am in dos, and i am prompted for a password, i don't have to type the password on a seperate line.

For example, instead of:

Code: [Select]C:\> 'runas /user:home\yazooney explorer.exe'
Enter the password for home\yazooney: 'PASSWORD'
I want to be able to do:
Code: [Select]C:\> 'runas /user:home\yazooney explorer.exe & PASSWORD'
However, using the & FUNCTION for doing mulitple commands on one line does not work.

Anyone know a way of solving this problem?the 'run as' command won't let you automate the password.

You will HAVE to enter it manually. (it's a security thing....)


you could use pstools, that will allow the password to be entered on the same line.


hope it helps.

** my 2 cents **Thanks for the reply. Currently having a look at this pstools thing. As you can imagine, i not that MUCH clued up.

Any chance you can give me an example of how this would work?sure;

in a dos prompt navigate to the pstools folder and run;

"start psexec C:\path\to\program -u username - password"

it's mainly used for running apps on remote machines but I see no reason why it won't run locally.

You might have to put in \\%localhost% between the psexec and the path to program bit.

I would have thought you could echo the password but just PIPE it into the runas command, like this:

Code: [Select]echo PASSWORD | runas /user:admin cmd.exe
I didn't try it but it should work, I think...

1555.

Solve : Merge files (computer XP)?

Answer»

Hey peoples, I have a windows XP computer and I have a request to make.
My problem is that I want to make a batch file program that merges 2 files together and when u change the.(something) to .(something else) it will still compute. So i have a pic and i merge it with a zip file and then the join. The pic does show up as a pic when you double click on it and when you change the type of file it works as a zip and SHOWS you what is in the zip file.

If any body out there could help it WOULD be much appreciated.

Regards,
Tan_ZaIs this so you can hide stuff?Sort off. It would be interesting to have 2 files on one. So when you change the .(something) to .(something else) it would be like a hidden type thing, yes and maybe.

Thanks anyways,
Tan_ZaWhat you want will require more than changing the extensions.  Most file types (including the 2 that you mention in your post) have file headers or signatures that tell programs what type and version they are.  A picture will most likely be a JFIF COMPLIANT JPEG file which will have a signature of "FF D8 FF E0" (hex in the first 4 bytes of the file).  A ZIP file will have a signature of "50 4B 03 04".  So if you merge the files, whatever file is first may open properly, but the second file will not because the header won't match, and the program won't know where to go to look for the right part of the file.

There are few (if any) legitimate reasons for hiding one file inside of another file, so you probably won't find how to do what you are looking for on this forum.  If you need security, just USE a legitimate encryption program. Quote from: GuruGary on March 29, 2008, 12:34:34 AM

There are few (if any) legitimate reasons for hiding one file inside of another file

 Well I don't think so there is away. Maybe if you know a alot about dos then you can give me an answer. The files that I would be doing this with would be a .jpg and a .zip. If you could post code it would be much appreciated.

Regards,
Tan_Za
1556.

Solve : Fixed Length and Variable Lengthing a file??

Answer»

Hopefully someone can help

I had a program that no longer works (unfortunately I do not have the SOURCE), it was passed on to me my someone 5 years ago.

The program can do the following:

1) Make a file Fixed Length if I pass it a size option. As in I have a log file and I want to pad it to 132 characters to be able to read it into an application.

2) Make a file variable length. I generate a script file from an application that I want to be STRIPPED of all trailing spaces before I SUBMIT it.

Anyone got any ideas for this? I would really LOVE to make this out of basic DOS script.

I really do NOT want a VB script or anything else that requires a compiler. I have these written for a UNIX platform and until now I thought I had a something to work on Windows....but Since I upgraded to x64, it no longer works. I have tried using the windows AWK tool, but there isn't a lot of samples out there to make it work in windows.

Ken

1557.

Solve : DIR - DiscLetter?

Answer»

how can do for loop which will do sth like this:
Code: [Select]echo.>DIR.txt
echo.---------------------------------------------------------------------- >>DIR.txt
echo.                               "A" DRIVE >>DIR.txt
echo.---------------------------------------------------------------------- >>DIR.txt
echo. >>DIR.txt
echo.--- RAR --- >>DIR.txt
dir A:\*.rar /s /b >>DIR.txt
echo.--- LOG --- >>DIR.txt
dir A:\*.log /s /b >>DIR.txt
echo.--- TXT --- >>DIR.txt
dir A:\*.txt /s /b >>DIR.txt
echo.--- BAT--- >>DIR.txt
dir A:\*.bat /s /b >>DIR.txt
echo.--- ZIP --->>DIR.txt
dir A:\*.zip /s /b >>DIR.txt
echo.--- DAT --->>DIR.txt
dir A:\*.dat /s /b >>DIR.txt
echo.--- VBS --- >>DIR.txt
dir A:\*.vbs /s /b >>DIR.txt
echo.--- PAK --- >>DIR.txt
dir A:\*.pak /s /b >>DIR.txtbut for all founded discs on computer ?
i have code which find selected drive but in this method i have file with 50000 letters so i want to do it with for loop but dunno how
Code: [Select]wmic volume get DriveLetter |findstr "A:"nice.

I fancied a LITTLE project for an hour or so...

here you go;

Code: [Select]echo off

set /a count=1

:loop

if /i %count% EQU 1 (set Letter=A)
if /i %count% EQU 2 (set Letter=B)
if /i %count% EQU 3 (set Letter=C)
if /i %count% EQU 4 (set Letter=D)
if /i %count% EQU 5 (set Letter=E)
if /i %count% EQU 6 (set Letter=F)
if /i %count% EQU 7 (set Letter=G)
if /i %count% EQU 8 (set Letter=H)
if /i %count% EQU 9 (set Letter=I)
if /i %count% EQU 10 (set Letter=J)
if /i %count% EQU 12 (set Letter=K)
if /i %count% EQU 13 (set Letter=L)
if /i %count% EQU 14 (set Letter=O)
if /i %count% EQU 15 (set Letter=M)
if /i %count% EQU 16 (set Letter=N)
if /i %count% EQU 17 (set Letter=P)
if /i %count% EQU 18 (set Letter=Q)
if /i %count% EQU 19 (set Letter=R)
if /i %count% EQU 20 (set Letter=S)
if /i %count% EQU 21 (set Letter=T)
if /i %count% EQU 22 (set Letter=U)
if /i %count% EQU 23 (set Letter=V)
if /i %count% EQU 24 (set Letter=X)
if /i %count% EQU 25 (set Letter=Y)
if /i %count% EQU 26 (set Letter=Z)


dir %Letter%: >nul

if /i %errorlevel% GTR 0 (echo.Unable to list %Letter%: Drive>>C:\ErrorLog.txt & goto next)

dir %Letter%: >c:\%Letter%Drive.txt


ping localhost -n 5 >nul




:next

set /a count +=1

if /i %count% EQU 27 (goto end)

goto loop






:end

cls
echo.End of Script.

pause>nul
exit
lol why i dont thinked about it ??  i tried to do harder work but anyway thanksglad i could help.

 This is where FOR is useful.

Code: [Select]echo off
echo.>DIR.txt
for %%L in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%L:\ (
echo.---------------------------------------------------------------------- >>DIR.txt
echo.                               "%%L" DRIVE >>DIR.txt
echo.---------------------------------------------------------------------- >>DIR.txt
echo. >>DIR.txt
echo.--- RAR --- >>DIR.txt
dir %%L:\*.rar /s /b >>DIR.txt
echo.--- LOG --- >>DIR.txt
dir %%L:\*.log /s /b >>DIR.txt
echo.--- TXT --- >>DIR.txt
dir %%L:\*.txt /s /b >>DIR.txt
echo.--- BAT--- >>DIR.txt
dir %%L:\*.bat /s /b >>DIR.txt
echo.--- ZIP --->>DIR.txt
dir %%L:\*.zip /s /b >>DIR.txt
echo.--- DAT --->>DIR.txt
dir %%L:\*.dat /s /b >>DIR.txt
echo.--- VBS --- >>DIR.txt
dir %%L:\*.vbs /s /b >>DIR.txt
echo.--- PAK --- >>DIR.txt
dir %%L:\*.pak /s /b >>DIR.txt
)
)
yup thanks Dias what is the /i switch?  Or is it even a switch? Quote from: qz33 on March 28, 2008, 01:57:28 PM

what is the /i switch?  Or is it even a switch?

if you type IF /? at the prompt you'll find out. STRICTLY speaking it was unecessary in the post above where you saw it.

1558.

Solve : Help deleting directory with out knowing name?

Answer»

There are some kids at my school who have installed games like halo and grand THEFT AUTO and other games on the school computers. I am in internship and have been put in charge of deleting the games from the school computers. I am wondering how I can get the directory name.

What I am doing so far is running a
Code: [Select]dir /b /s halo.exe >> location.txt

to find the location of the file. Once I find the location, I would like to be able to delete that entire folder.

Thanks for any HELP that is given,
Christry this. Use with care.

set filename=halo.exe
for /f "delims==" %%D in ('dir /s /b %filename%') do (
     ECHO %filename% found in folder %%~dpD
     echo Press a key to remove all programs in that folder
     echo and then delete it.
     echo.
     echo Hold down Ctrl  and press C to abort.
     echo.
     pause
     echo 
     echo deleting files in %%~dpD
     del %%~dpD\*.* && echo OK
     echo removing folder
     rd %%~dpD && echo OK
     )
 
     
thanks so much, I am going to see if that works today and post back.

Works quite well. One more thing. I was looking around and saw this
Code: [Select]for /f "tokens=1,2,3,4 delims=." %%a in (proxy.txt) do (
     ping %%a.%%b.%%c.%%d -n 3
     )
and was wondering how I could read a file using that.

Would I do something like this
Code: [Select]for /f "tokens=1 delims=." %%a in (games.txt) do (
     set filename=%%a

     for /f "delims==" %%D in ('dir /s /b %filename%') do (
        echo %filename% found in folder %%~dpD >> locations.txt
        echo deleting files in %%~dpD >> locations.txt
        echo removing folder >> locations.txt
        rmdir /s /q "%%~dpD" && echo OK >> locations.txt
     )
 )

Not sure if that is correct but it was worth a shot.sorry for the bump but I ended up editing my last post like 8 hours after I posted so I haven't gotten a reply. I tried to work on it my self, but it started to delete my desktop, even though I don't have a game there. and it wasn't out putting what I wanted it to.

I have changed my original idea and would like to do something like this.

nameoffile.exe:Searching for String

1559.

Solve : NET USE MAPPED DRIVES QUERY?

Answer»

Hi logon script to map drives and folders

net USE SAY P: // servername/folder/another/another

works FINE in xp

but in win 95 can only seem to get as far as say P:  //servername/folder

Can i get DEEPER in folders in win 95, do you see what i mean?

Error 50

Any help appreciatedFor Win9x you have to SHARE the deeper folder if that is what you want to map.

For example, on the server you could do
net share deeper=C:\folder\another\another
Then on the Win9x client, instead of
net use * \\servername\folder\another\another
use
net use * \\servername\deeper

1560.

Solve : run vbs from remote machine?

Answer»

on my servers i have created a vbs SCRIPT that will save the security log in a specific path with the date name.

when i try and run this remotely it saves the event log on the workstation i am working on, not the one on the server.  

is there a way of running a COMMAND so it runs on the remote system as if i was physically logged in and running it?

hope this makes sense

OR

Create some form of dos batch FILE that will save the event logs on my servers which is not run on the servers

btw i am using NT4Wow, you must be the only other person in the world with NT4. I thought I was the last one.

My email is
xxx gmail.com
(where xxx=QBasicMac)

Anyway, at the DOS prompt, enter "AT /?" and see if you like what you see.

Mac

cheers i will have a look see.

it seems most of the places i have worked are stuck in the NT zone, pain in the *censored* cos not only is it not capable to do a lot of stuff that newer platforms can.  it is sooo *censored* old i am having to re awaken my nt skills LOL.

Quote

Is there a way of running a command so it runs on the remote system as if i was physically logged in and running it?

Can you use a 3rd party tool?
Psexec from the pstools (Sysinternals) should do it.
The pstools are working fine with NT4.

hope it helps
uliPSEXEC from Sysinternals as suggested by Uli, or SOON.EXE from Microsoft (in the WINDOWS resource kit) should both do what you want.
1561.

Solve : check user input is x characters or specific forma?

Answer»

Hi,

hope you can all help me, I am new around these PARTS

I have created batch files to rebuild systems in dos via ghost and ghostwalker

, however when the user enters the COMPUTER name :-

Set /P compname=Please enter computer name:

I want to ensure they are using the correct format and characters ie nt0x00000

any tips?Aidy,

You can check each character one by one or you can check whole sub-strings, i.e.

[edit]setlocal ENABLEDELAYEDEXPANSION
if "!compname:~0,4!" NEQ "nt0x" goto:ERROR
for /l %%n in (4,1,8) do (
    if "!compname:~%%n,1!" LSS "0" goto:ERROR
    if "!compname:~%%n,1!" GTR "9" goto:ERROR
)
endlocal
echo.name is good
goto:EOF

:ERROR
echo.name is bad
goto:EOF[/edit]
DOS IT HELP?  I think the EASIEST and quickest way would be to USE the regular expression syntax of FINDSTR.  What is the correct format?  It looks like you are using nt0x#####, where "nt0x" is static, and # is any DIGIT?  If so,  you can use:
Code: [Select]:EnterCompName
set /p compname=Please enter computer name:
echo %compname%|findstr /r /x "nt0x[0-9][0-9][0-9][0-9][0-9]"
if errorlevel 1 echo Incorrect format&goto :EnterCompName
echo Name is goodNice GuruGary!!!  Much better!Thanks!thanks that did the trick, hopefully they might start making the machines with the right names now

1562.

Solve : Count Rows in a Text File?

Answer»

Hi Chaps,

Has anyone ever done this before?

I have a text file and want to count the number of rows it has. I know I can do this by importing into a database but this isn't feasible in the context of what I am doing.

I have some code (help from here already!!!!!!!) that provides me with a list of files in a directory eg

Filename1
Filename2
Filename3

This works great. However I would like to get the batch file to also count the number of rows in the text file and put this in eg

Filename1 25
Filename2   2
Filename3 178

Is this possible. I thought of perhaps counting the number of times the line feed appears in the file but am not really sure where to start.

I would really appreciate any help.

CheersWell, any programming language supports that. But I am just curious: DIR already reports file size. Why would you focus on number of lines rather than file size?

Mac
What OS are you running?  If Windows 2000 / XP / 2003 / Vista, you can USE:
Code: [Select]echo off
setlocal
if not {%1}=={} goto :Continue
echo No parameter specified. Syntax: %0 filename
goto :EOF
:Continue
for /f "tokens=1 delims=:" %%a in ('findstr /n . %1') do SET lines=%%a
echo The file %1 has %lines% lines.billsack,

Based on your other post I think this is what you want:

[edit](for /f "delims=" %%a in ('DIR *.XXX /b /s') do (
    for /f %%b in ('type "%file%"|find "" /v /c') do echo.%%a %%b
))>MyDIR.txt[/edit]

right or not? Hey guys,

Thanks for this. Cant get the code to work yet though.

Mac - the reason i am doing this is to get a ROW count for an import log. I don't need to know the filesize, just the number of records it contains!

The code to create the txt file with the file list is:

dir G:\share\CRS\FTPDownloads/b s>G:\share\CRS\FTPDownloads\CDSDataImport.txt

This works great.

I have tried:

(for /f "delims=" %%a in (G:\share\CRS\FTPDownloads*.txt* /b /s') do ( for /f %%b in ('type "%file%"|find "" /v /c') do echo.%%a %%b
))>G:\share\CRS\FTPDownloads\CDSDataImport2.txt

But I cant get it to work.

Cheers for all your help gents!Try this:
Code: [Select]echo off
setlocal enabledelayedexpansion
for /f "tokens=1 delims=:" %%a in ('findstr /n . G:\share\CRS\FTPDownloads\CDSDataImport.txt') do set lines=%%a
echo The file has !lines! lines.Should have tried it, sorry  :

[edit](for /f "delims=" %%a in ('DIR G:\share\CRS\FTPDownloads\*.txt* /b /s') do (
    for /f %%b in ('"type "%%a"|find "" /v /c"') do echo.%%a %%b
))>G:\share\CRS\FTPDownloads\CDSDataImport2.txt[/edit]

Now, how is that?

1563.

Solve : Batch to run ping loop?

Answer»

Hey guys,

Well I have searched high and low and tried everything but cannot get batch file to ping in a constant loop.
Basically I want to ping an ip constantly to keep a connection going (no not ping flood any1 )
Here is what I have so far....

pause
echo off

for /f "tokens=*" %%I in (C:\DocumentsandSettings\Matt\MyDocuments\Matt\iplist.txt) do call :pinger %%I
goto :eof

:pinger

echo %TIME% >> pingLOG
ping %1 >> pingLOG
:: DONE



Please have a look and advise me where I may have gone wrong or what I can do to make this work.
It would be greatly appreciated as I am at my wits end.

Cheers in Advance
SooPa_fLyThis worked when z.txt contained a few ip addresses, one to a line.

Lots of luck with your disk space if you run this for a long time. LOG will grow.

Mac

Code: [Select]echo off
cls
:loop
for /f %%I in (z.txt) do (
echo Pinging %%I
echo %TIME% >> z.log
ping %%I >> z.log
)
goto loop
How about:
Code: [Select]ping -t 1.2.3.4Replace 1.2.3.4 with the IP address that you really want to ping.Evil, GuruGary! LOL

That will keep one IP busy. He could use START to get them all going.

But I don't think he wants THAT many pings. He said
Quote

Basically I want to ping an ip constantly to keep a connection going

So he needs to ping every minute or 10 minutes, etc., not every 10ms. If you know a way to do the QBASIC equivalent of SLEEP 10, suggest that.

Mac
would a simple way to do this be :

:ping
ping x.x.x.x
wait 10
goto :pingBasically my iplist.txt is going to have a few different ips so I don't give 1 website the sh!ts by constantly pinging them.
I am looking to send a ping out every few minutes to keep the connection established. while I try to figure out what another problem is.

Cheers for the replies guys.The "wait 10" idea doesn't work in WindowsNT. WAIT is not a command.

However, if you just want to stall to give hosts a break, try this

Use my suggested BAT file (change filenames as desired)

In the TXT file, put your real sites you want to ping and then FOLLOW by a zillion instances of your own IP address.

By the time it gets through trying to ping them, some time would have elapsed.Qbasic cheers for that I will give it a try.
What about this
:ping
ping -n 100 127.x.x.x
goto :ping

I have been pinging a MATES website as he does not mind as I am having trouble making it find the txt file with the iplist.At what interval do you want to ping your iplist.txt?  Do you want to wait between each ping?  Or ping everything in your iplist.txt, and then delay?

Try this for once every minute, delay between each ping:
Code: [Select]echo off
:Start
for /f %%a in ("C:\Documents and Settings\Matt\My Documents\Matt\iplist.txt") do (
   echo %TIME% >> pingLOG
   ping %%a >> pingLOG
   ping -n 61 localhost >NUL
   )
goto :StartIf you are just looking for a result without the nuts & bolts then Connection Keeper will do it all for you.
http://www.gammadyne.com/conkeep.htm
Of course you will learn a lot more talking to these scary dos guys. Hi FELLAS! Quote
would a simple way to do this be :

:ping
ping x.x.x.x
wait 10
goto :ping

use the "sleep" command from the [RK]

uli
I would swear I just posted this, but I don't see it.
A bat file which can be named SLEEP.BAT and put in your path
Code: [Select]echo off
if x%1==x (
  echo Usage: SLEEP n [where n is the number of seconds]
  goto Adios
)
if not %1==NewCall %0 NewCall %1 >nul
ping -n %2 localhost
:Adios

SLEEP 10 will sleep 10 seconds.

Based on GuruGary's  ping -n 10 localhost >nul
which doesn't work on windowsNT for unknown reason

Mac

Cheers for the tips guys. I will give them a GO and see how it goes.

We have been running a ping utility but it is a trial and my manager wanted a bacth file.

Thanks again guys

cheers
1564.

Solve : Batch file does not exit?

Answer»

Hi.  I'm trying to make a bat for Win 2000 that will run a few printer related commands and then OPEN an executable.  The printer commands help with a glitch related to the exe.  The printer commands work fine.  I want the final action to start the exe and then have the CMD prompt window close.  Is there some way to have the window close even if the exe is still running?  It does make it all the way to the exe line, but stays open until the exe is closed.  Here is what I have so far:

ECHO OFF
ECHO Initializing printer drivers.
ECHO Correcting for HP related footer problems.
c:
cd\
CALL "c:\LaserJet_Restore_2000.bat"
"C:\INSTRON\COM\MERLIN.EXE"
CLS
EXITstart  "C:\INSTRON\COM\MERLIN.EXE"Adding START causes a 2ND cmd window to popup.  This window has a title of C:\INSTRON\COM\MERLIN.EXE and only shows a c: prompt.  The FIRST window closes, but the merlin.exe never opens.I FIGURED it out.  I needed to lose the extra quotes.  This worked:

ECHO OFF
ECHO Initializing printer drivers.
ECHO Correcting for HP related footer problems.
c:
cd\
CALL c:\LaserJet_Restore_2000.bat
START C:\INSTRON\COM\MERLIN.EXE
CLS
EXIT

1565.

Solve : Passing a blank line to a file?

Answer»

Hello all.

I have a requirement to PASS parameters to a program. I am building a parameter file on the fly before running the program, the problem is some of the parameters can be blank and I can't see to echo a blank.

Any Ideas?

Here is what I am doing:

REM Program Types                                                                                
> j582v02.bat echo KEN
>>j582v02.bat echo
>>j582v02.bat echo
call C:\Progra~1\Claims\bat\qzc.bat V60 SYR002B j582v02.bat
if %ERRORLEVEL% GTR 0 (                                                                          
  > ERROR.dat ECHO SYR002B %ERRORLEVEL%                                                          
  goto EOF                                                                                        
)                                                                                                

The result comes out like this:

KEN
ECHO is off.
ECHO is off.
echo.Thanks for the response.

A little more information WOULD have been nice....lol.

But I GOT the message. I almost didn't see the period at first.
Still not SURE why this works, but it does.

Thanks again.

1566.

Solve : complete beginner?

Answer»

hi, im a complete begginer with BATCH files, but what I have to is create a batch file that will

run a batch file (db.bat) on a remote computer
and then get a file (tuxp.txt) from a remote computer and put that file in a folder in E:\DB
and that file should overwrite any txt file in there aswell as moving  the overwritten file to a folder E:\DB\OLD.

all I know about batch files is that you create them with notepad.

Please help

thanks in advanceWhy do you need to do this? Is this a HOMEWORK question? I can't think of any other answer to ask this, but hold on and read these and the teacher will be along shortly.


http://www.chebucto.ns.ca/~ak621/DOS/BatBasic.html

http://www.allenware.com/icsw/icswidx.htm

http://www.techtutorials.info/dbatch.html

www.HomeworkHope.com Quote

all I know about batch files is that you create them with notepad.

You probably mean "I know nothing about DOS".

You see, normally you would start a DOS (CMD window) by Start/Run/CMD

There, you would issue DOS commands. For example, the AT command might help you run something on another computer.

To learn how a command works, enter the OPERAND "/?", for example
AT /?

Now MOVE will move a file, COPY will copy one.

So you just figure out how to solve your problem one DOS command at a time.

When you know what you want to do, you put the commands into a single file with SUFFIX "bat" and voila.

The only thing you might need to learn about BAT is that %1 means the first operand, etc. like this

The file is Z.BAT:
copy %1 d:\here\file1.dat
copy %2 d:\here\file2.dat

That is a nonsense two-line BAT file that will do this, if you enter
Z abc.txt def.txt

copy abc.txt d:\here\file1.dat
copy def.txt d:\here\file2.dat

So now you know about BAT files. Work on it and let us know if you have some specific question.

Mac


1567.

Solve : Deleting files older than 15 minutes?

Answer»

I need to create a batch file that will delete temp files in a directory. I want to delete files that are older than 15 minutes or more. I can use ?? > to cover the file names but can't narrow down the date/time. This seems like a pretty simple thing but...

Any help?

Operating system is Windows XP.Well, I could write you a QBasic Program that would do that, but it is dangerous if run automatically.

What is your application? Why do you focus on 15 minutes? Will the program be run on a scheduled bases or manually. I ask because I would have to worry about stuff like "is it midnight", "has the time adjusted (daylight savings)".

If I knew you always would run manually and not near midnight or 2am, then that would be nice.

Mac
there are ways to do time CALCULATIONS like that in batch, but things would get a bit messy. you could try lang like vbscript/perl/python etc , if you know them..
I like to use Python though. a simple ONE eg
Code: [Select]import os, time
now = time.time()
fifteen = 60 * 15  #15 min convert to secs
os.chdir("temp")
for file in os.listdir(os.getcwd()):
     m = os.stat(file)[7] #get last modified time,[8] would be last creation time
     if m - now < fifteen:
            print "File found: %s" % file
This should work in a COMMAND prompt under Windows XP.  Batch files were not really designed to handle dates or math very well, but this should work:
Code: [Select]echo off
setlocal

call :DateToMinutes %date:~-4% %date:~-10,2% %date:~-7,2% %time:~0,2% %time:~3,2% NowMins
for /f "delims=" %%a in ('dir * /a-d /b') do call :CheckMins "%%a" "%%~ta"
goto :EOF

:CheckMins
set File=%1
set TimeStamp=%2

call :DateToMinutes %timestamp:~7,4% %timestamp:~1,2% %timestamp:~4,2% %timestamp:~12,2% %timestamp:~15,2%%timestamp:~18,1% FileMins
set /a MinsOld=%NowMins%-%FileMins%
if %MinsOld% gtr 15 echo del %file%
goto :EOF

:DateToMinutes
setlocal
set YY=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if /i {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if /i {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
if /i {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
endlocal&set %6=%j%&goto :EOFThis is still in "debug" mode, so after you have tested it to be sure it works the way you want it to, take the echo out of the line if %MinsOld% gtr 15 echo del %file%

1568.

Solve : Problems mapping network drives after wireless net?

Answer»

Hello. I have a BATCH file witch maps two (linux ubuntu) network drives and then
sync's time with the linux ubuntu server.

The problem is that after I'v startet using wireless network the batch file
is run befor the network has started. The network starts after Windows ME login
and the batch file is started at login.

As I SAID (my server is Linux Ubuntu) and the klient i Windows ME.
What can I do to solve this ?You can add a delay at the top of your batch file.  A simple way to create a delay is using the PING COMMAND which waits 1 second between ping attempts.  So for a delay of 10 seconds, try something LIKE this:
Code: [Select]echo off
ping -n 11 localhost
net use X: \\ubuntu\share1
net use y: \\ubuntu\share2
net time /set \\ubuntu
You can change the number in the PING command for more delay or less delay.

1569.

Solve : Batch file to fetch user defined file?

Answer»

I'm looking to make a batch file that would ask the user to enter a 2 digit number to specify what file they need.  The files are located in a shared folder with each file located in a folder named XXXXXX## with the ##'s representing the 2 digits I would want the user to enter.  I can cover the rest as far as fetching the files and where to put them etc.

Thanks in advance, you guys really helped me last time and I'm sure this one will be a snap compared to that  Here's a simple way that works on all versions of DOS

Mac

Code: [Select]ECHO off
echo.
if x%1==x (
  echo You forgot the two digit code. Please try again
  echo.
  echo Format is %0 xx
  echo where xx is your two digit code
  goto Adios
)
if not exist xxxxx%1\*.* (
  echo That was an invalid code. Try again.
  echo Unable to find directory xxxxx%1
  goto Adios
)
{at this point you have your directory}
Quote

Here's a simple way that works on all versions of DOS
Actually, the parenthesis grouping in an IF statement is not SUPPORTED in DOS 6.x and older or Windows 9x.

Dam1an: What version of DOS are your users running?  If it is Windows 2000 / XP / 2003 / VISTA  you can try something like this:
Code: [Select]echo off
set /p number=Please enter the 2-digit code for your file:
echo The directory specified is xxxxxx%number%
You may want to add more error checking, but I THINK that is the basics of what you want.How do you see version number? All I see is
Microsoft(R) Windows NT(TM)
(C) Copyright 1985-1996 Microsoft Corp.

Mac
Thank you GuruGary, that WORKED great.  
 
QBasicMac: You can use the VER command to tell the DOS version.  If it is really DOS, it will return a string like MS-DOS Version 6.22.  If it is a command processor running under Windows it will return a string like Microsoft Windows 2000 [Version 5.00.2195].  You can also look up the version of your command processor extensions (under supported operating systems) with the command:
Code: [Select]echo %cmdextversion%
Dam1an: Glad it worked
1570.

Solve : A "autorun batch file"?

Answer» HELLO everybody!
It feels like i've looked everywhere but i cant find any solution to my PROBLEM...
I want to make a batch file that, when you start it it starts a program and if this program is already RUNNING i want nothing to happen..
can anybody plz make my life a bit easyer by solving this problem of mine  ?

Best Regards
LeXWhat version of Windows are you running?

You can try the TASKLIST command.  Something like:
CODE: [Select]tasklist /fi "imagename eq MYRPOG.exe"or
Code: [Select]echo off
tasklist /fi "imagename eq MYPROG.exe"|findstr PID
if not errorlevel 1 goto :Nothing
echo Make something happen
goto :EOF

:NothingWindoes XP Pro

cant get it to work  :-?
what to put in "imagename"? Quote
...I want to make a batch file that, when you start it it starts a program and if [highlight]this program[/highlight] is already running i want nothing to happen...
What is "this program"?

For this to work, you need to replace the MYPROG.exe in my code with the real file name of "this program".
1571.

Solve : net use?

Answer»

I'm setting up a scheduled task to retrieve some files from a remote server over VPN using MS DOS.  A drive has already been mapped on my machine but, SINCE connecting VIA VPN is part of the process, the drive is disconnected and requires a LOGIN to connect it.  Could someone just give me an example of how to connect to a drive using NET USE with a user name and password?  Thanks.Code: [SELECT]net use x: \\server\share /user:username password
X: would be the drive letter you want
\\server would be the computer name
\share would be the network share, or path
username would be the username
password would be the password

If it is already connected, you may NEED to disconnect it first with
Code: [Select]net use x: /del
net use x: \\server\share /user:username passwordThank you very much.  This code works.

net use x: \\server\share /user:username passwordyou may want to put the mapping of the drive into a short vbe and call the vbe from the batch script... with the cscript command...

1572.

Solve : ms dos 3.31 HELP!?

Answer»

I have a paperweight pc in my basement and wanted to boot it up and see what I could do on it, maybe play some old floppy games on it, whatever else.

Well it is a HEWLETT PACKARD VECTRA 386/25

when i HIT the power button a few seconds LATER a screen show this:

error code 800D 0250 system test reports error, run setup disck version C.02.00 or greater.

The computer itself has a floppy drive and a 3 1/2 inch disc drive.

I know this thing is older than dirt, It was in the basement when i moved in

I just want to know if I can get it to al least navigate enough to run some floppy games for the BOY...well me too.Sounds like a hardware error, probably the motherboard, before DOS even loads. You may want to google for the error code or check on the HP support site.

If you want to start by replacing the old CMOS BATTERY you can pursue it, but you would have to start there. Probably not worth the time and trouble, UNFORTUNATELY.

1573.

Solve : unable to start format?

Answer»

hey i am new here and i have a minor problem if someone would at least  try to help i would appreciate it. anyway my problem is i have alot of viruses and other minor PROBLEMS so i would like to format my c: but when i type in format c: like i usually do it says bad command or file name. i am using a boot disk (floppy) to do so and running windows xp home on a compaq presario. once again anyone who replies thank you for your timeSo you have booted from a floppy. It therefore doesn't matter if you usually are "running windows xp home on a compaq presario" or not. Now you are running DOS and there is no WindowsXP running - right??

So you are sitting at the A:> prompt and enter the command "format" and it says "something like ...".

Please try again and ensure the above is the case and report the EXACT wording of the error message. EXACT!

Offhand, I can't see why you are having a problem, unless you reported the case incorrectly and are doing something else.

Mac
Do you have the installation CD of your XP? if you have, then i believe you can boot up using that?? then do  reformmatting and reinstallation.That is correct. He is going about this the HARD way. If he has some sort of restore disc that should not be an issue either.Is format.com on your bootdisk? (maybe a stupid question but...)

uliType in format c:/u and hit Enter at the A: prompt.

Note the space between the command and the target C:


patio.  8-)Another hit and run poster......  O,that's too bad !I heard that on XP system ,there is no really DOS system in it !Can you find anther way to format you c:\ ,or you can try again to format u c: on DOS!May be it can be effect! Quote

O,that's too bad !I heard that on XP system ,there is no really DOS system in it !Can you find anther way to format you c:\ ,or you can try again to format u c: on DOS!May be it can be effect!


Get a Job ! !.... Quote
O,that's too bad !I heard that on XP system ,there is no really DOS system in it !Can you find anther way to format you c:\ ,or you can try again to format u c: on DOS!May be it can be effect!


Wangming, I am THIS close to just deleting all of your POSTS.

If you get an urge to type something and then click on the POST button - don't.hey thanks for the help everyone and sorry i took so long to post again. yea i didnt have the right boot disk and thats why it wasnt formatting but i got a copy of the one i needed and it worked. so i am virus free, for now. is there any free anti virus progs that you can just download? if so does anyone reccomend anything. Well thanks again

ns :|Avast
AVG

Choose one or the other.

AdAware
Spybot Search and Destroy
Ewido
CCleaner

Grab all of these.

Make SURE after installing each one to grab the online updates and scan your entire system the first time in Safe Mode with each one with System Restore turned offk thanks
1574.

Solve : DOS 6.22 installation on new HDD?

Answer»

I have a new formatted HDD.
I wish to make the 1st partition to be a DOS 6.22 sector.
I have no idea on how to install the DOS 6.22 into my HDD.
What I found is only DOS bootable files not installation setup files.

Anyone here have the installation files?
Is there a way to burn it as a CD, so that i can use this CD to install DOS next time.

You have to have the installation diskettes or CD (which is fairly rare). TRY eBay.DOS 6.2 is on 4 floppy disks...setup.exe should be on DISK # 1.
If it isn't this isn't a real ver. of DOS.

patio.  8-)To search on the NET!MAY be U can find one ver of DOS!W Quote

To search on the net!May be u can find one ver of DOS!W

Who knows what this means? Quote
Quote
To search on the net!May be u can find one ver of DOS!W

Who knows what this means?

Probably as much as his other posts so far...Nil.
1575.

Solve : file.txt to file.hex?

Answer»

i not know if it's easy to do but .. try to ask:

i have file.txt with

Quote

02E37CFE2445E08C04EF2049445FE3E6
03F5ED7538AA386C9C38087546FAC0F4
045F94AE3C85B806F73CEFF523D069E8
0499247205BE3F73DF99299D9525A7AF
08F8D5130625DEABDED4A7988DF1259D

at the end of every line i have 0d0a (i think "return" hex code)

i need to translate this line into hex code for make hex file

16byte, delete 0d0a, attach next 16 byte and go on

02 e3 7c fe 24 .... usable like hex dataexplain more clearly what you are trying to do.
you said you have "0d0a" at end of every line, but i don't see it in your sample file.
also, GIVE a sample of your desired output.You need to write a program to do that.

Here is one in QBasic. If you have QBasic in your DOS system, then SAVE this program as z.bas and your data as z.dat and do
QBasic /run z

That will produce z.com, your hex file of 80 characters.

Mac

Code: [Select]OPEN "z.dat" FOR INPUT AS #1
OPEN "z.com" FOR OUTPUT AS #2
DO WHILE NOT EOF(1)
  LINE INPUT #1, l$
  PRINT l$; "<---"
  IF LEN(l$) <> 32 THEN PRINT "Wrong length record": SYSTEM
  FOR i = 1 TO 32 STEP 2
    v1 = INSTR("0123456789ABCDEF", MID$(l$, i, 1))
    v2 = INSTR("0123456789ABCDEF", MID$(l$, i + 1, 1))
    IF v1 * v2 = 0 THEN PRINT "Non-hex in file": SYSTEM
    v3 = ((v1 - 1) * 16) + (v2 - 1)
    PRINT #2, CHR$(v3);
  NEXT i
LOOP
CLOSE
SYSTEM
i have one txt with more hex data (or i make one by copy/paste part from one other big txt)

if i see with hex editor the txt file i see at the end of every line one CR like 0d0a (2 byte)

now i need to make from this txt file one hex file

....

one functional way are to delete manually all "CR":

Quote
02E37CFE2445E08C04EF2049445FE3E603F5ED7538AA386C9C38087546FAC0F4
045F94AE3C85B806F73CEFF523D069E8
0499247205BE3F73DF99299D9525A7AF
08F8D5130625DEABDED4A7988DF1259D

like first two line and paste it into hex editor ...

but are about 189 line  frankly, i don't understand. Since you are using hex editor to see the file, does the editor have any way to save it as hex??with hex editor i see hex data (the hex data i need into hex file) like ASCII code into right windows Quote
frankly, i don't understand.

Two options:

He has a text file, not a hex file. The text file has 32 characters in the range 0-F on a line. Each line is terminated by a line-feed plus carriage return as is true for all text files. So if first two lines are this in the text editor:

02E37CFE2445E08C04EF2049445FE3E6
03F5ED7538AA386C9C38087546FAC0F4

then in the hex editor, he sees this (starting with E3E6 at the end of line one:

E 3 E 6 CRLF0 3
4533453613103033

And if so, my QBasic program will work.

Otherwise, he ALREADY has a file where the characters are 0-255, but each 16 characters is delimited by the crlf. He just wants to eliminate the crlf.

This can be DONE by
LINE INPUT #1, L$
PRINT #2, L$;

The semi-colon will eliminate the crlf.

Mac
i'm really newbie  :-?

i have just maked Qbasic program and it work (i not have test all hex code), so i need to put into little tool directory Qbasic executable

i'm searching for one more little (in disk space) solution

really thanks QbasicMac Quote
You need to write a program to do that.

Here is one in QBasic. If you have QBasic in your DOS system, then save this program as z.bas and your data as z.dat and do
QBasic /run z

That will produce z.com, your hex file of 80 characters.

Mac

Code: [Select]OPEN "z.dat" FOR INPUT AS #1
OPEN "z.com" FOR OUTPUT AS #2
DO WHILE NOT EOF(1)
  LINE INPUT #1, l$
  PRINT l$; "<---"
  IF LEN(l$) <> 32 THEN PRINT "Wrong length record": SYSTEM
  FOR i = 1 TO 32 STEP 2
    v1 = INSTR("0123456789ABCDEF", MID$(l$, i, 1))
    v2 = INSTR("0123456789ABCDEF", MID$(l$, i + 1, 1))
    IF v1 * v2 = 0 THEN PRINT "Non-hex in file": SYSTEM
    v3 = ((v1 - 1) * 16) + (v2 - 1)
    PRINT #2, CHR$(v3);
  NEXT i
LOOP
CLOSE
SYSTEM

one other question ...

for me it's usefull to have into beginning list (TXT FILE) some text word to esplain some information but, of course, when i trasform file.txt to file.hex thie word not have trasformed

can you adjust this program for not consider, for example, line begin with # char ?

Quote
02E37CFE2445E08C04EF2049445FE3E6
03F5ED7538AA386C9C38087546FAC0F4
#
# text for infomation about and not to translate
#
045F94AE3C85B806F73CEFF523D069E8
0499247205BE3F73DF99299D9525A7AF
08F8D5130625DEABDED4A7988DF1259D

thanks againscriptors,

I think this is what you want...

If text1.txt contains:
[edit]02E37CFE2445E08C04EF2049445FE3E6
03F5ED7538AA386C9C38087546FAC0F4
#
# text for information about and not to translate
#
045F94AE3C85B806F73CEFF523D069E8
0499247205BE3F73DF99299D9525A7AF
08F8D5130625DEABDED4A7988DF1259D [/edit]

Then you want to convert it into one continuous:
[edit]02 E3 7C FE 24 45 E0 8C 04 EF 20 49 44 5F E3 E6 03 F5 ED 75 38 AA 38 6C 9C 38 08 75 46 FA C0 F4 04 5F 94 AE 3C 85 B8 06 F7 3C EF F5 23 D0 69 E8 04 99 24 72 05 BE 3F 73 DF 99 29 9D 95 25 A7 AF 08 F8 D5 13 06 25 DE AB DE D4 A7 98 8D F1 25 9D[/edit]


The following batch script will do the job:
[edit]echo off
(
    for /f "eol=#" %%a in (file1.txt) do (
        set hx=%%a
        for /l %%n in (0,2,31) do (
            call echo.%%hx:~%%n,2%%
        )
    )
)>%~dpn0.htm[/edit]

Copy the code into a new batch file named myhex.bat.  Have text1.txt in the same directory.
Executing myhex.bat will create a new file named myhex.htm that you can open in a web browser and then copy your hex code from there into the hex editor.

DOS IT HELP?
1576.

Solve : DOS comand dir?

Answer»

When I write a COMAND DIR inside existing folder, I receive a list of folders, and always at the beginning there are two of them:
  .
  ..
all others.

Maybe it is basic question but what mean these "." and ".."?

Thanks

The . (dot) directory means "current directory".
The .. (double dot) directory means "parent directory" or "go back one directory level" (kind of like the "up" button with the green ARROW pointing up over the yellow folder in the Windows Explorer or My Computer toolbar).

You can use them with commands for many purposes.  For example, let's say you are in the directory "C:\Documents and Settings\kkkkk\My Documents".  If you want to copy everything in your current directory to "C:\Documents and Settings\kkkkk\Backup" then you could use the command:
CODE: [Select]XCOPY . ..\Backup\which is the same as (but a LOT shorter and quicker than):
Code: [Select]xcopy "C:\Documents and Settings\kkkkk\My Documents\*.*" "C:\Documents and Settings\kkkkk\Backup\"Nice one, GGThanks!

1577.

Solve : Getting a variable in FOR loop?

Answer»

Hi,
I have a FOR loop something like this :
FOR /f %%a in (temp.txt) do set b=%%a

Here, b takes the contents in the FILE temp.txt. The contents in this file are as follows :

S0000000.LOG
S0000001.LOG
S0000002.LOG
S0000003.LOG
S0000004.LOG
S0000005.LOG
S0000006.LOG
S0000007.LOG
S0000008.LOG

So, b takes all these values. But I want b to take only the NUMBER in the filename. So, I modify my FOR loop as follows :

FOR /f %%a in (temp.txt) do set b=%%a set c=%b:~1,7%
but c is taking the value as 0000008 through out the FOR loop, what should I do so as the values 0000001 to 0000008 come in the variable c?The trouble is, its a loop
That is to say, c get set to each of the values in turn -- the LAST one to be set is 0000008, so this is the value to be held after the loop exits.

You really want to call a subroutine for each iteration of the loop and do your processing there for each value :

FOR /f %%a in (temp.txt) do Call :Subroutine %%a %b:~1,7%  

GoTo :EOF
:Subroutine
Set b=%1
Set c=%2
... rest of your process


GrahamThanks a lot. It worked.Or a slightly shorter version:
Code: [Select]setlocal enabledelayedexpansion
FOR /f %%a in (temp.txt) do (
   set b=%%~na
   set c=!b:~1!
   echo Rest of your process for !c!
   )When using setlocal enabledelayedexpansion, you can use ! instead of % to use your variables without having to call a separate function.  For more information you can do "setlocal /?" or "set /?"

The set b=%%~na tells the batch file to use the filename portion of the %%a without the extension.  So this will work for FILES that are longer and files that are shorter than the 8.3 examples you had posted since it doesn't rely on just using the first 8 characters.Or filter the number while parsing the file by defining 'S' and '.' as delimitters and capturing the first TOKEN:

for /f "delims=S." %%a in (temp.txt) do (
    echo.Do the rest of your process using '%%a'
)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

1578.

Solve : Batch Files That Create Dir's w/ Today's Date?

Answer»

Hi All,

I'm trying to write a batch file that will create a directory named with TODAY's date and time: i.e., mmddyyyyhourmin.  I'm aware of the existence of the %time% and %date% variables.  But, %date% is of the format: Thu mm/dd/yyyy.  And, %time% is formated: hh:min:sec.msec.  How can I extract the pieces I need to form the string I need to pass to mkdir: i.e., mkdir mmddyyyyhourmin?

Thanks.
Quote

I need to pass to mkdir: i.e., mkdir mmddyyyyhourmin?

Well, I recommend yyyymmdd so your names SORT like this
200612311104
200701010015
etc.

It is normally a mistake to put year last, but you can easily patch my code below if your management is stupid and insists.

If the BAT file is just for your own use, fine. Otherwise, be aware that %date% and %time% are not defined in WindowsNT DOS (and maybe others)

I had a solution that required 'date /t', but learned that other systems don't have that command.

So I don't know a solution that is portable. This one will work on your system. The SET DATE and TIME are just to give me test data as %date% normally returns nothing for me.

Mac

Code: [Select]echo off
set date=10/26/2006
set time=11:04:30:22
cls
echo Debugging for date=%date% and time=%time%
echo.
for /F "tokens=1 delims=/" %%i in ('echo %date%') do (set dmm=%%i)
for /F "tokens=2 delims=/" %%i in ('echo %date%') do (set ddd=%%i)
for /F "tokens=3 delims=/" %%i in ('echo %date%') do (set dyy=%%i)
for /F "tokens=1 delims=:" %%i in ('echo %time%') do (set thh=%%i)
for /F "tokens=2 delims=:" %%i in ('echo %time%') do (set tmm=%%i)
echo The directory name will be %dyy%%dmm%%ddd%%thh%%tmm%
QBasicMac: Windows 2000 / XP / 2003 / Vista have built-in DATE and TIME environment variables.  I'm not sure about Windows NT.  I would strongly recommend against replacing these system variables with set time= or set date=.  

The format of %date% and %time% depends on your regional settings.  If yours is set for U.S. English this should work.  For mmddyyyyhourmin (as requested) you can make a directory with:
Code: [Select]set hour=%time:~0,2%
if %hour% LSS 10 set hour=0%hour:~-1%
md %date:~-10,2%%date:~-7,2%%date:~-4%%hour%%time:~3,2%
Like QbasicMac, I personally prefer to use the year first.  So for the format of yyyymmddhourmin you would replace the MD line with:
Code: [Select]md %date:~-4%%date:~-10,2%%date:~-7,2%%hour%%time:~3,2%
The reason I do the HOUR seperately is because by default a single digit hour (1-9) is padded with a space. Quote
I would strongly recommend against replacing these system variables with set time= or set date=.  

Oh, definitely!! I thought I made it clear that I did that only for debugging my NT script where they are not reserved WORDS. I guess I failed.

Right! Do not put SET DATE in your script, OP, especially if you WANT the current date rather than a constant.

Mac

For a more "portable" solution. You can use Perl/Python or other scripting languages.
Eg in Python
Code: [Select]import time,os
date = time.strftime("%Y%d%m%H%M%S" ,time.localtime()) ## date = 20062710110431
os.mkdir(date) #make directory with  format 20062710110431

Of course, this assumes you know other languages besides batch
1579.

Solve : General Forum Question?

Answer»

In the index, I see "Replies" and "Views"

I see some with Replies=0, yet when I go there, I see many replies.

Does this MEAN the statistics are bogus and to be ignored? (I did refresh but nothing changed)

Mac
The topic is probably locked to prevent erroneous posts.I post alot here and my replies go generally ignored...that might be a part of it.

PATIO.  8-) Quote

I post alot here and my replies go generally ignored...that might be a part of it.

patio.  8-)

Step into the light, Patio, step into the light... Quote
I post alot here and my replies go generally ignored...that might be a part of it.
Quote

LOL

But I guess I BELIEVE the EXPLANATION that closed threads show zero replies. Strange custom, though.

Mac
1580.

Solve : Problem with writing batch file?

Answer»

Hi all,
I am writing a BATCH file. The batch file is suppposed to find out the number of files in a particular folder. Is that possible using DOS command as I want the value of the number of files to be stored in a variable.
Also, is it possible using dos command that if I execute any command in dos prompt then the resulting value of that command can I store in a variable.
Which version of DOS are you using, or what version of Windows is your command prompt running under?  If running under Windows NT / 2000 / XP / 2003, then what you want to do is pretty easy, and can be done SEVERAL different ways.  To set the environment "numfiles" to contain the number of files in the current directory, you could run the following from within a batch file:
Code: [Select]for /f %%a in ('dir /a^|find "File(s)"') do set numfiles=%%aThanks a lot for that reply.
I have some more questions in my mind.

Is it possible to set the resulting value of a command to a variable?

If I have 2 values in 2 different variable, then can I concatenate them?

I have some value in a variable and there is an extra space at the end of the value, some thing like
"abcwdweydew ".I want to remove that extra space.Is it possible?

Quote

Thanks a lot for that reply.
Is it possible to set the resulting value of a command to a variable?
Yes
Quote
Thanks a lot for that reply.
If I have 2 values in 2 different variable, then can I concatenate them?
Yes
Quote
Thanks a lot for that reply.
I have some value in a variable and there is an extra space at the end of the value, some thing like
"abcwdweydew ".I want to remove that extra space.Is it possible?
Yes

The FOR /F loop will save resulting output to a variable as in my previous example.

To concatenate 2 variables (let's say named numfiles1 and numfiles2) into a new variable (numfilesconcat) you can do:
Code: [Select]set numfilesconcat=%numfiles1%%numfiles2%If you want to add them together instead you would do:
Code: [Select]set /a numfilestotal=%numfiles1% + %numfiles2%
To remove the LAST character off a variable named "string" you can do:
Code: [Select]set new=%string:~,-1%Thanks a lot. It worked.
1581.

Solve : Repair Connection?

Answer»

Hello,

I am having a PROBLEM on my computer when I try to connect to a network drive HOWEVER I noticed that when I "repair the CONNECTION" I can access it, so does ANYBODY know how to do that in DOS or how to fix this problem. By the way its a wireless connection.

Thanks

Al968ipconfig /?

Try
ipconfig /release
ipconfig /RENEW

1582.

Solve : format a floppydisk without questions?

Answer»

I want to format a FLOPPY in a batch file without the usual input i have to give. I have done something like that for a hard drive which WORKS fine:

echo j | format c: /v:vollabel /q

the floppy however is asking me if i want to format another one and here the system halts.
here i need to press N. i dont have any idea how to add this N in my batch. I hope anyone out there can help me

thanks in advance
Code: [Select]echo yn|format a: /q >nul
works on English system
(>nul is to get rid of all the EXCESS prompt messages)

Mac
Thank you Mac
I COPIED your sugestion today in my batchfile but it didnt work. i took away the >nul option to see what happened and it looks the Jn characters are used right after "press enter when ready...." I hope there are some other options left

I dont know if it has anything to do with it but i am using a dos window in w98. i believe dos 7.xx. it could be the reason why it worked on your pc and not mine. i rather not go for the idea that it has something to do with language so i keep trying.





If you run the command manually
format c: /v:vollabel /q
exactly what keys to you have to press to get to the end?  Is it:
[Enter]
j [Enter]
n [Enter]

If so, you can save those KEYSTROKES to a temp file like this:
Code: [Select]echo.>fmt.tmp
echo j>fmt.tmp
echo n>fmt.tmp
format c: /v:vollabel /q<fmt.tmp
del fmt.tmp Quote

Code: [Select]echo.>fmt.tmp
echo j>fmt.tmp
echo n>fmt.tmp

Learn something every day! I always wanted to write blank lines with echo, but always got "echo is on/off".

You meant, of course, to use >> instead of > for the rest of the prompt file.

But you have to put "jn" together to avoid a line feed.

Code: [Select]echo.>fmt.tmp
echo jn>>fmt.tmp

Mac
Quote
I dont know if it has anything to do with it but i am using a dos window in w98. i believe dos 7.xx. it could be the reason why it worked on your pc and not mine.

I am embarrassed that the answer is that I goofed.

I didn't test with FORMAT, but tested with some commannd which has no such prompt for an enter-key. So I gave poor advice.

See GuruGary for the right idea (with my small correction).

So to attone for my sin, I just used the Bat file below to test on a floppy. First floppy I have formatted for at least 10 years: Don't use them much and if I ever buy any, they come pre-formatted.

It took about 2 minutes, seemed like 20. LOL.

Mac

Code: [Select]echo off
echo.>z.dat
echo yn>>z.dat
format a: >z.lst <z.dat

You can use "nul" rather than "z.lst" if you don't want to keep output.

Use any names you want for the files.
Good catch, Mac.  Yes, as corrected by QBasicMac, the code should be set to append the file.
1583.

Solve : what is *.*?

Answer»

i'm trying to create a boot disk and this site told me to COPY format*.* a: then press enter and my pc said FILE not found. does the *.* mean something else?* is a joker sign

Basically, it will look for any file and any extension. If you were to type *.exe it would look for every executable file. Depending on what command you use in front of it, though, it could also mean copy every .exe file..

Copy format *.* A: doesn't make sense at all, what are you trying to achieve?i'm trying to copy additional files to a boot disk for windows 98Can I see the instructions?If you created a w98 boot disk from windows, format.com should already be on the disk. It is one of the utilities placed on the disk when it is created. If you need to copy additional files:
copy a:
or:
insert the floppy and locate the file to be copied. Right click and select SEND to 3 1/2 floppy.*.* means all.

If you need a bootdisk to format a drive go to www.bootdisk.com. Quote

copy format*.* a:
yields error message "file not found."
What does that mean?

copy format*.* means to copy all files that begin with "format" that are in your current DIRECTORY, for example
format.exe
format1.exe
formatx.com
format~2.zip

"file not found." means that in your current directory, there are no such files.

In general, it means you are not in the CORRECT directory or the instructions you are following do not apply to your environment.

Mac
1584.

Solve : ramdrive?

Answer»

i want to create an image drive on floppy msdos-startup disk using
device=ramdrive.sys 4096 /e , on config.sys
..i want to ask:
1. to successfully create it, do i need ramdrive.sys file on my windows folder?
   (i didn't find it, how to create it ??)
2. as i know the syntax..
device=[drive:][path]RamDrive.sys  [DiskSizeSectorSize NumEntries] [/e][/a]
, using drive and path for what??? it's on floppy right?
3. what is the diffrent between extended and expanded memory..?
sorry.. if too many questions.. i hope someone could help me..1: The RAMDRIVE.SYS file needs to be accessible from your floppy disk.  The best way to ensure it is accessible is to put it on your floppy disk.

2: Drive and path to the RAMDRIVE.SYS file.  So if it is on your floppy disk, it would probably be DEVICE=D:\RAMDRIVE.SYS 4096 /e

3: Expanded and extended memory are 2 different ways programs can access your RAM.  Windows uses Expanded memory, as do most programs.  There are some old Lotus programs, and a few really old DOS games that use expanded memory, but just about all programs written in the past 10 years will use extended memory.
sorry,i still don't understand bout extended and expanded memory..
what is the different on how they works..could you TELL me more...? thank you

one more.. if ramdrive.sys is in my floppy. i would just write device=ramdrive.sys 4096 /e ( no drive and path specified means that ramdrive.sys is on the root directory right.. it's in my floppy disk)
why you write D: on your example above?...For the difference between extended and expanded, try these links:
http://www.webopedia.com/TERM/E/expanded_memory.html
http://www.webopedia.com/TERM/E/extended_memory.html
There is not really a difference between the actual memory (in most cases), but back in the "old days" before Windows, different applications had to be written to take advantage of RAM over 1 MB, and the 2 choices were Extended and Expanded.

You are right to QUESTION my use of the D: drive in my example.  That was a BAD example, and I should have used A:.  If the file is on your floppy disk you can use Code: [Select]DEVICE=A:\RAMDRIVE.SYS 4096 /e or EVEN just Code: [Select]DEVICE=RAMDRIVE.SYS 4096 /e assuming the RAMDRIVE.SYS is in the root directory of your boot drive.OK.. thank you very much for your nice help...
You're welcome. Quote

sorry,i still don't understand bout extended and expanded memory..
what is the different on how they works..could you tell me more...? thank you

There is no need to reinvent the wheel. That information and much more is readily available through Google, etc. Here you go:

http://www.google.com/search?hl=en&q=extended+and+expanded+memory
1585.

Solve : setting paths from search result?

Answer»

Hi all,

I need HELP setting the filename and path, for a secondary search. Scenario is this;

I've done a search of all drives for files of a certain size, and echoed the results to text (showing full path).
I now need to search the files in those results for a string. How do I echo those to the command line with my search parameters?

I have another situation where I have done a specific directory search of all drives, and now need to echo those paths back to get a file list in each directory.

Intent is to use on 9X and NT both.

TIA
Assuming z.txt contains a list of filenames,
and z.lst is where you want your results:
Code: [Select]echo off
time /t>z.lst
for /f %%i in (z.txt) do (
find "Press Enter" %%i >> z.lst 2>&1
)
Thanks QBasicMac. That helped a lot.
I had to revise it a bit due to the fact that I forgot to add, that also in the text is the file size, currently listed first (all the same size). Have it working for NT using ' for /F "tokens=2" %%i '. Would using the %%i as SHOWN above work for 9X if filepath was listed first and size second? Or, is there a way I can MAKE it ignore or even retype the list without the file size, then use the ' for /F %%i ' ?

TIA

BTW, what does this do?  2>&1
dir /b
That will avoid DATE/time, etc.

2>&1 says to write any error messages to the same place as the regular messages.

example, if you say
type abc.txt
then abc.txt will be typed to the console, right?
and if there is no file abc.txt, an error message instead.

If you say
type abc.txt >mylog.txt
then abc.txt will be type to mylog.txt. But if there is no file abc.txt then an error message will be typed to the console, not abc.txt.

But if you say
type abc.txt >mylog.txt 2>&1
both will go to mylog.txt.

2> is for errors
1> is normal (nobody ever types the "1" but they could)

Mac
Uh, yep, the tokens stuff should work if you can't avoid the date. What exactly did you use to build the list?

I know of no way to get files smaller than x, such as

dir *.* /size<5K /b /s >Mylist.txt

(bombs out like crazy - LOL)

Thanks for that explanation Mac ...... I'm sure I'll be using it in the future  

Actually, I need the size. I first do a search of all files by K size>> 1my.txt
then sort that by a byte size and exclude certain directories >> 2my.txt
It's from 2my.txt that I need to search the remaining files by string.

TIA Quote

TIA

TIA?  Is there an outstanding question? LOL. I thought I was finished here.
Maybe I misunderstood your previous post...........

Quote
Uh, yep, the tokens stuff should work if you can't avoid the date.

Were you suggesting that tokens will work in 9X?Sorry, my friends tell me 98 does not support
date /t
so I don't know how you get the date there.

Bummer

Mac
Think we got crossed somewhere on what I'm trying to achieve.

I have a text file of filenames with path, and the file size. File size precedes the path/name.

I need to search every file in that text for a string and output the results to another text.

No date involved, and it's my understanding that 9X does not support tokens option, therefore the use of ' for /f %%i in (my.text) do find "string" %%i >> my2.txt' will try to search the string from the filesize rather than the path/filename. Will putting the filesize after the path in my.txt allow it to search the files?

example of current my.txt

19225   C:\windows\filen.ame
19225   C:\progra~1\Norton\filen.ame


if changed to,

C:\windows\filen.ame   19225  
C:\progra~1\Norton\filen.ame   19225  

will %%i search the files for string as if the size isn't even present?
Quote
T
will %%i search the files for string as if the size isn't even present?

I'm pretty sure. The variable, %%i, will be set to the first string up to a space, the default delimiter.

At least I know the following works on NT4:
Code: [Select]echo C:\windows\filen.ame   19225    > z.txt
echo C:\progra~1\Norton\filen.ame   19225    >>z.txt
for /F %%i in ('type z.txt') do (
echo Got a filename
echo It's name is %%i
echo So I am happy
)

Mac

Thanks. I'll give it a try on 9X.
1586.

Solve : Batch file programming?

Answer»

I am putting some error checks into to some batch files that I inherited and need some help with the following:

if not exist \\server\share\folder\%1.txt
   echo cute message
   pause
   goto :finish

Could anyone tell me why this is not working?  The share and server exist.  What is happening is it is falling through and processing the code that follows.  I have deliberately ENTER an incorrect parameter to see if this section works.

 :-?if not exist \\server\share\folder\%1.txt echo "cute message" goto :finish
echo "another cute message"
pause
goto :finish
  
I think there is a basic logic issue with the code.  I think 2k_dummy has the right idea, but it looks like there may be a syntax issue with his code.  Assuming you are running Windows 2000 / XP / 2003 / Vista, you could use the following:
if not exist \\server\share\folder\%1.txt [highlight]([/highlight]
   echo cute message
   pause
   goto :finish
   [highlight])[/highlight]I assumed "inherited" batch files were for real DOS and were real .bat files, rather than .cmd files as used by XP. Real DOS doesn't have XP's CMD extensions and the syntax is very different. Although CMD will run most .bat files, real DOS will RARELY run .cmd files. Batch files in XP should actually be saved with a .cmd extension, and only those intended to run under DOS command.com should be saved with a .bat extension. It seems that, judging from most questions posed on this board, most people don't know the difference between a .cmd file and .bat file.I tried GuruGary's suggestion but it didn't WORK.  Could you come back at me.It's me again.  It worked.... I had another error checking routine in the batch file and I switched the order and voila!  Don't ask me why. Quote

Could anyone tell me why this is not working?

WELL, you probably guessed this from GuruGary's correct response, but anyway here is an explicit answer to your question.

command ---> if not exist \\server\share\folder\%1.txt

tells BAT that if the file does not exist, do NOTHING
which is what will also happen if the file does exist.

After that command finishes doing nothing, it goes on to the next instruction.
command ---> echo cute message

So instead, you want to tell it to do SOMETHING.
command ---> if not exist \\server\share\folder\%1.txt (
tells BAT that if the files exists, do commands until ")" and if the file does not exist, skip everything until the next ")".

Mac

[Well, the parentheses can be nested, so interpret my word "next" in that context]
1587.

Solve : Install without floppy drive?

Answer»

Can anyone help with this---

How can I perform a fresh install of DOS 6.2 on a newly-formatted hard drive on a laptop that has no floppy drive?  I'm assuming that I will have to possibly make a bootable DOS install CD.  Is this right?  If so, how can I go about making such a CD?

Also, I've thought about using a USB floppy drive.  Would this simply require placing a USB driver on the boot disk?How to make a bootable CD DEPENDS on which CD BURNING software you use.  It typically involves starting with a bootable floppy disk, then going to your CD burning software and telling it you want a bootable CD, and it uses the information from the bootable floppy disk when it burns the CD.

For a USB floppy, you shouldn't need any drivers, but the support needs to be in the computer BIOS.  If the BIOS supports it, be sure it is enabled and plug the USB floppy drive in the computer before booting up.  It should boot right to the floppy disk.10-4.  I'll give it a shot with the USB floppy.  Thanks.If that machine is more than 3 or 4 years old chances are that BIOS does not support booting from a USB device...
Post more info on what burner program you have as was requested and we can go further.

patio.  8-)1.  I just checked the BIOS, and this particular system does support booting from USB.

2.  My question REGARDING the bootable CD should have been a little clearer.  I use Nero, and I know how to burn a bootable CD.  My question involves transferring files from the DOS install disks to the bootable CD.  Is the process as simple as transferring the files from the three DOS floppies to a directory, and then using these files to make the bootable CD?  Or is there more involved?If you have the floppy disks, and you have a USB floppy, and your computer supports booting to USB, then why not use that?

If you want to use CD, then I would try a process like this:

  • For the boot image on your CD be sure to include the CD-ROM device driver file, and a line to load it in your CONFIG.SYS (like "device=oakcdrom.sys /d:cd1")
  • Include the MSCDEX.EXE and load it in your AUTOEXEC.BAT (like "mscdex /d:cd1").
  • Then when you burn your bootable CD, you can copy all of your DOS files to the non-bootable part of the CD.
  • When the CD is booting, it should load CD-ROM support and ALLOW you to read the files on the CD so you can copy them to your computer.
Quote
If you have the floppy disks, and you have a USB floppy, and your computer supports booting to USB, then why not use that?

I was having a brain fart.  For some reason, I wasn't even thinking about checking the BIOS for the USB boot option...   :-/Simply copying the files to the machine will not WORK...you have to run setup.exe in order to install DOS.

patio.  8-)
1588.

Solve : Link over serial port?

Answer»

Hi, I need to help a friend with a very old machine still using floppies (12 inches original floppies). I think it would be possible to connect two computers via serial PORT and appropriate cable (a LapLink cable) using an old DOS command that I am unable to remember or find. Thanks to this command two DOS machines can see each other files and then copy them. I hope, in this way to be able to tranfer those old files to a more modern support. Thank you very much for your help, Massimo ([email PROTECTED])I think the command you are looking for is INTERLNK, which works in conjunction with INTERSVR.  They came STANDARD with DOS 6.x.I found some more information here: http://www.microsoft.com/technet/archive/msdos/comm5.mspx ... you have to scroll down the page a ways.Thank you.
Considering the type of floppy my friend has, I fear that its DOS version is earlier than DOS 6.0. I have to add that this command does not ring a bell in my brain so the command should be older and different. And, if not already INSTALLED in the system I do not see any way to do so. Thank you very much anyway, I will continue digging in my memory and Internet.
Thank you, Massimo
Quote

I think the command you are looking for is INTERLNK, which works in conjunction with INTERSVR.  They came standard with DOS 6.x.
i just crashed into this topic. LOOKS like ancient times. when i just started with computerwork (XT 086) there was a program called nortun utility. i used to work with it a lot and it had an option to link computers with serial. works easy and what you need. where to get is another problem.

other option might be something like

xx.txt >com1  (this works)
xx.txt
good luck
1589.

Solve : Password Param for Batch File??

Answer»

Hi all,
I'm sure this question has come up before, but I can't find anything using the search function, so I apologize for the repeat post in advance.

Anyways, onto my actual question:

I wrote a .bat file that opens up several network drives at once.  Everything was going great until someone decided that one of these network drives could only be ACCESSED via admin IDS.  Is it possible to set up a batch file to open a network drive using different logins/passes?

Thanks in advance!Assuming that you are running a command prompt under Windows, the answer is "yes".

If you have the following 2 shares:
Z: as \\server1\share (username = "User" password = "password")
Y: as \\server2\pub (username = "Admin" password = "admin"

You could do:
Code: [Select]net use Z: \\server1\share /user:User password
net use Y: \\server2\pub /user:Admin adminSorry - yes I'm running in WinXP

How would you go about doing it if the drives were not mapped?



I'm not sure why, but if I have the drive already mapped when I log in to the computer (and, yes, it's set up to log in as a different user aka my admin id), when I double click the link I get an error saying the ID/Pass isn't valid.  If I disconnect and remap the drive, I get an error saying I'm already logged in under a different name.
I can only get it to work is when I FIRST map the drive after login.


You can't have the same share mapped as different USERS.  For EXAMPLE, this would not work:

Code: [Select]net use Z: \\server\share /user:Administrator password
net use Y: \\server\share /user:skreap newpasswordThis also would not work:
Code: [Select]net use Z: \\server\share /user:Administrator password
net use Y: \\server\share\dir /user:skreap newpassword
What do you mean "how would you go about doing it if the drives were not mapped"?  Do you mean if the drives ARE already mapped?  If they are NOT mapped, then it should work fine.  If they ARE already mapped, then you may run into the scenario you mentioned, in which case you can disconnect the shares like:
Code: [Select]net use Z: /delete
net use Z: \\server1\share /user:User password
net use Y: /delete
net use Y: \\server2\pub /user:Admin admin

1590.

Solve : how do i make a Batch file run Always-On-Top??

Answer»

I wolud like to run my batch file always on top. Is it possible.

I hate it when my batch file prompts me with a "Press Any Key" and it's minimized.

Can somebody help me with this??Check the files properties. Run maximized.no not there yet...  I can't such a box to check under startup.bat -> properties... any other ideas??Must be XP. That option exists for DOS programs but not for .bat files. If you have access to a w98 machine, copy a .pif file (any one will do) to your machine. Modify it to point to your .bat file and you will have the option to run it in a normal window, minimized, or maximized. And a few more little things that XP don't let you do.thanks... great answer.. i'll LOOK in to it as SOON as i can get my hand on an '98 computer, if i can find oneDo you mean "run Always-on-top" or "not minimized" or "maximized"?

You MENTION both "always-on-top", but then SAY you don't want it minimized.

When calling batch file, you can use the START command to force it to start maximized if that is what you are looking for.  Example:
CODE: [Select]start /max mybatch.bat

1591.

Solve : PLease Help me Exit MS DOS!?

Answer»

I accidentally RESTARTED my computer on MS DOS mode and I can't get out! How do I RETURN to normal Windows?Reboot & tap the F8 key until you get the menu up, then SELECT whatever you want.It should go back to Windows if you type
Code: [Select]EXITfrom the Windows 9x MS-DOS Mode PROMPT.  If not, then just START Windows manually by typing
Code: [Select]WIN

1592.

Solve : Keyboard input through batch file?

Answer»

What would be the command to have f5 and enter entered through a batch file to a program that was just opened with a batch file?There is not one. However, if this is a TRUE DOS batch file, you might use a utility that will STUFF the KEYBOARD BUFFER. Do a google SEARCH for "keyboard buffer stuffer" and see what pops.

edit: Most keyboard buffer stuffers are limited to sixteen characters, as that is length of the keyboard buffer. Some of the better ones will allow an ASCII stuff so that a string can be entered and stuffed.

1593.

Solve : What is your preferred way of checking for parms?

Answer»

Just wondering if people have a favourite WAY of testing for parameters?

Do you just test the total number of parameters, or each one individually?

ThanksHow about

Code: [Select]echo off
if {%1}=={} echo No paramsOr, if you require 5 parms
Code: [Select]echo off
if not X%6==x (
  echo Try again: Too many parms
  goto ADIOS
)
if x%5==x (
  echo Try again: Not enough parms
  goto Adios
)
echo Good Man, you game me 5 parms
:Adios
Mac

1594.

Solve : Why is my FOR loop not working??

Answer»

Hello everyone, just found this forum today and have already searched over 10 pages of history as well as used the search but no luck in the last step.

Here is what I have so far.
I have the contents that are here inside the FOR loop in another .bat file and it tests out ok by itself.
I can't get the FOR loop to call the second procedure OR execute the commands in FOR loop directly.


dir/b ?..*.*.*.job > schedules.dat  (this works)

FOR %%A in (schedules.dat) do  runjob.bat %1 %2 %A

OR-----

FOR %%A in (schedules.dat) do (
set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%
echo %CURDATETIME%

set JOBFILE=%1
set RUNDATETIME=%JOBFILE:~2,12%
echo %RUNDATETIME%

if %RUNDATETIME% LEQ %CURDATETIME% echo OK TO RUN

)

Any help would really be appreciated.
KenI need more information on your code to help.  Please post your results of:
echo %date%
echo %time%
What OS are you running?
Please provide an example of the exact file names of a couple of .JOB files
Please provide the what parameters you are passing to this batch file

Instead of dir/b ?..*.*.*.job > schedules.dat why not use dir /b *.job >scuedules.dat? If the formatting needs to be more specific, I think you can at least minimize it to dir/b ?..*.job > schedules.dat

I can't really troubleshoot very much of the the logic of your code without the information above, but here are some possible issues that I see in your code:

Code: [Select]dir/b ?.????????????.*.*.*.job > schedules.dat  (this works)
 
FOR %%A in (schedules.dat) do[highlight] call [/highlight]runjob.bat %1 %2 [highlight]%%A[/highlight]
 
OR-----
 
FOR[highlight] /f [/highlight]%%A in [highlight]('type schedules.dat')[/highlight] do (
set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%
echo %CURDATETIME%
 
set JOBFILE=%1
set RUNDATETIME=%JOBFILE:~2,12%
echo %RUNDATETIME%
 
if %RUNDATETIME% LEQ %CURDATETIME% echo OK TO RUN
) Thanks for the response, I have tried the suggestions listed and have modified my scripted with the information you asked for.
My ENVIRONMENT is listed in my Signature file WinXPPro and Server2003

Ken


echo off
REM ;---------------------------------------------------------------------
REM ;/T/ Batch queue
REM ;
REM ;/D/ Passing Parameters:
REM ;/D/ Field                         Position
REM ;/D/ ----------------------------- --------
REM ;/D/ Version                       P1       (IE V60)
REM ;/D/ Batch Queue                   P2       (ie dayq)
REM ;---------------------------------------------------------------------
call %CLAIMS%\bat\setup.bat %1

REM Change location to the batch queue folder
cd %QUEUES%\%2

REM Check to see if the queue is running
if not exist schedules.dat goto END

REM Check to see if this job has already started, but not completed
if exist running.dat goto END

REM Set a running flag to stop jobs from being picked up twice
copy %CLAIMS%\bat\exit.bat running.dat

REM List every job file in the Queue and redirect it to a file
REM The results of this command are:
REM 1.200610111230.KEN.j12345.User_Listing.job
REM 3.200610111230.KEN.j12345.Testing_thisProcess.job
REM 5.200609111259.DON.j155.UserSecurity.job
dir/b ?..*.job > schedules.dat

REM Loop thru the file and run the job
FOR /f %%A in ('type schedules.dat') do (
  REM Set up the current date and time
  set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%

  REM show me the results until this works, then remove this line
  echo %CURDATETIME%
  REM 20061016 845  (THIS IS A PROBLEM, the blank in the time)

  REM Check the run time of the job
  set JOBFILE=%A
  set RUNDATETIME=%JOBFILE:~2,12%

  REM show me the results until this works, then remove this line
  echo %RUNDATETIME%

  REM Run the job if the date/time is less than current date/time
  if %RUNDATETIME% GTR %CURDATETIME% goto ENDOFLOOP

  REM Rename the job so it runs and doesn't get picked up again
  move %A %A.bat

  REM Run the job
  call %A.bat > %QUEUES%\%2\logs\%A

  REM Archive the job
  move %A.bat %A.done
:ENDOFLOOP
)

REM Remove the running flag
DEL running.dat

REM ;---------------------------------------------------------------------
:END
OK I GOT IT.....

I had to combined the two suggestions you made and it works for now....not the best way...but it works.

Here is what I have done.



The first file is called from CRON.
echo off
REM ;---------------------------------------------------------------------
REM ;/T/ Batch queue
REM ;
REM ;/D/ Passing Parameters:
REM ;/D/ Field                         Position
REM ;/D/ ----------------------------- --------
REM ;/D/ Version                       P1       (ie V60)
REM ;/D/ Batch Queue                   P2       (ie dayq)
REM ;---------------------------------------------------------------------
call %CLAIMS%\bat\setup.bat %1

REM Change location to the batch queue folder
cd %QUEUES%\%2

REM Check to see if the queue is running
if not exist schedules.dat goto END

REM Check to see if this job has already started, but not completed
if exist running.dat goto END

REM Set a running flag to stop jobs from being picked up twice
copy %CLAIMS%\bat\exit.bat running.dat

REM List every job file in the Queue and redirect it to a file
REM The results of this command are:
REM 1.200610111230.KEN.j12345.User_Listing. job
REM 3.200610111230.KEN.j12345.Testing_thisP rocess.job
REM 5.200609111259.DON.j155.UserSecurity.jo b
dir/b ?..*.job > schedules.dat

REM Loop thru the file and run the job
FOR /f %%A in (SCHEDULES.DAT) do call %CLAIMS%\bat\runjob.bat %1 %2 %%A

REM Remove the running flag
DEL running.dat

REM ;---------------------------------------------------------------------
:END


The runjob.bat file is called from the first file and it works now.
echo off
REM ;------------------------------------------------------------------
REM ;/T/ Run Job (called from batchq)
REM ;
REM ;/D/ Passing Parameters:
REM ;/D/ Field                         Position
REM ;/D/ ----------------------------- --------
REM ;/D/ Version                       P1
REM ;/D/ Batch Queue                   P2
REM ;/D/ Job File                      P3
REM ;------------------------------------------------------------------

REM Set up the current date and time
set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%

REM Check the run time of the job
set JOBFILE=%3
set RUNDATETIME=%JOBFILE:~2,12%

pause
REM Run the job if the date/time is less than current date/time
if %RUNDATETIME% GTR %CURDATETIME% goto END

REM Rename the job so it runs and doesn't get picked up again
move %3 %3.bat

REM Run the job
call %3.bat > %QUEUES%\%2\logs\%3

REM Archive the job
move %3.bat %3.done

REM ;------------------------------------------------------------------
:END



Thanks for you help.
Ken
You're welcome.

1595.

Solve : boot with msdos startup disk?

Answer»

i just made msdos startup disk.. how to run it ?
i insert the disk on the floppy and restart the computer.. but it only process like USUAL and enter my windows xp...Enter the BIOS and change the BOOT order to floppy, CDRom, then HDD...

patio.8-)ohh..THANK you..
You're more than Welcome...STOP by anytime...

patio.  8-)

1596.

Solve : Batch File Creation help needed?

Answer»

Hi,

I am kind of new to batch file CREATION. I am trying to reset the passwords to about 40 odd servers on our network. Rather than doing this manually I thought I would try to do this via a batch file, I am also hoping to run DISK defrag and to an anti-virus scan this way also:

I have created a batch file, see contents below:

for /F "delims= " %%i IN (c:\Scripting\Servers.txt) DO (c:\Scripting\rcmd.exe net user administrator testpassw0rd >> c:\Password.txt)
Pause

The file mentioned Servers.txt is a list of servers listed as follows:

\\lvpwpnas01
\\lvpwpnas02
etc...etc

When I look at the password.txt file once this has been run I get the following result:

"
USAGE: rcmd [server_name [command] ]

Prompts for server_name if  not supplied.   Session is
interactive and is terminated by ctrl-Break or Exit of
remote shell.   Program is terminated by ctrl-Break or
ctrl-C when no session is in progress.

If no command supplied,  session is interactive and is
terminated by ctrl-Break  or Exit  of remote cmd shell

If command is supplied,  remote shell executes  single
command on specified server and exits.

Note : Command line server_name requires leading '\\'s"

Any help would be great...  Where am I going wrong?

Kind Regards, Lee  
Quote

for /F "delims= " %%i IN (c:\Scripting\Servers.txt) DO (c:\Scripting\rcmd.exe net user administrator testpassw0rd >> c:\Password.txt)

Kind of lost me, buddy. What do you expect "delims" to do? Your file apparently has no delimiters. Well, anyway, I guess it doesn't hurt anything.

But you have no %%i inside the DO. So all you will do is repeat the DO as many times as there are lines in your data.

Try this to see what I mean:
for /F  %%i IN (c:\Scripting\Servers.txt) DO (ECHO MyStuff: %%i)
if you omit the %%i, you just get MyStuff repeated.

How about just explain what you would do if there was no BAT file and you were going to sit and enter stuff 40 times. Would you enter this command list:
c:\Scripting\rcmd.exe net user administrator \\lvpwpnas01 >> c:\Password.txt
c:\Scripting\rcmd.exe net user administrator \\lvpwpnas02 >>c:\Password.txt
... (etc.)?

Forget about BAT files and come up with a list of 40 COMMANDS that do what you want. (Of course, start with messing with only 2 servers). When you have them, simply put them in a BAT file and run them. Do it the straightforward way with no tricky FOR-stuff. Then later develop tricky stuff if you just want to play around.

MacI think QBasicMac is right ... you forgot to use  your %%i.  Try this:
Code: [Select]for /F "delims= " %%i IN (c:\Scripting\Servers.txt) DO c:\Scripting\rcmd.exe %%i net user administrator testpassw0rd >> c:\Password.txt
Pause
1597.

Solve : .batch simulating user typing and pressing enter?

Answer»

Hi! I am with a program in Fortran that when executed ask the input FILE name, output file name and a parameter. But I have to do this for many files that have always the same names. So for this I am trying to make a “.bat” file to help me. So I need to know which command can simulate the user typing and pressing enter.
I tried the follow TEXT:

LSQM1.exe      
a00.txt            
b00.txt            
10
But it open the program but insists to ask the input file name—so just the first line is ok… Someone can help me??[ch12288]Please!!!
 :-?Does the Fortran prog read the command line, then prompt the user for input if nothing is supplied? If so, you could just supply the correct parameters. Do you have access to the Fortran SOURCE ? could you modify it to do this ?

If not, then I suggest you use VBSCRIPT, where you can PACK the keyboard buffer with keystrokes

GrahamArigato gosaimashita!!! Thank u very much!!!! :) :)

1598.

Solve : Batch File - automated password input?

Answer»

Hi,

I WANT to create a batch file for starting commands to encrypt a file. Therefore it is necessary to type in a password. This process should be automated.

Example:

C:\GnuPG\gpg -d c:\File\test.txt.gpg

This command line INPUT above is responsible for decrypting a file with the program "GnuPG", wich is an OpenSource tool.
The problem is, that this command WANTS the user to type in a password that was created some steps before. If the password isn't typed in, the file cannot be decrypted.

The password input should be automated, so the user mustn't type the password in.
GnuPG doesn't offer a command which avoids the password input.

Is there a pssibility to avoid typing in the password?It would help if you would explain what you would do if there were no batch file and in terms of that explain what you want the batch file to do.

Mac

Example

To encrypt, I do this
c:\util\ZCrypto MyStuff.txt MyStuff.zzz Mo33jkt
erase MyStuff.txt

This will encrypt MyStuff.txt USING password Mo33jkt and put the result into MyStuff.zzz.

That is too much to type, so I want a batch file to do that. But I don't want to hard-code the password into my batch file as that is a security violation.

What can I do?

======== answer, if that is your question
Your BAT file, zC.bat
Code: [Select]c:\util\ZCrypto MyStuff.txt MyStuff.zzz %1
erase MyStuff.txt
and to encrypt a file, you would enter this at the prompt: Code: [Select]ZC Mo33jkt Quote

Hi,

I want to create a batch file for starting commands to encrypt a file. Therefore it is necessary to type in a password. This process should be automated.
So, is there a command that fills in the password AUTOMATICALLY?
you zipping program should have command options you can use to input password. check with manual of your zip program
1599.

Solve : Comparing two character dates?

Answer»

Ok last problem (I think).

I am comparing two 12 digit numbers (YYYYMMDDHHMM), the GTR doesn't seem to work as it runs a job that is scheduled for next year.

FYI, My O/S and Date Format are in my signature file at the end of my posts.


runjob.bat

echo %1
5.200709111259.DON.j155.UserSecurity.job

REM Set up the current date and time
set CURRENTHOUR=%TIME:~0,2%
if %CURRENTHOUR% LSS 10 set CURRENTHOUR0%CURRENTHOUR%
set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%CURRENTHOUR%%TIME:~3,2%

REM Check the run time of the job
set JOBFILE=%1
set RUNDATETIME=%JOBFILE:~2,12%

echo %RUNDATETIME%, %CURDATETIME%
200709111259, 200610162028

REM Run the job if the date/time is less than current date/time
if %RUNDATETIME% GTR %CURDATETIME% goto END

REM Rename the job so it runs and doesn't get picked up again
move %1 %1.bat

REM Run the job
call %1.bat > %QUEUES%\%QUEUE%\logs\%1

REM Archive the job
move %1.bat %1.done

:END



This process does not go to END it CONTINUES to execute the script
I think the command PROMPT can only handle 32-bit integers.  Assuming that is the CASE, you have to deal with numbers that are between 0 and 4294967295 (or may.  Your date STRING / number of 12 characters is probably just too big.

Maybe try chopping off some insignicicant digits (3 to be safe) from the front and / or back of the number?

Maybe try
if %RUNDATETIME:~2,9% GTR %CURDATETIME:~2,9% goto END
Just be aware that that will only work as long the CURDATETIME and the RUNDATETIME don't get past the year 2042 (assuming my theory about the 32-bit unsigned integers is correct)If you have Python:
Code: [Select]import sys,time,os
jobname = sys.argv[1] #get job name
getdate = jobname[2:14] #get 200709111259
current = time.time() #get current time in seconds
convert = time.strptime(getdate,"%Y%m%d%H%M%S")  
rundate = time.mktime(convert) #convert 200709111259 to seconds
if rundate < current:
        print "Run the job because less than current date/time"
        os.rename(jobname, jobname + ".bat") #rename to .bat
        os.system(jobname + ".bat") #run job

Thanks again GuruGary. That worked.
Of course by the time 2042 comes around....I won't care about this system, as I will be 79.
If this system is still RUNNING....I pitty the fool who has to maintain it....lol

1600.

Solve : Problems using the TIME function?

Answer»

When I use the following set statement before noon, I get a blank in the time (HOURS) portion of the statement.
Any ideas.

set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%


The result is:

20061116 849That is going to depend on the way your regional settings are configured for your time format.  For your particular case, you can probably do this:
Code: [Select]set CurrentHour=%TIME:~0,2%
if %CurrentHour% LSS 10 set CurrentHour0%CurrentHour%
set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%CurrentHour%%TIME:~3,2%if you have Python on windows

Code: [Select]import time
print time.strftime("%Y%m%d%H%m%S", time.localtime())

output:
Code: [Select]'20061017071053'
Thanks guys, I have added to code to the script. I will check it tomorrow morning (when the time is right).

Ken
OK, slight problem with the code supplied by GuruGary.
1) There was a syntax error (missing =)
2) It left a space in between the 0 and 8 (200610170 849)
No problem, the code you gave me was enough for me to solve the problem.

Thanks again. So far so Good

Here is the revised version

REM Set up the current date and time
set CURRENTHOUR=%TIME:~0,2%
if %CURRENTHOUR% LSS 10 set CURRENTHOUR=0%TIME:~1,1%
set CURDATETIME=%DATE:~8,2%%DATE:~3,2%%DATE:~0,2%%CURRENTHOUR%%TIME:~3,2%


As for the Python solution, thanks but I do not want to INSTALL anything on my client machines unless absolutely required. I want to keep the install as NATIVE as possible. I am also reproducing this on a UNIX machine (I have a working version, just have to make it now WORK similar to this now for support reasons).

Thanks again for all your help guys. This site is now part of my development Favourites.
Ken Quote

As for the Python solution, thanks but I do not want to install anything on my client machines unless absolutely required. I want to keep the install as NATIVE as possible. I am also reproducing this on a UNIX machine (I have a working version, just have to make it now work similar to this now for support reasons).
Ken

FYI, you do not need to reproduce if you use scripts made in Python/Perl. Those scripts can be ported to unix with little or no modification at all. Well anyway, its your CHOICE.