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.

5101.

Solve : need newer way of doing Old DOS command?

Answer»

oh, srry.Quote from: just-a-teddybear on APRIL 24, 2008, 08:43:31 PM

EASIEST would be to just copy CHOICE.com from windows 98

"easiest" In the long run the easiest way is the right way.

Quote from: llmeyer1000 on April 25, 2008, 08:30:52 AM

Quote
Choice.com was originally supplied on the Windows 95 install CD, however there are some issues with this version under NT - multiple concurrent invocations of CHOICE will CLOBBER each other. CHOICE.com will also burn a lot of CPU's when in a wait state.
The NT and 2000 Resource Kits contain CHOICE.EXE which behaves a lot better.
In Windows 2003 CHOICE became a built-in command so it is no longer in the resource kit.
http://www.ss64.com/nt/choice.html

According to this guy, it's not such a good idea to use the Win98 version of "choice.com".

Oh radhamurali92,
Did you not look at the site (link above) which warns against using choice.com under NT?
Better to use choice.exe which was written for NT.
5102.

Solve : Batch creation of new folders?

Answer»

Hello again. SCENARIO...10 files in a folder...Is it possible to use a batch command to create a folder for each of the files (with the name of each respective created folder the same as the file) and MOVE the file into it's new folder? Thanksihope its usfl
for /f "tokens=1,2 delims=." %%i in ('dir /b /a-d ' ) do (
MKDIR "%%i"
move "%%i.%%j" "./%%i/."
)

put this CODE will not work correctly if ur files name got . other that the on before the file type for eg the code will not work on this file
a.g.txt Superb...THANKS very much!!!

5103.

Solve : REG COMPARE HELP?

Answer»

How do I check for a value in the registry and based upon weather the registry value exist allow a PROGRAM to be installed. If registry value does exist, don't install a program. (How do I get the return valve from the REG COMPARE into a varable.)Use for then reg query, the file wont be created if the key doesent exist because reg query creates an error..


for /f "tokens=1*" %%a in ('reg query HKCR\exefile\shell\open\command\sss') do echo %%a>>r2
if not exist %cd%\r2 goto installreg query HKCR\exefile\shell\open\command\sss || echo key does not existThank you very much. I used the double pipe command.
This is the opposite

reg query HKCR\exefile\shell\open\command\sss && echo key existsIs there a way to prevent the command results from being DISPLAYED on the screen? /QQuote from: mrische1 on JUNE 05, 2008, 10:15:29 AM

How do I get the return valve from the REG COMPARE into a varable.

The Return Code is returned by the system as a variable already (Errorlevel):
0 - Successful 1 - Failed.
You can use the if errorlevel - goto in your batch file to utilize the results. Test for errorlevel 1 first. If true goto an error message and exit. If errorlevel 1 is false, then the reg query was successful and you can proceed with the installation.

Quote from: mrische1 on June 06, 2008, 11:28:17 AM
Is there a way to prevent the command results from being displayed on the screen? /Q

I couldn't find any way, but adding the code &cls to the line will clear the screen within a few nanoseconds, so that most users will not be able to see the output. (Warning, It may still be possible to capture the output while using the cls.)

The following code tests for the existence of a specific string value name.
[HKEY_CURRENT_USER\Software\7-Zip] "Test"
If you need to check for a specific string value, it may be a bit more difficult.
(You can eliminate the notes, echo's & pauses after testing & debugging.)

Oops: The following code has been edited as of 06/08/2008 1:15 AM EST.
The original posted code did the opposite of what mrische1 requested.
It went to Don't_Instl, when it should have gone to Install. I read the request wrong.

Code: [Select]@echo off

:: Tests for the existense of string value name
reg query HKCU\Software\7-Zip /v Test&cls
if errorlevel 1 goto Install

:: Add Installation Error Message here. IE:
echo Sorry ... The system cannot install your program as desired.
pause >nul
goto End

:Install
:: Add Installation code here. IE:
echo Installation proceeding as requested.
pause >nul

:End
exitQuote from: llmeyer1000 on June 07, 2008, 08:53:19 AM
adding the code &cls to the line will clear the screen within a few nanoseconds

Not without seriously distorting the meaning of "few".
Quote from: Dias de verano on June 07, 2008, 09:06:32 AM
Not without seriously distorting the meaning of "few".

WOW! Dias, I might have expected that out of some others, but I didn't expect you to be so picky. Do you really need to get so creative to increase your post count?

I'm sorry I didn't do any research on the ELAPSED time between lines in a batch file, the processor refresh rate, the refresh rate on the average video card, and any other factors involved!
The inaccuracy in my use of the word "few" might have actually made a difference on a 286, but on most computers in use today the difference is almost neglible, which is what the phrase was meant to convey. (I would have thought that most people would have realized that.) Besides, I think the warning that I posted should have been sufficient to cover the nanosecond error. Quote
(Warning, It may still be possible to capture the output while using the cls.)

No need to get sore, not to say nasty, over being caught out about an elementary error.

A nanosecond is a billionth of a second. Quote from: Dias de verano on June 07, 2008, 11:42:23 AM
A nanosecond is a billionth of a second.

I think most of us know that already. Your posts usually a bit more useful than trying to finding "error" in someones choice of wording. The point was simply that the output would be displayed for only a very brief period of time. (two shakes of a LAMB's tail, a few nanoseconds, a very short period of time.)

I really doubt that the writer of this article meant a few nanoseconds literally any more than I did:
Take a Few Nanoseconds to Explore the Roots of ComputingOk, maybe I went over the top there, but it does bug me when people use terms like that loosely. As in off by a factor of 10,000. Other ones that bug me are using the phrase light year as a measure of time, or saying that using paper "kills rain forests" (it doesn't). I had to research "over the top" before I could reply. Were you referring to the military definition, leaving a safe condition for an unsafe one, the arm wrestling move, or the one referring to "excess, particularly outrageous behaviour or hyperbole."
http://en.wikipedia.org/wiki/Going_over_the_top

If it was the latter, I suppose I was guilty also, particularly in Reply #8. I may have overreacted a bit due to being too thin skinned at times. I really hope that "thin skinned" isn't another one of those expressions that get on your nerves. If it is then I'll probably just have to do something drastic, like reformat my HD. Opps, I just did it again. Sorry about that! I just couldn't resist.

I hope mrische1 gets back with us soon and gets this thread back on track. Any more deviation on our part, & we may soon be accused of hijacking!

Oops: Now here's an error worth fixing. In Reply #6 the posted code has been edited as of 06/08/2008 1:15 AM EST.
The original posted code did the opposite of what mrische1 requested.
It went to Don't_Instl, when it should have gone to Install.

Quote from: mrische1 on June 05, 2008, 10:15:29 AM
If registry value does exist, don't install a program.

I read the request wrong. I read it as if "Do not install unless the value does exist.
5104.

Solve : Renaming files with DOS using part of the original name?

Answer»

I've managed to find the errror, it was a problem of carelessly copying & pasting

Thanks a LOT for your HELP QUOTE from: Richard GORE on May 14, 2008, 09:18:08 AM

copying & pasting
i would expect you to understand what the script doing.
5105.

Solve : were can you get DOS Shell that came with version 4??

Answer»

does anybody know were i can GET DOS Shell that came with VERSION 4 and later? You can download the Supplemental Disk directly from Microsoft. This version is for DOS 6.22 but was the only one I could find.

Good luck.
SRRY but after i installed it DOS Shell wasnt working. Any other ideas?QUOTE from: macdad- on June 07, 2008, 12:40:49 PM

Srry but after i installed it DOS Shell wasnt working. Any other ideas?

Installed it on what? DOSShell is a component of DOS. Did the supplemental disk provide all the following files: DOSSHELL.COM DOSSHELL.EXE DOSSHELL.GRB DOSSHELL.INI DOSSHELL.VID DOSSWAP.EXE DOSSHELL.HLP?

If I remember correctly, DOSShell installed with DOS, not as a separate package.

Any error messages? Did it crash Windows Explorer?

Wait it works! Thanks Sidewinder Aparrently i accendently renamed one of the files that prevented setup to install but it works now! Thanks!
5106.

Solve : run command on many files?

Answer»

Good day all..

Hope this isn't too much of a newbie question. I am trying to run a command line on a SERIES of files, e.g. command -i input.ext -o output.ext

Should I use pipe for this? Or get a list of files in the folder first? There are several hundred files that need to be processed.

Thanks in advance...use this
mkdir outputfils
for /f "delims=" %%i in ('dir /b /a-d') do (
command -i %%i -o out%%i
move "out%%i" "./outputfils/."
)

u should move the file the command create to a sub folder so that the for loop will take it again and go in an infinit loop
Excellent, thank you.

Needs a bit of REFINING on my PART, as there are two files for each bit of data, with different extentions, of which in only need one file as the input name, and a single file for both is generated, but those are only minor bugs, as everything is working as it should. Going to take a while though, it's about 500GB Quote from: andrewgerm on May 14, 2008, 08:50:51 AM

Going to take a while though, it's about 500GB

i thing u will smile like that when it finish successfully
and if not i will be like this
At the moment, I'm not even breathing
Everyone knows thing always fail at 98%...i think u have the hope
just don't be depressed
2% STILL a good ratio It worked... Im' happy...

Thanks again all. Been a while since I did any sort of in depth batch programming...
5107.

Solve : Help...Any DOS command can get string from file ??

Answer»

Hi,

I wish to writea BAT file which able to get a string from one file. For example, I have a file named :helloworld.cpp. I wish to get a string "SingTel" in the helloworld.cpp file. How can I do tat? Any dos command ALLOW me to do so...

Million thanks in advance.

Regards,

Adrianyes U can

find "SingTel" filepath/helloworld.cpp Hi,

Thanks for your reply, I knew there is a "find" command. however, what i wish to do is to "get" the string and replace it somewhere else. For example, I need to get the "Singtel" string and replace it into another file.

Besides, what if my string is get from combobox? Can the DOS command retrieve that? For example, the string i get is as below:

Code: [Select]String^temp=comboBox1->SelectedItem->ToString();

So what DOS command can I use to retrieve the string "temp" and replace it into another file?

Million thanks.it will depend on whether the word "SingTel" is constant word in your file, or whether its unknown at the time of "getting it"
If its constant, you can use find as demonstrated and if its found, you can be sure the word Singtel is there. If its unknown, then its a different story, as you need to know where it appears. Show a sample of your helloworld.cpp file.Hi,

Thanks for your reply, if the string "Singtel" is constant word then how can I use "find" command to get the string? I mean get the string" Singtel" and put it into another file. I tried the "find" function, it only find out the requested string in the file, my QUESTION is how to get the string and put it into another file.

For example, if there is a string "Singtel" (constant word) in helloworld.cpp, how can i get the string and put it into test.txt?

Thanks in advance.if the constant "Singtel" is in the file and the find command found it, then proceed on to the file you want to manipulate and insert "Singtel" into it. Hi,

i m a newbie in MS-DOS, can anyone give me an example on how to insert the string i found into a file? For example, I found a string "Singtel" and how can I insert the the string into line 2 of file hello.cpp.

Million thanks in advance.

5108.

Solve : how to make file splitter??

Answer»

hi friends,

i am not asking the actual logic for, HOWEVER i just want to know what commands should be used to write/read data to/from the files.
my question is not limited to text data however for for binary data also(like .dat files).

regards
sanYour question does not MAKE any sense. Please rewrite it so it does.
Quote from: san_crazy on May 11, 2008, 06:19:07 AM

hi friends,

i am not asking the actual logic for, however i just want to know what commands should be used to write/read data to/from the files.
my question is not limited to text data however for for binary data also(like .dat files).

regards
san

you need a a better language that KNOWS how to read files and cater for number of bytes read. A vbscript snippet
Code: [Select] Dim fso, f, MSG
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
ReadTextFileTest = f.Read(10)

the example above reads in 10 characters. You can do a loop to read in the rest, then write them out to INDIVIDUAL files.
is it not possible using dos shell script?
5109.

Solve : Wrong Output?

Answer» FIXED.
5110.

Solve : Web Loading?

Answer»

resolved.The type command expects [drive:][path]filename parameters not internet addresses. Batch coding is not designed for the Web, but you have alternatives on your SYSTEM that will scrape and print the web page data:

Code: [Select] Set objIE = CreateObject("InternetExplorer.Application")

objIE.Navigate("HTTP://batchmedia.0moola.com/text.txt")
Do Until objIE.ReadyState = 4
WScript.Sleep 100
Loop

objIE.document.parentwindow.clipboardData.SetData "text", objIE.Document.Body.InnerText

WScript.Echo objIE.Document.ParentWindow.ClipboardData.GetData("text")
objIE.Quit

Save the script with a vbs extension and RUN from the command prompt as CSCRIPT scriptname.vbs

Good luck. Quote from: SIDEWINDER on June 07, 2008, 07:51:32 AM

The type command expects [drive:][path]filename parameters not internet addresses. Batch coding is not designed for the Web, but you have alternatives on your system that will scrape and print the web page data:

Code: [Select] Set objIE = CreateObject("InternetExplorer.Application")

objIE.Navigate("http://batchmedia.0moola.com/text.txt")
Do Until objIE.ReadyState = 4
WScript.Sleep 100
Loop

objIE.document.parentwindow.clipboardData.SetData "text", objIE.Document.Body.InnerText

WScript.Echo objIE.Document.ParentWindow.ClipboardData.GetData("text")
objIE.Quit

Save the script with a vbs extension and run from the command prompt as cscript scriptname.vbs

Good luck.
amazing
works like a dream
thanks very much
5111.

Solve : I have a problem at month end.?

Answer»
I'm new to this and have written a simple batch file that runs every day and copies a month-to-date performance file to a 'current_month' folder.

When a new month starts I need it to copy the previous months final file from 'current_month folder to the 'archive' folder before saving down the first set of data for the new month.

No problem until the last day of the month is say Thursday 31st - I pick up that days data on Friday 1st. did i mention that I don't work weekends ? Which means it is the 3rd before I am back to run the new months first file.

How can I get the script to detect the month has changed from the last time it was run and automatically run the end of month routine before carrying on with the first file of the new month ?

Many thanks for your attention and help.
Trevwhen you reach the last day of the month, just copy the file to the archive folder. You don't have to wait to till next month when the job is run to do that. Quote from: trevorg2 on May 09, 2008, 09:32:22 AM
How can I get the script to detect the month has changed from the last time it was run and automatically run the end of month routine before carrying on with the first file of the new month ?


I won't write a batch file for you but i can suggest the logic of how to do this.

First set up your archive and populate it with last month's files.

Run the batch every work day.

Write it so that it READS the system date and isolates the month. Then it checks in a certain location to see if there is a file called e.g. thismonth.txt. If there is no such file there, it means that this is the first time you have run the batch, so it writes e.g. "05" to thismonth.txt. If there is such a file there, then the batch has been run at least once already. Open the file and compare the 2 digit string it contains with the current month number contained in the system date. If they are the same, then the month end has not passed yet and you can exit. If they are not the same, then we are into the next (or another!)* month and you can do your archive stuff and finally write the new month value to thismonth.txt. Then you can do whatever you need to do next.

* We assume for this simple DESCRIPTION that you never leave a gap long enough between runs so that more than one month end has passed.


Quote from: ghostdog74 on May 09, 2008, 09:49:51 PM
when you reach the last day of the month, just copy the file to the archive folder. You don't have to wait to till next month when the job is run to do that.

Read his post, he mentions the problem of a month change happening on a non-working day when he is absent.
Quote from: Dias de verano on May 10, 2008, 02:25:35 AM
Quote from: ghostdog74 on May 09, 2008, 09:49:51 PM
when you reach the last day of the month, just copy the file to the archive folder. You don't have to wait to till next month when the job is run to do that.

Read his post, he mentions the problem of a month change happening on a non-working day when he is absent.

Read his post also, that his batch file copies files everyday. So when it reaches the last day of the month, either a 30th or 31st, (or 28/29) , just do an extra copy of the file to the archive directory. There's no need to extra code to detect a month. change. Or am i misinterpreting what OP wants? Quote from: ghostdog74 on May 10, 2008, 04:15:48 AM

Read his post also, that his batch file copies files everyday.

Every working day, I should think, in view of this that he wrote:

Quote
did i mention that I don't work weekends ? Which means it is the 3rd before I am back to run the new months first file.

But it is ambiguous, so let's wait for him or her to clarify.Thanks for your replies - I'm okay to copy the last days file into the archive - I have a second 'EOM' batch file set up to do that.

However, If I go on vacation at month end/crossover my cover could easily just run the daily file and end up over-writing the month end file ....Not good news !!

I just wondered if I could somehow put the daily and EOM files together so that the super file could just be run - and it would sort out whether to continue saving to the 'current folder' or archive to the EOM folder before continuing.

I love you all
Trev

If this sort of thing is really mission-critical then you are being (I am sorry to be blunt) foolishly cheeseparing to do things this way, getting IT SUPPORT from a web forum. Budget for some IT support costs.
Dias de verano - You are right !!

Also your earlier solution will work perfectly - Many thanks for that - I was toying with something similar but couldn't get it to work - your solution avoids the problem I has neatly.

As for IT support ................. In our place ?? You are joking I'd be OLD and GREY before that happened !!

Look after yourself
and thanks also to everyone else who chipped in - we can call this one resolved.

Trev


5112.

Solve : Possible Idea?

Answer»

My game currently loads THINGS by checking if the file is there and if it is then setting a variable to certain value.

I am wondering if you could make one text file that contains DIFFERENT information on each line, for EXAMPLE:
Code: [Select]Jacob
MP5
Level 3
And then make the batch file read from one line e.g the second line.
then set a variable to what the second line contained.
For Example:
- Batch file reads second line of jacob.txt
- Batch file sets the second line of data to %weapon%.
- Batch file then echos %weapon%

I want to know if this is possible, and if so how to do it.

The only good thing about my system at the moment is it only loads the guns that i specify so people cannot enter their own guns.

thank you.

You can have something like this:

file1.bat
Code: [Select]set name=Jacob
set weapon=MP5
set level=level 3
file2.bat
Code: [Select]call file1.bat
echo %weapon%
pauseQuote from: Carbon Dudeoxide on June 07, 2008, 04:07:01 AM

You can have something like this:

file1.bat
Code: [Select]set name=Jacob
set weapon=MP5
set level=level 3
file2.bat
Code: [Select]call file1.bat
echo %weapon%
pause

How would i get the game to output the data into file1.bat please.
Honestly, batch isn't one of my strongest areas but I've had a lot of experience with it.
Try this (as an idea):

file1.bat
Code: [Select]set name=Jacob
set weapon=MP5
set level=3
file2.bat
Code: [Select]@echo off
call file1.bat
echo Hello %name%, you are using an %weapon% and you are currently on level %level%.
pause
cls
echo please enter your name
set /p name= :
cls
echo Please enter a weapon
set /p weapon= :
cls
echo Please enter a level number
set /p level= :
cls
del file1.bat
echo set name=%name%>>file1.bat
echo set weapon=%weapon%>>file1.bat
echo set level=%level%>>file1.bat
echo Successfully saved
pause
exit
Side NOTE: you don't need the ':' when using the set command (set /p level= :). I just put it there because I think it looks better.Quote from: Carbon Dudeoxide on June 07, 2008, 04:15:01 AM
Honestly, batch isn't one of my strongest areas but I've had a lot of experience with it.
Try this (as an idea):

file1.bat
Code: [Select]set name=Jacob
set weapon=MP5
set level=3
file2.bat
Code: [Select]@echo off
call file1.bat
echo Hello %name%, you are using an %weapon% and you are currently on level %level%.
pause
cls
echo please enter your name
set /p name= :
cls
echo Please enter a weapon
set /p weapon= :
cls
echo Please enter a level number
set /p level= :
cls
del file1.bat
echo set name=%name%>>file1.bat
echo set weapon=%weapon%>>file1.bat
echo set level=%level%>>file1.bat
echo Successfully saved
pause
exit
Side note: you don't need the '[glow]:[/gow]' when using the set command (set /p level= [glow]:[/gow]). I just put it there because I think it looks better.

Thanks, But I'll keep my old way as it took a good week to perfect.
And it will take a long TIME to incorporate this successfully.
Thanks.
No problem. (again)
5113.

Solve : Checking For A Folder Then Creating It.?

Answer»

I need to check for a folder called data, which is in the same area as the batch file.
If it doesn't exist i need the folder 'data' to be created.

I have TRIED this so far, with no success:
Code: [Select]IF NOT EXIST data\. (
> data\.
)
Code: [Select]if exist data (
md data
)
Try that.Code: [Select]if NOT exist data (
md data
)

FIXED, Thanks.
Yeah, my bad. I forgot the NOT.

Quote from: Carbon Dudeoxide on June 07, 2008, 03:27:45 AM

Yeah, my bad. I forgot the NOT.


No Worries, Thanks.
And What Does MD Do?MD is pretty much the same as MKDIR.
They both create directories (A.K.A, folders)Quote from: Carbon Dudeoxide on June 07, 2008, 03:32:34 AM
MD is pretty much the same as MKDIR.
They both create directories (A.K.A, folders)
OKAY, Thanks, Your A Big Help.
No problem. Glad to help.

One thing I should ADD (if you didn't already know this), In Command Prompt, if you TYPE command /?, it will tell you what the command is and what it does.

Example:
Quote
C:\Documents and Settings\Brian> MD /?
Creates a directory.

MKDIR [drive:]path
MD [drive:]path

If Command Extensions are enabled MKDIR changes as follows:

MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:

mkdir \a\b\c\d

is the same as:

mkdir \a
chdir \a
mkdir b
chdir b
mkdir c
chdir c
mkdir d

which is what you would have to type if extensions were disabled.
Quote from: Carbon Dudeoxide on June 07, 2008, 03:37:39 AM
No problem. Glad to help.

One thing I should add (if you didn't already know this), In Command Prompt, if you type command /?, it will tell you what the command is and what it does.

Example:
Quote
C:\Documents and Settings\Brian> MD /?
Creates a directory.

MKDIR [drive:]path
MD [drive:]path

If Command Extensions are enabled MKDIR changes as follows:

MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:

mkdir \a\b\c\d

is the same as:

mkdir \a
chdir \a
mkdir b
chdir b
mkdir c
chdir c
mkdir d

which is what you would have to type if extensions were disabled.
Thanks Brian Hehe, no problem Jacob.
5114.

Solve : Displaying Data From A .txt?

Answer»

I am in the PROCESS of making a simple TEXT based game.
My Batch file outputs the current data by means of:
Code: [Select]cls
echo Saving Data, Please Wait...
DEL %b%.txt
echo %a% >> %b%.txt
echo %b% >> %b%.txt
echo %c% >> %b%.txt
echo %d% >> %b%.txt
echo %e% >> %b%.txt
echo %f% >> %b%.txt
echo 1 >>%b%.txt
echo MP5 >>%b%.txt
echo Silencer >>%b%.txt
echo GAS Mask >>%b%.txt
echo SAS "Corporal Smith's Unit" >>%b%.txt

Although I Would Like To Reload This When They Ask For It:
I have this so far
Code: [Select]:LOADGAME
cls
echo Please Enter Your First Name:
echo.
set /p firstname=First Name:
echo.
echo <%firstname%.txt //this does not work
pause >nul

I Would like the data to be displayed like:

--Current Statistics--
Surname: (THEIR SURNAME)
First Name: (THEIR FIRST NAME)
Occupation: (THEIR OCCUPATION)
and so on.....

Any Help Appreciated.can this actually be done?Instead of this:
Code: [Select]echo <%firstname%.txt
I think you want this:
Code: [Select]type %firstname%.txtI think you are looking for this:

Code: [Select]echo Surname: %surname% >>"C:\Documents and Settings\%username%\Desktop\file.txt"
echo First Name: %firstname% >>"C:\Documents and Settings\%username%\Desktop\file.txt"
echo Occupation: %occupation% >>"C:\Documents and Settings\%username%\Desktop\file.txt"UNLESS the batch prog is working in the same directory as the files.Yes, otherwise it would just be %surname% >> File.txti want to load the data not output it.

thats why i used < not >> or >.Quote from: KenJackson on June 01, 2008, 10:52:32 AM

Instead of this:
Code: [Select]echo <%firstname%.txt
I think you want this:
Code: [Select]type %firstname%.txt

Thanks Very Much.
5115.

Solve : problem to catch errorlevel?

Answer»

Dear All, i'm newbie. I tried to make a batch file to backup data(files). But before it copy the files which are needed to backup, it checks first whether there is a data to backup and give information...
here with is part of my coding:

:BACKUP new or changed files
:: Check whether there are files to backup
ECHO. Checking files...
set task=There were no files to backup
xcopy %src% %dest% /d /s /y /q /l|find " 0 "
if not errorlevel 1 goto JOBDONE
set task=Backup new or changed files
echo. %task% in %src%
xcopy %src% %dest% /d /y /s
goto JOBDONE

==============
JOBDONE, only echo the message EV "task".
the idea is using find "0" to get information whether there are files to backup. and i use "errorlevel" for this.

i tested DIRECTLY in command promt, find "0" would give 0 if no file and 1 if found the file(actually charater 0) from xcopy list result using /l switch.
But the problem in my batch file, it always catched errorlevel 1 even it is no file to backup( 0 file).

i'm using ms dos ver:5.1.2 and XP SP2

thank before.....
FOR /F "tokens=1" IN ('DIR /B %src%') DO XCOPY %src% %dest% /d /y /s

If there is nothing in the %src% directory, then nothing is copied, no need for ERRORLEVEL checking.
Quote from: ProgressDBA on June 05, 2008, 10:38:20 AM

FOR /F "tokens=1" IN ('DIR /B %src%') DO XCOPY %src% %dest% /d /y /s

If there is nothing in the %src% directory, then nothing is copied, no need for ERRORLEVEL checking.


Thank u for your respond,

Could u help me to explain ur logic of that code?
Because if i were not mistaken, it won't copy,only if %src% directory is empty.
But the idea of my coding is that there will always be files in %src% dirct. and xcopy /d /s /y /l gives display list whether there is a file changing or update than check with "find" to KNOW whether there is file update and than need to backup...
And also i want to give message to the user...that there is no file need to backup because no file changed.

Or maybe ur code has worked like my idea, just perhaps i didn't understand it well?

once again thank u...The flaw in the original logic is twofold. One there is no leading space in the string you're using in the find instruction. If you fix the first ("0 "), any numeric that is a multiple of ten will produce an errorlevel not zero.

Code: [SELECT]:BACKUP new or changed files
:: Check whether there are files to backup
echo. Checking files...
set task=There were no files to backup
for /f %%i in ('xcopy %src% %dest% /d /s /y /q /l') do (
if %%i==0 goto JOBDONE
)
set task=Backup new or changed files
echo. %task% in %src%
xcopy %src% %dest% /d /y /s
goto JOBDONE




Quote from: Sidewinder on June 06, 2008, 05:49:46 AM
The flaw in the original logic is twofold. One there is no leading space in the string you're using in the find instruction. If you fix the first ("0 "), any numeric that is a multiple of ten will produce an errorlevel not zero.




Wow....u r right, now my code is working...
I didn't realize that.
And i tried ur coding, it's nice, worked very well, and i never thought about that logic which is very cool ...(need more practice)
also this forum...
i think i'll use yours...

Thank u very much....

5116.

Solve : how to echo % in dos?

Answer»

hey all,

anyone know how I can echo the % character in dos?

I'm guessing I need the exit charactor???

any ideas???

cheersWhat exactly do you want to do?

By DOS I assume you mean Command Prompt?

Do you want to show the symbol '%' or what?yeah, I need to show the % sign.

I'm running the output of a unix tool to a txt file and one of the SWITCH's has a % in it. Which the command prompt isn't seening.

but I could GET the below to work I'd have the rest sorted;

Code: [Select]set var=%
echo %var%
pause

cheers for the quick REPLY!!
Try this:

Code: [Select]@echo off
set var=%%
echo %var%
pausearh, spot on.


cheers for that!!

No Problem.This has to be the FASTEST ever recorded reply and fix!!!!


Nice The simple answer is, to echo a % sign, write it twice in a batch file

echo %%

will show % on the screen.

5117.

Solve : long path names in FOR loop?

Answer»

I have a little BATCH file that doesn't seem to recognize the long pathname. Looks like this...
for %%f in (c:\Matt Files\*.dwg) do START /WAIT "c:\Program Files\AutoCAD 2006\acad.exe" %%f /b c:\AutoCAD Ref\LSP Files and Script Routines\Sript File Routines\TitleBlockReplace.scr

I get an error message "Windows canot find 'c:\Matt'.
I'm new to this - sorry.Code: [Select]for %%f in ('dir /s /b "c:\Matt Files\*.dwg"') do START /WAIT "c:\Program Files\AutoCAD 2006\acad.exe" "%%f" /b "c:\AutoCAD Ref\LSP Files and Script Routines\Sript File Routines\TitleBlockReplace.scr"

Using quotes is recommended whenever the possibility exists that a path/filename will have embedded spaces.


I pasted your resonse - I got a response of...

Windows cannot find 'dir'
and then
Windows cannot find '/s'
and then
Windows cannot find '/b'

What else could be WRONG?



Rus7755Sorry about that:

Code: [Select]for /f %%f in ('dir /s /b "c:\Matt Files\*.dwg"') do START /WAIT "c:\Program Files\AutoCAD 2006\acad.exe" "%%f" /b "c:\AutoCAD Ref\LSP Files and Script Routines\Sript File Routines\TitleBlockReplace.scr"

Pasted it where? If using the code in a batch file, the code posted is CORRECT. If pasted at the command prompt, use single % symbols on the f variable (both of them).




I just pasted into notepad where the batch was written. I'm just double-clicking the file to execute it.

I don't understand the first /fdirectly after the FOR. Also the pathname for the directory of files to be used has a nest double quotes inside single quotes. Is that my mistake?


Thanks for the help,
Rus7755Quote

I don't understand the first /fdirectly after the FOR. Also the pathname for the directory of files to be used has a nest double quotes inside single quotes.

"c:\Matt Files\*.dwg" has embedded space(s) and therefore needs to be quoted.

The /f switch tells the for instruction that it will be processing a file-set (no quotes), a command (single quote), or a string (double quotes). In this case a command (dir) will be processed, therefore single quotes are needed.

This explains why you have a double quotes string nested in a single quote string. The paths after the wait switch and the /b switch also have embedded spaces. The %%f variable could go either way with spaces, so quoting the variable does no harm.

Is the code throwing an error or is everything fine?



It might be EASIER to debug your file if you run from the command prompt and not by double-clicking the file. For starters the cmd window will STAY open.
5118.

Solve : Messenger?

Answer»

Hey guys, i've taken a break from programming because i'm starting to suck at it. So i came back to batch for a bit and this my 'messenger' all it uses is the messenger service and so on. Hope you enjoy it. Code: [Select]@echo off
title Messenger *V1.0*


NET START "Messenger"


echo ----------
echo -----My----
echo --Messenger-
echo -----V1.0----


echo This program will let you communicate VIA: I.P. address or Username on a

PC

:C

echo ----------
echo -------The-
echo ---------Menu-
echo ---------------

echo 1. My.Messenger *V1.0*
echo.
echo 2. Log Off Messenger
echo.
echo 3. Options
echo.
echo 4. Extra's
echo.
echo 5. Freinds List
echo.
set choice=
set /p choice=Type the number to continue:

if '%choice%'=='1' goto A
if '%choice%'=='2' goto B
if '%choice%'=='3' goto D
if '%choice%'=='4' goto E
if '%choice%'=='5' goto J

goto C



cls
:A
echo -__-__-__-__-__-
echo -__-__-Messenger-__-
echo -__-__-V1.0-__-__-__-__-
echo -__-__-__-__-__-__-__-__-__-


set /p u=User/I.P.:
set /p m=Message to User/I.P.:

net send %u% %m%
m

echo 1. Return to Messenger
echo.
echo 2. Go to the menu

set choice=
set /pchoice=Choice to continue:
if '%choice%'=='1' goto A
if '%choice%'=='2' goto C


goto A

:B
echo ----------
echo -----Log---
echo ------------
echo -----Off-----
echo Logging off...
echo Are you sure you want to log off?
set choice=
set /p choice= If so please type 1 if not PRESS ENTER:
if '%choice%'=='1' goto C
echo.
echo.
echo.
echo Good Bye!
pause

goto






:D
echo ----------
echo ---Options-
echo ------------
echo -------------

echo Welcome to the Options Menu!

echo 1. Edit Foreground & Color
echo.
echo 2. Return to the Menu

set choice=
set /p choice=Type the number for the coresponding Options:
if '%choice%'=='1' goto G
if '%choice%'=='2' goto C
pause

goto D



:E
echo ----------
echo ---Extras--
echo ------------
echo -------------

echo Welcome to the Extra's Page!

echo Extra's to view:

echo 1. About
echo.
echo 2. Utilities
echo.
echo 3. Return to Menu
echo.
set choice=
set /p choice=Type the number for the coresponding options:
if '%choice%'=='1' goto F
if '%choice%'=='2' goto I
if '%choice%'=='3' goto C
pause

goto end

:end

:F
echo ----------
echo -----About-
echo ------------
echo -------------

echo Made by: Clipper34

echo Date/Time completed: 16:47:24.50 04/28/2008

echo Options:

echo 1.Return to Menu
echo.
echo 2.Log Off

set choice=
set /p choice=Type the number for the numbers shown above:
if '%choice%'=='1' goto C
if '%choice%'=='2' goto B


goto end


:end

:G
echo ----------
echo ---Color---
echo ---Page-----
echo -------------

echo Welcome to the Color page!

echo Here is the list of COLORS:
echo 0 = Black
echo 1 = Blue
echo 2 = Green
echo 3 = Aqua
echo 4 = Red
echo 5 = Purple
echo 6 = Yellow
echo 7 = White
echo 8 = Gray
echo 9 = Light Blue
echo A = Light Green
echo B = Light Aqua
echo C = Light Red
echo D = Light Purple
echo E = Light Yellow
echo F = Bright White

echo Now the numbers represent the background color and the letters represent

the foreground color (the text)

set choice=
set /p choice=To continue press '1' to go to the menu press '2':
if '%choice%'=='1' goto H
if '%choice%'=='2' goto C

goto end

:end

:H
echo ----------
echo -----Colors-
echo ----Config---
echo --------------
echo ---------------

echo Use the color code listed in the Color Page to refer to your option of

changing the colors

set color=
set /p color= What color scheme would you like?:
if '%color%'=='1' Color A0
if '%color%'=='2' Color A1
if '%color%'=='3' Color A2
if '%color%'=='4' Color A3
if '%color%'=='5' Color A4
if '%color%'=='6' Color A5
if '%color%'=='7' Color A6
if '%color%'=='8' Color A7
if '%color%'=='9' Color A8
if '%color%'=='10' Color A9

if '%color%'=='11' Color B0
if '%color%'=='12' Color B1
if '%color%'=='13' Color B2
if '%color%'=='14' Color B3
if '%color%'=='15' Color B4
if '%color%'=='16' Color B5
if '%color%'=='17' Color B6
if '%color%'=='18' Color B7
if '%color%'=='19' Color B8
if '%color%'=='20' Color B9

if '%color%'=='21' Color C0
if '%color%'=='22' Color C1
if '%color%'=='23' Color C2
if '%color%'=='24' Color C3
if '%color%'=='25' Color C4
if '%color%'=='26' Color C5
if '%color%'=='27' Color C6
if '%color%'=='28' Color C7
if '%color%'=='29' Color C8
if '%color%'=='30' Color C9

if '%color%'=='31' Color D0
if '%color%'=='32' Color D1
if '%color%'=='33' Color D2
if '%color%'=='34' Color D3
if '%color%'=='35' Color D4
if '%color%'=='36' Color D5
if '%color%'=='37' Color D6
if '%color%'=='38' Color D7
if '%color%'=='39' Color D8
if '%color%'=='40' Color D9

if '%color%'=='41' Color E0
if '%color%'=='42' Color E1
if '%color%'=='43' Color E2
if '%color%'=='44' Color E3
if '%color%'=='45' Color E4
if '%color%'=='46' Color E5
if '%color%'=='47' Color E6
if '%color%'=='48' Color E7
if '%color%'=='49' Color E8
if '%color%'=='50' Color E9

if '%color%'=='42' Color F0
if '%color%'=='43' Color F1
if '%color%'=='44' Color F2
if '%color%'=='45' Color F3
if '%color%'=='46' Color F4
if '%color%'=='47' Color F5
if '%color%'=='48' Color F6
if '%color%'=='49' Color F7
if '%color%'=='50' Color F8
if '%color%'=='51' Color F9
pause
set choice=
set /p choice=Do you want to go back to the menu?if so press '1' if not press

'2':
if '%choice%'=='1' goto C
if '%choice%'=='2' goto H


goto H

:end

:I
echo ----------
echo -Utilities-
echo -----Page---
echo -------------

echo Welcome to the Utilities page!

echo Here you can access Random Utilities through this page

echo Your choices are:

echo 1. Paint - Everyone loves to paint!
echo.
echo 2. Calculator - For those math problems
echo.
echo 3. Command Prompt - To configure your OS and other options
echo.
echo 4. Return to the Menu - Go back to the menu
echo.

set choice=
set /p choice= Type the corresponding number for the choices:
if '%choice%'=='1' start %SystemRoot%\system32\mspaint.exe
if '%choice%'=='2' start %SystemRoot%\system32\calc.exe
if '%choice%'=='3' start %SystemRoot%\system32\cmd.exe
if '%choice%'=='4' goto C

echo

-------------------------------------------------------------------------
echo 5. Go back to Utilities
echo.
echo 6. Return to menu:
echo.
set choice=
set /p choice= Do you want to look at another Utility or go to the menu?:
if '%choice%'=='5' goto I
if '%choice%'=='6' goto C


goto end

:end

:J
echo ----------
echo --Freinds--
echo --List------
echo -------------

echo Welcome to the Freinds List you can View/Add and Delete Freinds

echo Your choices are:

echo 1. Add Freinds
echo.
echo 2. Delete Freinds
echo.
echo 3. View Freinds
echo.
echo 4. Return to Menu
echo.
set choice=
set /p choice= What would you like to do?:
if '%choice%'=='1' goto K
if '%choice%'=='2' goto L
if '%choice%'=='3' goto M
if '%choice%'=='4' goto C



goto end

:end



:K
echo ----------
echo -------Add-
echo ---Freinds--
echo -------------

echo Welcome to the Add Freinds Page!

cls
type freindslist.txt
SET /P SAVES= Enter desired text:
echo %SAVES%>>text.txt
msg * Text Saved!
goto J



:L
echo ----------
echo ---Delete--
echo ----Freinds-
echo -------------

msg * You must exit the Messenger for the changes to take place

echo 1. Return to Menu
echo.
echo 2. Return to Freinds List
echo.
echo 3. Continue by pressing ENTER
echo.
set choice=
set /p choice= What would you like to do?:
if '%choice%'=='1' goto C
if '%choice%'=='2' goto J
pause
edit type text.txt

goto L

:end

:M
echo ----------
echo -----View--
echo ---Freinds--
echo -------------

echo 1. Return to the Menu
echo.
echo 2. Return to the Freinds List
echo.
echo 3. Continue by pressing ENTER
pause
echo.

type text.txt
echo.
set /p loads=

goto J

:end




























5119.

Solve : games in dos messed up?

Answer»

When I try to play a game in dos part of the top i on the BOTTOM, and the bottom is elevated so if I move my mouse up, it goes to the top, which is at the bottom. How do I fix this?please someone answerYou waited only 20 minutes before bumping! This is not a chat room. How are you starting DOS?

You've also left out tons of valuable info on the machine;OS the GAMES and what happened prior to this that would certainly help in the troubleshooting process.yes plz tell us the NAME of the game and ur System's specs

5120.

Solve : find special characters?

Answer»

I am hopefull you guys can help me out with this question.

Do you know of a way to search a string of characters and find out if any are "special characters"?

example: if a string contains any of the following `[emailprotected]#$%^&*()_+-={}|[]\:";'<>?,./ then do [command] else [command]CHECK out the findstr command. Where does this string exist? If from a file you can check if not A-Z, and not a-z and not 0-9. If a character is not one mentioned, it must be a special character.

Good luck. Quote from: Sidewinder on May 12, 2008, 11:51:58 AM

Check out the findstr command. Where does this string exist? If from a file you can check if not A-Z, and not a-z and not 0-9. If a character is not one mentioned, it must be a special character.

Good luck.

This is the commands I am trying to run with some others to check for length and such. I have the string I am working with set as the varable choice.

rem checks to see if special used
set errorlevel=
echo %choice% |findstr /i /r "[^0-9]"
if /I %errorlevel% lss 1 goto spchar

it works but it also seems to be grabbing everything not just the special charactors.

any ideas?It seems the findstr command does not support multiple ranges in the regex expression.

The good news is there is always a way to build a better mousetrap. For this solution I had to reach deep into the DOS gene pool and then fast forward to the present.

Code: [Select]@echo off
set spechar=N
echo;;|choice /c=%choice%; set > p.bat
CALL p.bat
for %%v in (%[%) do call :check %%v
set [=
del p.bat > nul
if %spechar% equ Y echo This string: %choice% contains special characters
goto :eof


:check
echo %1 | findstr /r "[0-9]" > nul
if %errorlevel% EQU 0 goto :eof
echo %1 | findstr /r "[A-Z]" > nul
if %errorlevel% EQU 0 goto :eof
echo %1 | findstr /r "[a-z]" > nul
if %errorlevel% EQU 0 goto :eof
set spechar=Y

This works with the DOS version of choice not the NT version.I couldn't find a source for the choice command but you may have better luck with Google. You can also borrow a copy from another machine.

Good luck.
vbscript
Code: [Select]Set objArgs = WScript.Arguments
strToCheck = objArgs(0)
WScript.Echo strToCheck
Set objRE = New RegExp
objRE.Global = True
objRE.IgnoreCase = False
objRE.Pattern = "[^a-z0-9]+"
Set colMatches = objRE.Execute(strToCheck)
For Each objMatch In colMatches
WScript.Echo "At position " & objMatch.FirstIndex & " matched " & objMatch.Value
WScript.Quit(2)
Next

usage: save the above as script.vbs and on command line :
Code: [Select]C:\test>cscript /nologo script.vbs "s^dfs"
s^dfs
At position 1 matched ^

C:\test>echo %errorlevel%
2
I have it working now but it is giving me some weird results

here is my code

Code: [Select]@echo off
GOTO itemB

:nowearly
cls
echo time not valid
echo please do not use between midnight and 1 AM
echo.
goto LOOPA

:spchar
cls
echo time not valid
echo please do not special charctors
echo.
goto itemB

:badtime
cls
echo time not valid
echo please do not add a : to the time
echo.
goto itemB

:badtimesc
cls
echo time not valid
echo please do not add a ; to the time
echo.
goto itemB

:badtimep
cls
echo time not valid
echo please do not add a . to the time
echo.
goto itemB

:badtimes
cls
echo time not valid
echo please make sure time is in 24 hour format
echo see example below
echo.
goto itemB

:badtimel
cls
echo time not valid
echo please do not use LETTERS in time
echo.
goto itemB

:tooearly
cls
echo time not valid
echo please do not use between midnight and 1 AM
echo.
goto itemB

:overtime
cls
echo time not valid
echo please do not set time greater then 2400
echo.
goto itemB

:minover
cls
echo time not valid
echo please do not set minutes greater then 60
echo.
goto itemB


:itemB
set spechar=N

rem gets user input and set a variable for the input
SET Choice=
echo Type the time in military (24 hour) format and press Enter:
echo Example: 1300 is 1:00 PM
SET /P Choice=time:

rem only accepts the first 4 characters entered
set choice=%choice:~0,4%

REM sets the number of characters to length
echo %choice%> %temp%\string.txt

REM get the file size in bytes
for %%a in (%temp%\string.txt) do set /a length=%%~za

REM do some batch arithmetic
set /a length -=3
if /i %length% lss 4 goto badtimes

REM clean up temp file
del %temp%\string.txt

rem sets the time to variables to be checked
set choice1h=%choice:~0,1%
set choice2h=%choice:~1,1%
set choice1m=%choice:~2,1%
set choice2m=%choice:~3,1%
set choicemm=%choice:~2,2%

goto check


REM checks for special charctors
:check

rem checks to see if a : is used
set errorlevel=
echo %choice% |findstr /i /r "[:]"
if /I %errorlevel% lss 1 goto badtime

rem checks to see if a ; is used
set errorlevel=
echo %choice% |findstr /i /r "[;]"
if /I %errorlevel% lss 1 goto badtimesc

rem checks to see if a . is used
set errorlevel=
echo %choice% |findstr /i /r "[.]"
if /I %errorlevel% lss 1 goto badtimep

echo %choice1h% | findstr /r "[0-9]" >nul
if %errorlevel% EQU 1 goto lettest

echo %choice2h% | findstr /r "[0-9]" >nul
if %errorlevel% EQU 1 goto lettest

echo %choice1m% | findstr /r "[0-9]" >nul
if %errorlevel% EQU 1 goto lettest

echo %choice2m% | findstr /r "[0-9]" >nul
if %errorlevel% EQU 1 (goto lettest) else goto timetest

:lettest
echo %choice% |findstr /i /r "[a-z]" >nul
if /I %errorlevel% lss 1 goto badtimel

echo %choice1h% |findstr /i /r "[a-z]" >nul
if /I %errorlevel% lss 1 goto badtimel

echo %choice2h% |findstr /i /r "[a-z]" >nul
if /I %errorlevel% lss 1 goto badtimel

echo %choice1m% |findstr /i /r "[a-z]" >nul
if /I %errorlevel% lss 1 goto badtimel

echo %choice2m% |findstr /i /r "[a-z]" >nul
if /I %errorlevel% lss 1 goto badtimel

:spcset

set spechar=Y

if %spechar% equ Y goto spchar

:timetest
rem validating time
if /I %choice% GEQ 2400 goto overtime
if /I %choicemm% GEQ 60 goto minover

rem makes sure that time is not set between midnight and 1 am
set choicea1=%choice:~0,2%
set choicea2=%choice:~0,3%
set errorlevel=
echo %choicea1% |findstr /i /r "/C:00"
if /I %errorlevel% lss 1 goto tooearly
echo %choicea1% |findstr /i /r "/C:000"
if /I %errorlevel% lss 1 goto tooearly

goto end

:end
echo done
pause
[\code]

if you place a ; in the 3rd number place it goes to the following section:

:badtimes
cls
echo time not valid
echo please make sure time is in 24 hour format
echo see example below
echo.
goto itemB


do you have any ideas as to why this is happening?Quote
It seems the findstr command does not support multiple ranges in the regex expression

In any other script language regular expressions can contain multiple ranges, so you can exclude upper and lower alphas and numerics and by the process of elimination conclude that at least one character is special.

Sending the entire string to the findstr command with a single range only proves you have upper, lower and numerics but tells you nothing one way or the other whether you have any special characters.

The choice command, deprecated in NT machines but brought back in Vista is quirky enough to allow you to parse a string into it's component characters. The logic posted assumed each character was not special, then checked each character separately. If the checks fell through all the logic, the flag was flipped indicating that at least one character was special.

Unless you want to do this with VBScript, you can download the choice command here.

Good luck.

There is a version of choice as a .exe file. Testing shows only the .com version of choice works as shown in my previous post.
wbrost, you need to be aware of a problem with set /a. It treats numbers with a leading zero as being octal and not decimal, which means that 08 and 09 will be rejected and there will be an error.

In my opinion batch language data validation sucks. You can break mosts scripts by inputting the '&' character, the so-called "poison character". Something like QBASIC is better.

Ghostdog will be along in a minute with a VBscript.



Quote from: Dias de verano on May 14, 2008, 12:41:23 PM
Ghostdog will be along in a minute with a VBscript.
already done. Post #4
5121.

Solve : telnet probelm...?

Answer»

Hey guys, i've been having an issue with telnet. I've started the telnet service on both of my laptops, and when i use my laptop to telnet to the other one it doesn't work. Any ideas? Thanksdid u CHECK and SEE if you TYPE the right parameters in

telnet [host [port]]

for ethernet USUALLY just use port 80 and you would have to choose which laptop is the host and which is the guest.

so it would look like this
Code: [Select]telnet (Network ID of host laptop) 80thanks macdad it works perfect nowyour quite welcome

5122.

Solve : Cann't install windows after formatitng?

Answer»

Hi, I run fdisk and think I did it okay,but at the end I see c: but nothing more, I try to put a XP CD to install windows, but it seems not to READ it bcause it SAY 'no cdrom.
After I format my harddisk, what should I do to install windows, or is it so that I am doing something wrond during formatting?RESTART computer. Go into the BIOS and select to boot from CD-ROM. Exit BIOS.


5123.

Solve : barcode printer command?

Answer»

i try to run a barcode printer USING .bat file ,but it will read the 1st line only
example
this is the WORKING command when i type using dos


when i run using .BAT file..it will only SHOW the 1st line..


this is my .bat code


any suggestion?

5124.

Solve : Reading a file through DOS commands?

Answer»

Dear members,
I want to read a text file and pass each line in it as parameter to a MSDOS batch(.bat) file through DOS commands. Is it poosible through DOS commands??
Pls help me. You really need to post your OS in this forum as all versions of the batch processor are not the same. This may work on your machine:

Code: [Select]@echo off
for /f %%v in (textfile.txt) do (
batchfile %%v
)

Hi friend,
Thanks for reply.

i ran your code in DOS command prompt, I am getting error like this: "%%v was unexpected at this time"

D:\>@echo off
for /f %%v in (textfile.txt) do (
%%v was unexpected at this time.
1.bat %%v
%1
)

"1.bat" contents
--------------
echo %%1
---------------

My objective is to read each line and print it by the bat file which has received the line string as a parameter.

I am new to these commands.
Can you please correct my code.

Thanks in advance..!

[OS using : Microsoft windows Server 2003]Your original post MENTIONED a batch file. Variables in a for LOOP use single % at the command prompt and %% in batch files.

Code: [Select]for /f %v in (textfile.txt) do (
1.bat %v
)

The above code is for the command line only.

Good luck.

Hi dude,
It worked . I had spent more than a day in serach engines for this, no where i had found solution(may be i m not efficient)
Thank u so MUCH for your help I need the command to move files, but only those that contain a specific string,
example sonia_444_yyy

well in this case I would be searching for sonia, SINCE I know this is the good initial string

5125.

Solve : unwanted repeat?

Answer»

okay my sci teacher GOT this document in a email and EVERYTIME he OPENS it it says the exact time it is when you open it, it says this

"Hey, i knew you would open this at exactly (whatever time it is) blah blah blah..."

so he found what the code was ( "{ /@ "h:mm am/pm" }"
also i tried to open a batch file through a batch file through a batch file...why didnt it work? i think it was because i ahve to type
"c\:Documents and Settings\"ME"\pt1.bat"
i think its cuz theres SPACES in the doc and settings but i tried without spaces still didnt work so i tried with underscores for spaces no worky, is this cuz the location can only be 8 char long, i mean i should have the 255 char count i have Win XP pro SP2 Quote

"c\:Documents and Settings\"ME"\pt1.bat"

It should be "C:\Documents and Settings\"ME"\pt1.bat"

If the batch file is located in the same place as the other, you just type

Code: [Select]start pt1.bat
Otherwise:

Code: [Select]start "" ""C:\Documents and Settings\"ME"\pt1.bat"

[i]Note, you need the double '""'[/i]

Quote
everytime i type edit it says " (the code up there) is not a system command blah blah" and now i cant edit any of my batch files whats goin on?
What exactly do you mean? Are you talking about the EDIT command in the Command Prompt?
You can use notepad to edit batch files.
5126.

Solve : A minor tweak to a loop.?

Answer»

I could use a little help. For reasons that my peers KNOW, I need to get the shutdown -a COMMAND to repeat infinitely. I can get it to happen, but the command prompt window remains open. Is there any way that I can get it to run and have the window not appear?

Is this possible at all?

What are those "reasons that your peers know"? May we be permitted to know them too? Once we do, we can make an informed decision on what to tell you. Being secretive is not the best way to persuade people to help you.

Sorry. They were watching at the time I initially wrote that. There have been 'random' shutdowns. This is mostly because the local computers aren't that secure from internal sources. Anyways, it seems that at the most inopportune moment, we get a shutdown thrown at us. My response to this was a shutdown -a batch. The issue, though, is that it leaves the window open. I can supply codes if you need.Are you trying to bypass shutdowns initiated by your network admins?No. I work for a small company where we are 'all responsible for our computers'. That's boss language for 'there aren't enough of you to make it worth hiring a dedicated sysadmin.'

Anyways, my coworkers keep initiating shutdowns. I have the following running:

Code: [Select]@echo off
:start
shutdown -a
goto start
Unfortunately, this keeps the window open. What I want to know is if there's a way of essentially running the same file, but without it being in an open window.Surely your colleagues would be wise to attend to their work instead of misusing their employer's IT equipment to play silly pranks on their co-workers? Where I work, people have been (rightly) fired for such things. Maybe a WORD with that boss of yours would be a more practical way of stopping people trying to shut down your PC if that is what you mean. Surely that is very irresponsible BEHAVIOUR? You might have work in progress that would be lost. Your boss might be interested to know how people are using the time that he pays for, and also following on from that, very interested to know how he could get the same amount of work (or more!) done for less money by employing only responsible people!

I was cautious before because we get a lot of queries on here from people who are, - how SHALL I put this? - quite young, and they seem to want to know how to play tricks on their fellow workers or students such as ejecting their CD trays, shutting down their PCs, spamming them with network messages, or help to avoid site blocks, etc, etc.

Without addon software, there is no built in way to run a batch file in "hidden" mode. You can use the start command with the /MIN switch to run a batch file minimized to the taskbar.
Thanks to llmeyer1000 for making the point that I can just compile it into an exe.

I can't believe I didn't think of that.

5127.

Solve : Batch file for renaming all files inside a folder?

Answer»

does anybody know the COMMAND??u can use the command MOVE
move filename filenam2
if u need to rename all files inside a folder do this bat file

@echo off
for /F "tokens=1* delims=." %%i in ('dir /b /a-d') do (
if "%%j" NEQ "bat" move ".\%%i.%%j" ".\%%i55.%%j" )

now in stead of 55 u put the STRING u want to add to the name of ur files
and u should put the file inside the folder u want to chang its files name

Go to Dos prompt
I usually change the directory to the folder with the files in it
then use the rename command

c:\test>rename text*.* newname*.*

everything beginning with the filename 'text' will be renamed to 'newname' retaining any * fillers.

textxxx.doc will be newnamexxx.doc
text33mn.txt will be newname33mn.txt
textdada.xls will be newnamedada.xls

hi pwekn68

in ur command u should have something shared between many folder so u can rename them
but withen mine u don't

i hope that jedix10 can find a solution for his issue His question was RENAMING all files within a folder. Nothing about subfolders.Quote from: .bat_man on May 06, 2008, 03:17:54 PM

hi pwekn68

in ur command u should have something shared between many folder so u can rename them
but withen mine u don't

i hope that jedix10 can find a solution for his issue

i am sorry i typed folder instead of files
Quote from: pwekn68 on May 06, 2008, 12:56:36 PM
Go to Dos prompt
I usually change the directory to the folder with the files in it
then use the rename command

c:\test>rename text*.* newname*.*


You may also use ? in PLACE of the *. This is useful if you have a specific naming convention where you do not want to change specific characters within the filename.

For Example:

I had two files named: "igsg09op.4" and "igsg08op.5" (Yes weird extensions, but my program requires them to run properly.)
However I needed to change the names to all uppercase. Using the ? in place of the "09" or "08" within the name allows this to work:

c:\> rename igsg??op.* IGSG??OP.*

The two files changed respectively.

IF I were to use only asterisks:

c:\> rename igsg*op.* IGSG*OP.*

I would get the following filenames:

IGSG08op.4OP and IGSG09op.5OP

By the way, Thank you pwekn68. Your method helped me solve my more complex naming convention. Kudos!
5128.

Solve : Copy the names of root folder, sub folders and the files with in?

Answer»

there is nothing with the comand i think its SOMTHING related to the OS he is using or some SECURITY issues'Path' is just the example.

I would post 'C:\path' and he would change it to (for example) 'C:\documents and settings' or something.

it says "file not found" but I saw the contents of the file

" Volume in drive E is DATA
Volume SERIAL Number is ACA9-FF62" make sure that the file may be heddin for that u have to do
dir c:\path /a /sAnyways, I am not getting....thanks for your helpWhen I plug in my flash drive (E:\), it works fine.

dir E:\ /s>>"C:\file.txt"

It is possible the code is right but the flash drive isn't allowing this.can u try to make the same command on an other path tried in c and e DRIVES as wellFirst of all, does the dir E:\ /s work at all? Is the problem saving the file?

Quote

" Volume in drive E is DATA
Volume Serial Number is ACA9-FF62"
BTW, this is normal, I have this too.I think so, not able to troubleshoot...
see u tomorrow
5129.

Solve : Using .bat to move a file with an unknown file name?

Answer»

System: Win2k3 Server

We are receiving a nightly FTP upload to a specific directory. The file's name changes based on several criterion; none of which I have control over. Basically, the date is PART of the file name, but there are other numbers that appear pretty random from the filesystem perspective.

Anyway, I want to accomplish a couple of things:
1. copy the file to a network share (\\ipaddress\share)
2. MOVE the file to a local directory so it can be decrypted (pgp); the file WOULD be renamed in the move

I'm hoping to put this into a sheduled task in win2k3 so that I don't have to intervene. What I'm struggling with is how to work with a file that I don't know it's file name? I only know the extension, but I'm certain I need the file's name in order to perform the copy/move/rename operations.

Any suggestions?

Thanks,
JonCode: [Select]@ECHO off
for /f "tokens=* delims=" %%v in ('dir /s /b c:\specificdirectory') do (
copy "%%v" \\ipaddress\share
move "%%v" c:\localdirectory
ren "%%v" newname
)

You'll need to change the directory and newname placeholders.

Quote from: Sidewinder on May 09, 2008, 05:12:40 AM

Code: [Select]@echo off
for /f "tokens=* delims=" %%v in ('dir /s /b c:\specificdirectory') do (
copy "%%v" \\ipaddress\share
move "%%v" c:\localdirectory
ren "%%v" newname
)

You'll need to change the directory and newname placeholders.


Awesome! I changed it slightly:
Code: [Select]@echo off
for /f "tokens=* delims=" %%v in ('dir /s /b c:\path\to\file') do (
copy "%%v" \\192.168.1.111\path\to\archive\directory
move "%%v" "C:\path\to\local\staging\newfilename.extension"
)

Thanks for such a fast reply
5130.

Solve : How to read the properties in a dos file?

Answer»

I do have a set of properties in the file, which needs to be made used in my .BAT file.

Say my data.properties file contains

key1=value1
key2=value2

How can I access these values in my .bat file.

Advance THANKS for the help.

I'm guessing the commands are:
set key1=value1
set key2=value2

If so, you can use them with the call command.

Code: [Select]call C:\documents and settings\%username%\Desktop\keys.bat
Try that and see if it works or not. Yep it works. The reply was really fast . Thanks a lot.No problem.

Any other QUESTIONS, you KNOW where to find us.

5131.

Solve : add comma in the begining of each row by batch?

Answer»

hello, how to add comma in the begining of each row by using batch file?
thanksWhat exactly do you mean?

Where do you want the comma to be?o, i have solved this problem~~thanks
and i would like to ask another QUESTION:

If I want to import 10 files in a folder, how to write a batch script in order to import those 10 files? I mean how to read the number of files in that folder and write a loop for doing that?

thanks!!try this
for /f "tokens=1" %%i in ('dir ^| find " File(s)"') do echo %%io,i m sorry i can't test it?why it will print the count of files in a directory u are in i have made your command into a BAT file, a.bat. then i RUN it. It displays the command only but not the variable.C:\**\Desktop\ttt>a.bat

C:\**\Desktop\ttt>for /F "tokens=1" %i
in ('dir | find " File(s)"') do echo %i

C:\**\Desktop\ttt>echo 4
4

can u make a DIR command on ur prompt and show me the result it prints

5132.

Solve : help fixing computer?

Answer»
- About a month ago, my antivirus program(Avast) said it detected a virus in MEMORY.
- SUGGESTED I shut computer down and reboot.
- Did so.
- Everything went fine with no RESULTING errors or messages.

- When attempted to return MS-DOS prompt level, received message that it couldn't fine
the .pif file.
- Researched and found it still there.

- Tryed to recreate an ms-dos prompt.
- Then receive message that system couldn't find command.com.
- Tryed c:\windows\system32\command.com.
- System still couldn't find it, even though file is there.

- Then ran virus check; spybot checkers(Adaware, Spybot, SpyDoctor, etc.), etc.
- They did find instances of viruses, etc. and removed them.

- Ran defrag, checkdisk, scandisk, etc. etc.
- Check registery for .EXE and exefile settings. All o.k. here
- Rebooted computer.
- Tryed other user logons.
- Tryed creating new user logon.

- Still same results.

- Did extension research into problem.
- Can't find anything that works.
- Did extensive research on this board concerning MS-DOS.
- Have not found anything new that is helping.


- NOTE:
----
- Can get cmd command to work and get me to DOS level.
- However that are certain dos command I use frequently such as 'edit' 'fd(changes date of file(s))', etc.
- These are not working.


- I don't want to do a system restore at this point. I just want to fix the problem.

- B-T-W.
- Have Compaq Presario V5305.
- WINDOWS XP MEDIA EDITION - VERSION 2002 - SERVICE PACK 2
- Only have RESTORED disk - did not come with OEM disks.

- Any suggestions......

-thanks
-dan
Double Post.
Please see your other post for replies.

Topic Closed.
5133.

Solve : how to calculate time lapse?

Answer»

Greeting,
I wrote tthis batch file which run a program(3Dmark06), at the beginning of the batch file I issue a Echo command which output the start time (s.txt), at the end of the batch file I also issue an Echo command which output the end time(e.txt). I would like to know if DOS Batch file can the read the end time(s.txt) and minus the Start time and output the total time which my program has run(3Dmark06).
Please see my batch file for more details.
Any help is greatly appreciated.
Thanks/Vansky03


@echo off
Echo Start Time: %date% %time%>e:\testprog\3dmark06\s.txt
call e:\testprog\3dmark06\3Dmark06 -repeat=35 -res=1024x768 -gtall -cpuall -featureall -batchall -vsprofile=2_a -psprofile=2_a 3dmark.3dr -verbose
echo End time: %date% %time%>e:\testprog\3dmark06\e.txt
copy log*.* 3d.html

Rem Change log file from html to txt here
call e:\testprog\3dmark06\htmlastext.exe /run "e:\testprog\3dmark06\convert.cfg"
rem Look for passed clue here
find /I "End test" e:\testprog\3dmark06\3D.txt
find /I "32768 Triangles" e:\testprog\3dmark06\3D.txt
if errorlevel 1 GOTO :FAIL
if errorlevel 0 goto :PASS
goto end

:Fail
echo Results: Test Failed >e:\testprog\3dmark06\fail.txt
copy e:\testprog\3dmark06\s.txt+e:\testprog\3dmark06\fail.txt+e:\testprog\3dmark06\e.txt e:\testprog\3dmark06\3dmarkh.txt
goto end

:Pass
Echo Results: Test Completed and Passed >e:\testprog\3dmark06\Pass.txt
copy e:\testprog\3dmark06\s.txt+e:\testprog\3dmark06\pass.txt+e:\testprog\3dmark06\e.txt e:\testprog\3dmark06\3dmarkh.txt
:EndNormally I would just write that batch code does not handle date/time arithmetic very well. And that is very true when compared to other scripting languages.

I found this on the net, and if precision is not your main goal, this is close enough for most government work:

Code: [Select]@echo off
setlocal enableextensions
:: store start time
for /f "tokens=1-4 delims=:.," %%t in ("%time%") do (
set starttime=%time%
set /a start100s=%%t*360000+%%u*6000+%%v*100+%%w
)

:: wait for 10 seconds to simulate batch processing
ping -n 11 127.0.0.1>nul

:: retrieve stop time
for /f "tokens=1-4 delims=:.," %%t in ("%time%") do (
set stoptime=%time%
set /a stop100s=%%t*360000+%%u*6000+%%v*100+%%w
)

:: test midnight rollover. if so, add 1 day=8640000 1/100ths secs
if %stop100s% lss %start100s% set /a stop100s+=8640000
set /a tooktime=%stop100s%-%start100s%

echo (%~nx0) started: %starttime%
echo (%~nx0) STOPPED: %stoptime%
echo (%~nx0) elapsed: %tooktime:~0,-2%.%tooktime:~-2% seconds
Source

You should be able to work in your own code where the ping currently exists.

i wrote this code and it works for day laps and i hope it got no bugs

@echo off
for /f "eol=E tokens=5,6,7 delims=.: " %%i in ('echo.^|time') do (
set h1=%%i
set mi1=%%j
set s1=%%k
REM the following code is to avoid the 08 and 09 due to the set command consider REM any number that starts REM with 0 as octal and there is no octal digit 9 or 8
REM the easiest way is to convert them to hex so that they will got there same REM valyes as decimal 8 and 9
for %%r in (08,09) do (
if %%i equ %%r set /a h1= 0x%%i
if %%j equ %%r set /a mi1= 0x%%j
if %%k equ %%r set /a s1= 0x%%k
))
set /a t1=3600*%h1%+60*%mi1%+%s1%
for /f "eol=E tokens=1,2,3 delims=/" %%i in ('date /t') do (
set d1=%%i
set m1=%%j
set y1=%%k
for %%r in (08,09) do (
if %%i equ %%r set /a d1= 0x%%i
if %%j equ %%r set /a m1= 0x%%j
if %%k equ %%r set /a y1= 0x%%k
))
REM put ur code instead of the ping
ping -n 4 10.10.10.127 >nul

for /f "eol=E tokens=5,6,7 delims=.: " %%i in ('echo.^|time') do (
set h1=%%i
set mi1=%%j
set s1=%%k
for %%r in (08,09) do (
if %%i equ %%r set /a h1= 0x%%i
if %%j equ %%r set /a mi1= 0x%%j
if %%k equ %%r set /a s1= 0x%%k
))
set /a t2=3600*%h1%+60*%mi1%+%s1%
for /f "eol=E tokens=1,2,3 delims=/" %%i in ('date /t') do (
set d2=%%i
set m2=%%j
set y2=%%k
for %%r in (08,09) do (
if %%i equ %%r set /a d2= 0x%%i
if %%j equ %%r set /a m2= 0x%%j
if %%k equ %%r set /a y2= 0x%%k
))
set /a t_con=%t2%-%t1%
set /a d_con=%d2%-%d1%
set /a m_con=%m2%-%m1%
set /a y_con=%y2%-%y1%
if %t_con% LSS 0 (for /l %%q in (1,1,24) do (if %d_con% EQU %%q set /a t_con=%%q*86400+%t_con%)
goto done)
if %t_con% GEQ 1 (for /l %%q in (1,1,24) do (if %d_con% EQU %%q set /a t_con=%%q*86400+%t_con%))
:done
set /a hour=%t_con%/3600
set /a min=(%t_con%-(%hour%*3600))/60
set /a secnds=%t_con%-(%hour%*3600)-(%min%*60)
echo ur code toke %secnds% seconds ,%min% min and %hour% hour
echo it passed throw %d_con% days, %m_con% month, %y_con% years
pauseQuick hack - will give wrong answer if start is before midnight and end is after midnight.

Code: [Select]@echo off
set timenow=%time%
set nhh=%timenow:~0,2%
set nmm=%timenow:~3,2%
set nss=%timenow:~6,2%
set ncs=%timenow:~9,2%
if "%nhh:~0,1%"==" " set nhh=%nhh:~1,1%
if "%nmm:~0,1%"=="0" set nmm=%nmm:~1,1%
if "%nss:~0,1%"=="0" set nss=%nss:~1,1%
if "%ncs:~0,1%"=="0" set ncs=%ncs:~1,1%
set /a nssecs=%nss%
set /a nmsecs=60*%nmm%
set /a nhsecs=3600*%nhh%
set /a ntimesecs=%nssecs%+%nmsecs%+%nhsecs%
set /a ncentisecs=100*ntimesecs
set /a ncentisecs=%ncentisecs%+%ncs%
set /a msec1s=%ncentisecs%*10

REM start process to be timed
REM -------------------------

echo Wait a while then press a key
pause

REM -------------------------
REM end of process to be times

set timenow=%time%
set nhh=%timenow:~0,2%
set nmm=%timenow:~3,2%
set nss=%timenow:~6,2%
set ncs=%timenow:~9,2%
if "%nhh:~0,1%"==" " set nhh=%nhh:~1,1%
if "%nmm:~0,1%"=="0" set nmm=%nmm:~1,1%
if "%nss:~0,1%"=="0" set nss=%nss:~1,1%
if "%ncs:~0,1%"=="0" set ncs=%ncs:~1,1%
set /a nssecs=%nss%
set /a nmsecs=60*%nmm%
set /a nhsecs=3600*%nhh%
set /a ntimesecs=%nssecs%+%nmsecs%+%nhsecs%
set /a ncentisecs=100*ntimesecs
set /a ncentisecs=%ncentisecs%+%ncs%
set /a msec2s=%ncentisecs%*10

set /a elapsed=%msec2s%-%msec1s%
echo elapsed time %elapsed% milliseconds
hi Dias de VERANO

i just want to draw ur attention if ur code handle day laps like if the program started at 23:59:00 and ended at 00:02:00 of the next day i think it will give wrong data.
Quote from: .bat_man on June 04, 2008, 08:15:43 AM

hi Dias de verano

i just want to draw ur attention if ur code handle day laps like if the program started at 23:59:00 and ended at 00:02:00 of the next day i think it will give wrong data.


I just want to draw your attention to the first line of my post.
hi dias
i dont think it was there when i read ur code
for that i didnt notice itThank you much, will try and see how it work
Regards/VanskyThank you Sidewinder, your code work just great.....
Regards/Vansk03
5134.

Solve : Start Minimised?

Answer»

Is there a way to minimise an application from a batch file after it has opened up in a window?

I have an application that ALWAYS STARTS in a window EVEN when I USE the /min switch.
It is irritating, because I want it to run in the background.
Example:
Code: [Select]start "title" /MIN "application.exe"

download CMDOW and STUDY its switches.
Works perfectly! Thanks!

Am I going to have a problem with antivirus software that CLASSIFIES cmdow as a virus?
Well, I use AVG 7.5 Free and it doesn't mind CMDOW.

5135.

Solve : How to print from a DOS file to Laser Jet??

Answer»

Just bought a new computer and laser printer.
The operating system is Vista
For some reason, I cannot print the DOS files onto the laser.
I had been able to print from XP onto the same model laser printer.
Any suggestions.
Thank You
Can you tell us the Printer Model.

Have you tried downloading the driver for the printer from the manufacturers website?

Quote

For some reason, I cannot print the DOS files onto the laser.
What do you mean by this?The Printer is HP Laserjet P2015d
I have downloaded the printer driver from HP website to the computer, which is also an HP Pavilion Slimline, Vista Operating System.
My DOS program is used for financial balance sheets, etc and has historical data
The information and program is on disc, which is attached to the computer by cable.
I need to print the information on this disc
Therefore, I upload, work on it and then print it out
I cannot print out since the laser jet is not accepting the print command from the dos program
Thank youwell first your printer has to be connected to ur computer by means of a Parrallel port or serial port, not a Firewire or USB nor Ethernet because DOS was not made around the time Firewire, USB, and Ethernet were developed and so DOS isnt compatible with these Ports but is compatible with serial and parrallel. So once you have your printer connected to your computer using a serial or parrallel then in Command Prompt, type in this "copy .* lpt1" this prints your file to your printer if its connected by means of parrallel, now if you have it connected by serial port then type this "copy .* COM1" just remember that DOS doesnt support Firewire, USB, nor Ethernetif the printer is a modern raster type of printer, it will just plain not print from DOS.
I HAVE gotten DOS to print to both USB and Ethernet Printers, "BUT" you have to do it through a share. You need to map LPT communications to the printer share. Also make sure the share is simple without spaces like HP2015 so your share is \\COMPUTERNAME\HP2015. Obviously enter your computer name in place of computername, and create the share to say HP2015 without spaces. DOS mapped printers dont like spaces, if you want to split its share name up you can use _ underscores!!!

I also run old accounting software that NEEDS to print via DOS since the program is a 10 YEAR old priceless application that still serves a purpose without spending like $10,000 to replace it for our food store, where I am an IT Professional, and I used the trick below to make ours work to a shared printer on a computer that has its printer connected via ethernet.

We hit this problem when the accounting department replaced their old HP4000 Laserjet which was communicating through LPT1 with a Savin 27 Color printer that is USB and Ethernet only!!! ((( and I didnt buy that Savin piece of junk...I call it the Spendin 27 color printer for as many problems as they have had with it and its Ricoh guts )))

This below should make it work for you... You will want to set the lpt2 shown below to the LPT that the DOS program is trying to print to...I'd try LPT1 first, and if LPT1 doesnt work, try LPT2


1. Click Start, and then click Run.
2. In the Open box, type cmd, and then click OK.
3. Type net use lpt2 \\computername\HP2015 /PERSISTENT:yes, and then press ENTER.
4. To quit the command prompt, type exit, and then press ENTER.

http://support.microsoft.com/kb/314499
5136.

Solve : Assigning Mouse Buttons to other purposes.?

Answer»

I would like to know how I could use a Batch file to assign the Left or Right mouse click function to something else (Like assign Right Mouse click to open Task Manager).

Also, I would like to know how to create hot-keys on the keyboard by changing a key to execute a file instead of serving it's initial purpose (Ex. Set the "[" key to open up my default browser). I know their are programs out there to do this but I am more interested on learning to do it through a Batch file.

I am more interest in learning how to do it just so I can expand my knowledge rather then actually make use of it. I have been searching through Google and Forums trying to figure it out and still can't get it to work. I FOUND a few examples for the hot-keys on the keyboard but it didn't work correctly for me.

THANK you for any and all help.yes it is possible to do this in batch except you need a 3rd party program called GetKey which comes with a bunch of other MS-DOS Apps that work with batch files to create menus, tones, and the detecting which key on the keyboard was pressed.
heres the website to download it.
http://ourworld.compuserve.com/homepages/ken/
i strongly recommend reading the help document that came with it, because it is kinda hard to reconginize it.

Quote

I would like to know how I could use a Batch file to assign the Left or Right mouse click function to something else (Like assign Right Mouse click to open Task Manager).
this is not possible in batch files, and there arent any 3rd party PROGS that i know of that can detect Mouse clicks.

Oh, Well that's disappointing.

Aren't there commands like this:

Rundll32 user32,SwapMouseButton
Rundll32 mouse,disable

You can disable the mouse or even swap the functions of the mouse buttons yet you can't assign them to execute a file

Hmm, Well thank you very much for your response. I appreciate it no that is possible in batch
Quote
Rundll32 user32,SwapMouseButton
Rundll32 mouse,disable

but im saying that you cant assign mouse presses as hot keys.Alright,

Well do you think it would be possible with VBS?im not an expert on VB, but PROBABLY so.Quote
You can disable the mouse or even swap the functions of the mouse buttons yet you can't assign them to execute a file

I can't imagine why you'd want to do this. Might be very frustrating when left-clicking and some program pops-up and starts executing instead of the normal operations of the mouse event.

Does your mouse software support assigning a button to a file? If so, a VBScript could mimic the mouse presses although in most cases it's easier to use the GUI.

VBScript can create shortcuts where you can assign hotkeys. It might be possible to create a SHORTCUT in a directory other than the desktop (keep it invisible). The hotkey assignments should still be valid.

Edit: not too sure about that last sentence; in fact the shortcut might have to be on the desktop for the hotkey sequence to work.

I use a Logitech G5 mouse as well as the G15 keyboard. I have programmable keys on the keyboard with a GUI but the mouse does not have one.

As I said in the initial post I am more interested in learning to see if it is possible and how to do it rather then actually doing it. Just curiosity. May come in handy down the road.

Thank you for your responses
5137.

Solve : Use a .bat file to open a database routine/menu driven system?

Answer»

Windows XP Professional, V5.1, 1 MILLION megs RAM

In Notepad I place the following text and SAVE it as a .bat file:

:: ATMS Applications
:: Links to latest version of the ATMS queries, forms, and reports
::
@echo on
copy /y C:\Documents and Settings\user\Data\Paula Axlerod.html “&temp&\ Paula Rivera.html”
start “&temp&\ Paula Axlerod.html”
cls
exit

Using the DOS commands shown above I get the following errors:

does not recognize double quotation marks" (")
can not find the file specified"
'temp' is not recognized as an internal or external command

Any help would be GREATLY appreciated.Provided temp is defined, this should work:

Code: [Select]:: ATMS Applications
:: Links to latest version of the ATMS queries, forms, and reports
::
@echo on
copy /y "C:\Documents and Settings\user\Data\Paula Axlerod.html" “%temp%\ Paula Rivera.html”
start “%temp%\ Paula Axlerod.html”
cls
exit

Those ampersands flashed me back to mainframe JCL

Note: You can also make user a replaceable variable by using %username%Sidewinder,

Thank you for your ASSISTANCE!

Brian

5138.

Solve : Commands in bat file?

Answer»

Hi

If i use the following DOS commands individulaly in the DOS window to search for a file and then copy the file the commands work but if i add these two commands to a bat file then they do not work.

DIR /S /B C:\rename\tt1-10.txt> TMP.DIR
FOR /F %F IN (TMP.DIR) DO COPY %F c:\auto\com1\tt1-10.txt /y

Am i missing something.

ThanksQuote

but if i add these two commands to a bat file then they do not work

Does not work how? You are overwriting a single file so that only the data in the last file copied will exist in c:\auto\com1\tt1-10.txt.

The most obvious error is the lack of double % WITHIN the batch file. A potential error EXISTS if the file names have embedded spaces.

Code: [Select]DIR /S /B C:\rename\tt1-10.txt> TMP.DIR
FOR /F "tokens=* delims=" %%F IN (TMP.DIR) DO COPY "%%F" c:\auto\com1\tt1-10.txt /y

Thanks for the help, WORKS now.

Thanks
5139.

Solve : Question about menu's in .bat, net name?

Answer»

Hi!

I know how to make a menu in batch. My problem now, is that I want to make an opinion with "Net Name" and that you should get a QUESTION to write in your name, you see?

Like after you chose for example '1. Net Name', you should get a question: 'What name would you like? TYPE here:'.

Thank you for answers.set /p netname=Type your net name here:
ECHO You typed: %netname%
AH! Thank you! Worked perfect!

5140.

Solve : Mail from DOS prompt?

Answer»

I WANT to send a MAIL with attachment from DOS BATCH file. do i need to use any 3rd party tool? or in BUILD command available in DOS??
Pls assist...wait are you wanting to make a Batch file that can send EMAILS?

Quote

do i need to use any 3rd party tool? or in build command available in DOS??
Do you mean you want to make it into a full-scale application?
Plz explain
http://www.google.com/search?q=send+mail+from+dos

There are lots of different methods to do this, but it depends on if you mean from pure DOS (like MS-DOS) or a Windows command prompt.it all comes down to this, you cant send email in DOS without a 3rd party prog, unless you have an internal Dial-up modem that you can send files with the Copy command.
or you could use the Netsh command(if ur using command prompt) to send files through a LAN.
5141.

Solve : How do I Parse data out of a file into a Variable??

Answer»

This is one of the many attempts I have made to Parse data out of the file into a Variable.

FOR /F "delims=" %%4 IN (SPIMRF1.dat) DO (

SET INPUTVAR=%4
ECHO INPUTVAR=%4

)


I have read the "FOR /F" parsing online documentation but am obviously missing something.

I verified that my SPIMRF1.dat file contains data = "05820080519"

This is the string of data that I am trying to retreive out of the file into the variable.

A little help please, would be greatly appreciated.

Thank You.I think the problem here is that you are using a numeric loop variable, when it should be alphabetic

Try changing the %%4 to %%A

GrahamQuote from: gpl on JUNE 04, 2008, 06:24:33 AM

I think the problem here is that you are using a numeric loop variable, when it should be alphabetic

Try changing the %%4 to %%A

Graham

Not quite. He wrote %4 not %%4. That's the problem. You can use %%a to %%z, %%A to %%Z and %%1 to %%9 as loop variables, although the number ones are not documented. Obviously you can't have as many implicit variables using "tokens=1,2,3" etc, if you choose to use numbers as the variable symbols in a loop.

The problem is the number of % signs. There should be 2 in front of the variable letter or number in a batch file and 1 at the command prompt.

CODE: [Select] SET INPUTVAR=%%4
ECHO INPUTVAR=%%4

Incidentally why not try this

Code: [Select]FOR /F "delims=" %%4 IN (SPIMRF1.dat) DO SET INPUTVAR=%%4
ECHO INPUTVAR=%INPUTVAR%



I tried several different variations using your posted suggestions.

Either of the FOLLOWING TWO (2) pieces of code worked for me.

FOR /F "delims=" %%P IN (SPIMRF1.dat) DO (
SET INPUTVAR=%%P
ECHO INPUTVAR=%INPUTVAR%
)



FOR /F "delims=" %%4 IN (SPIMRF1.dat) DO (
SET INPUTVAR=%%4
ECHO INPUTVAR=%INPUTVAR%
)


Thank You very much for your help. Quote from: Dias de verano on June 04, 2008, 06:48:07 AM
Not quite. He wrote %4 not %%4. That's the problem.
DOH
I didnt spot the single %4, he had %%4 on the FOR line

I didnt know about %%num - all these years and theres still something new to learn !!

Cheers
Graham
5142.

Solve : save RTF Files in plain Text file format?

Answer»

Hello All,

I am new to this forum.

I need a batch file which can save my *.rtf files in *.txt file.

I want to save Rich text Format to Plain Text Format using a batch file as there are 1000 of such rtf files.

Please help me.

Thanks in advance!

Welcome to the CH forums

And to do this just copy the code here to ur batch file and you can convert the files.

Code: [Select]cd C:\(Where ever the folder is)
copy *.rtf *.txt
echo Files Converted.
pauseThanks a lot for the quick reply.

Yes, I tried the told batch commands, and it does converts rtf to txt format, But the txt file contains some junk characters also all the lines are wrapped.

its not the format i want.

when i saved the rtf as text files by using the SAVE AS option. i am not getting any junk or wrapping problem.

Thanks!
Quote

cd C:\(Where ever the folder is)
copy *.rtf *.txt
echo Files Converted.
pause

Unfortunately it's not that simple. Changing the extension of a file does not change it's organization. If the OP has a copy of MS-Word, it is possible to write a simple VBScript to save the documents as text files.

Let us know. I do have VB for the above function, but i want to know is it possible to create a batch program to achieve what the VB is doing.

I think its possible through batch as batch files are easy to handle and work with.

Thanks!Sidewinder, you beat me to it.

Macdad, you goofed. Please check your answers before posting in future.

This is a text file containing just the words "This is a text file.":

Code: [Select]This is a text file.
This is an RTF file containing just the words "This is a rich text format file":

Code: [Select]{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang2057\deflangfe2057{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f37\froman\fcharset238\fprq2 Times New Roman CE;}
{\f38\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f40\froman\fcharset161\fprq2 Times New Roman Greek;}{\f41\froman\fcharset162\fprq2 Times New Roman Tur;}{\f42\froman\fcharset177\fprq2 Times New Roman (Hebrew);}
{\f43\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f44\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f45\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;
\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;
\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang2057\langfe2057\cgrid\langnp2057\langfenp2057 \snext0 Normal;}{\*\cs10 \ADDITIVE \ssemihidden
Default Paragraph Font;}{\*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv
\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}}{\*\latentstyles\lsdstimax156\lsdlockeddef0}{\*\rsidtbl \rsid219276\rsid13575563
\rsid13646503}{\*\generator Microsoft Word 11.0.6568;}{\info{\title This is a rich text format file}{\author User}{\operator User}{\creatim\yr2008\mo5\dy7\hr22\min40}{\revtim\yr2008\mo5\dy7\hr22\min41}{\version1}{\edmins1}{\nofpages1}{\nofwords5}
{\nofchars29}{\*\company HOME}{\nofcharsws33}{\vern24579}}\paperw11906\paperh16838 \widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1800\dgvorigin1440\dghshow1
\dgvshow1\jexpand\viewkind1\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct
\asianbrkrule\nojkernpunct\rsidroot13646503 \fet0\sectd \linex0\headery708\footery708\colsx708\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang
{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang
{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain
\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang2057\langfe2057\cgrid\langnp2057\langfenp2057 {\insrsid13646503 This is a rich text format file.}{\insrsid13575563
\par }{\insrsid13646503
\par }}Quote
I do have VB for the above function, but i want to know is it possible to create a batch program to achieve what the VB is doing.

Under the circumstances, the CLOSEST to a batch file would be the one to launch your VB converter program.

Is your VB program interactive or batch?

wait you guys, wat if he put in the Findstr command and did that for all the converted txt files so he COULD look for anything in the brackets and delete EM from the file.
except wat is the command for deleting specific lines in a file. edlin?Quote from: macdad- on May 08, 2008, 05:40:32 AM
wait you guys, wat if he put in the Findstr command and did that for all the converted txt files so he could look for anything in the brackets and delete em from the file.

Because {\insrsid13646503 This is a rich text format file.} is in brackets, it would GET deleted. Anyway, writing a VB script is, in my opinion, the easiest and most efficient way to achieve what the OP is trying to do.yea, i guess.
5143.

Solve : batch file to open multiple DOS windows?

Answer»

Hi there
can someone help me with a batch FILE to OPEN multiple dos windows at the same time (each window will be running the same commands) start "" "batchfile.cmd"
start "" "batchfile.cmd"
start "" "batchfile.cmd"
start "" "batchfile.cmd"

etc
Thanks Dias,
Can I give user input to decide on the NUMBER of TIMES the window to be opened?Code: [Select]@echo off
set /p num="How many windows ? "
for /l %%i in (1,1,%num%) do (
start "" "batchfile.cmd"
)
Great!! Thanks a lot.

5144.

Solve : how to make string for a commond??

Answer» 1. to run the commonds in dos i do have to switch to system32 directory each time when i open dos window. is there any way to come out from this issue so that it WOULD been possible to run commonds directly without switching again and again.
although i know that this can be achieved by setting path variable to point to system32.
but this variable already has been set already to point to java home directory as per my requremet.

2. how can i define a string for a commond

suppose this is a commond C:\> cd c:\windows\system32 now i want that this commond would work as such if i write C:\> string


regards
san


1)I dont fully understand the question, if you understand you need a variable and one has already been set, why not just set another?

2)so instead of typing C:\windows\system32\batfile.bat , you just want to type batfile.bat , this can be done by placing the batch file inside the windows folder, and if that doesent work TRY windows\system32 folder.Quote from: diablo416 on May 08, 2008, 07:44:22 AM


1)I dont fully understand the question, if you understand you need a variable and one has already been set, why not just set another?

yes!! isn't it possible to define two seprate variables such that both of them work?
please read my problem again

Quote
2)so instead of typing C:\windows\system32\batfile.bat , you just want to type batfile.bat , this can be done by placing the batch file inside the windows folder, and if that doesent work try windows\system32 folder.

i meant how to define a small string for a lengthy commond?Quote
although i know that this can be achieved by setting path variable to point to system32.
but this variable already has been set already to point to java home directory as per my requremet.

The path variable can point to multiple directories by separating them with semi-colons.

path=c:\java\directory;c:\windows\system32;c:\windows;

After checking the current directory, the path is searched reading left to right. If a match is found, execution begins, if not you get the dreaded "is not recognized as an internal or EXTERNAL command, OPERABLE program or batch file."

Many programs add themselves to the path when installed. You can also add your own directories so you don't have to store your own stuff in the Windows directories.

The path also works with the pathext variable when files in a directory have the same name but different extensions.

thanks!!

and what about my second question?

Quote
how can i define a string for a commond

suppose this is a commond C:\> cd c:\windows\system32 now i want that this commond would work as such if i write C:\> string

Put it in a batch file called string.bat, put the batch file in a folder on the PATH and then you can just type string

for example

s32.bat

Code: [Select]@echo off
cd "c:\windows\system32"

Now if you type s32 at the command prompt the effect is the same as if you had typed cd "c:\windows\system32"

The power of batch files!

PS the word command has an 'a' in it. Hmmm... somebody else was in the habit of spelling it "commond"...





5145.

Solve : Assign most recent file to a variable. (curious)?

Answer»

Hi all,

Am trying to perform a bare listing of files in a particular format
(eg: %xDIR%\%xMCode%%xCCode%%xTType%.%Year:~2,2%%Month%%Day%.* ) and do the following ...

  • If no files ... return an error/flag value
  • if more than one file exiss ... return with a message
  • If one or more files ... return the value of the most recent file only
This isn't for anything right now, was wondering how it would be ACHIEVED in msdos/batch ... I know what I'd need to do in a unix environment.

Cheers,
Cameron.show samples of your file formats, and what you WANT to doHi ghostdog74 ...

I'd provided the file format in the initial post...
%xDIR%\%xMCode%%xCCode%%xTType%.%Year:~2,2%%Month%%Day%.*
For example: C:\...\USCBTT.080604.155015

What I WANTED to do was INDICATED in the dot points.
you can use the dir command to generate a file listing

these switches would seem relevant

/b ... generate a bare listing
/o:d ... in date order, earliest first
/o:-d ... in date order, latest first

/T:C ... use file creation date
/T:A ... use last access date
/T:W ... last written

You can add a wildcard to select the file(s) you require

e.g.

dir /b /o:-d /t:c [filespec]

You can use FOR to process the output.

You can use the IF EXIST test.




5146.

Solve : The "runas" command?

Answer» HEY!
I know what the "runas" COMMAND is doing, but I have no idea how to use it! I have seen some examples, but never got it explained.

So could SOMEONE help me out?

Thanks.

s0br3.Maybe this will help .Ty
5147.

Solve : Paths with spaces, Help.?

Answer»

Hello,

Can anyone help me with getting the full path when one of the directories has a space in it?

I.e.

Dir STRUCTURE:
c:\test
c:\test\new stuff
c:\test\new_stuff

Batch File: (snippet)
FOR /R %%A in (*.security) do CALL :IndexAdd %%A

:IndexAdd
SET FNAME=%~nx1
SET fPath=%~dp1
ECHO Indexing file: %fPath%%fName%

This seems to work fine, until I hit a directory with a space in the name, when it has a space it truncates at the space and then the filename and path are incorrect.

I tired ADDING the delims= with different characters, but when I do it doesnt FIND anything at all...

Thanks for any help.

Brock


Code: [Select]FOR /f "tokens=* delims=" %%A in ('dir *.security /s /b') do CALL :IndexAdd "%%A"

:IndexAdd
SET fName=%~nx1
SET fPath=%~dp1
ECHO Indexing file: %fPath%%fName%

The R switch in the for command does not ALLOW the use of the tokens and delims options. A workaround is to build a better mouse trap.

5148.

Solve : How do activate and deactivate wireless and wired network?

Answer»

Hi!

I just wonder if it is possible to write a .bat file that activates my wireless network CONNECTION, and at the same time deactivates the wired Local Connection?

Thanks for answers.

s0br3.The GUI is actually your BEST option. But this piece of doggerel from deep in the snippet closet may help:

Code: [Select]strEnable = "En&able"
strDisable = "Disa&ble"

strNetworkFolder = "Network CONNECTIONS"
arrConnections = Array("Wireless Network Connection","Local Area Connection") 'Connection names; change if necessary

Set objShell = CreateObject("Shell.Application")
Set objCP = objShell.NameSpace(3) 'Control Panel

For Each f In objCP.Items
If f.Name = strNetworkFolder Then
Set colNetwork = f.GetFolder
Exit For
End If
NEXT

If colNetwork.Items.Count = 0 Then WScript.Quit

For Each strConnection In arrConnections
For Each cn In colNetwork.Items
If cn.Name = strConnection Then
Set conn = cn
Exit For
End If
Next

bEnabled = True
For Each verb In conn.Verbs
If verb.Name = strEnable Then
Set objEnable = verb
bEnabled = False
Exit for
End If
If verb.Name = strDisable Then
Set objDisable = verb
Exit For
End If
Next

If bEnabled = True Then
objDisable.DoIt
Else
objEnable.DoIt
End If
WScript.Sleep 3000
Next

You'll probably have to change the names of the connections. The line is FLAGGED. This script is designed to toggle the state (enabled->disable or disable->enabled) of the connections named in the array.

Save the script with a vbs extension and run from a command prompt as cscript scriptname.vbs

Good luck. Thank you! Worked perfect!

5149.

Solve : Similar to 'tee' in batch/msdos ???

Answer»

Hi All,
Currently I'm having to duplicate a lot of my logging ouput to also be seen if RUN manually.

In unix I'd do something like ... Code: [Select]echo This is an echo | tee -a /some/output/file.txt
Is there anything similar in a batch/msdos environment ?

Cheers,
CameronNothing built in, I am afraid. There is the the Tee-Object cmdlet in Windows Powershell, or you can get the GNU Core Utils which include tee.exe.

http://gnuwin32.sourceforge.net/packages/coreutils.htm

With a Unix background you might find them useful.

I Googled & FOUND various tee programs for Windows that you can download and a vbs script that would be handy if you cannot install addon software.

http://www.google.co.uk/search?source=ig&hl=en&rlz=&q=windows+tee&btnG=Google+Search&meta=&aq=f
Many thanks Dias,

Not SURE how much time I'll be spending on the msdos side of THINGS after my current project is finished.
However will check out those links and bookmark them should my msdos experience be extended

Cheers,
CameronBeware of confusing ms-dos and nt command prompt!!!

5150.

Solve : starting program in dos?

Answer»

Hi guys,

Im using windows XP.

i am really intrested in this. I can obviously start a program in dos with start command. But, when the program starts say for example superscan, i want to be able to execute commands in the program through dos.

for example, superscan has a command that says "lookup" and "scan" ect.. and say, another program like calc on the machine has NUMBERS to press, i was wanting to understand a method to start commands from the actual gui of the program, from inside the dos window.

Another great example is a port scanner. to be able to load it up which ive DONE, then issue a dos command to enter my ip and port and hit scan.

can you help me? Thankyou.I'm a bit confused. By 'dos', do you mean Command Prompt? If so, are you trying to get it to open a program like calc and have it press the numbers for you? because that's not possible.yeah thats what i was hoping for. Or is there some 3rd party program i can use to do this?I don't know of a program that can do this for you but I am sure Command Prompt isn't the way to go.
One thing I do know is you are looking for some type of script or macro. I'm afraid I don't know of any though...

Sit tight and maybe someone will point you in the RIGHT direction.There are a couple of ways to do what you're asking. The first would be to send keystrokes to the application. This example uses the Windows Calc program:

Code: [Select]set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc"
WScript.Sleep 100
WshShell.AppActivate "Calculator"
WScript.Sleep 100
WshShell.SendKeys "1{+}"
WScript.Sleep 500
WshShell.SendKeys "2"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "*3"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 2500
Source: Windows Scripting Technologies

The other is to mimic logical MOUSE actions. An example was posted here

Some applications provide their own COM objects which makes scripting the application very easy. In other situations it depends on the specific program and how it behaves in the Windows environment.

Generally if a program presents a window and waits on the user, scripting the GUI may be possible. If a program presents a window and immediately starts doing it's thing, scripting the application probably is not possible.

Good luck.

Ah yes, I forgot about those.

Just save the script Sidewinder posted as .vbs from Notepad.Thankyou for you exellent answers widewinder, you too carbon. That script works perfect. I have a slight problem tho. I want to understand how it works, because when i look at the 1+ 2 command, obviously this is + key, but what is the ~ for?

also, when i try this on say, superscan, i start it fine and now am able to input info in the box, but what would the command be to make a button click CALLED "Me" under the ip address i entered.


EDIT///


Now if i do this..

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "scanner.exe"
WScript.Sleep 100
WshShell.AppActivate "scanner.exe"
WScript.Sleep 100
WshShell.SendKeys "me"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500


How would i be able to not enter any word text, but skip out the buttons and just click the "ME" button, because the above sript hits the lookup button.



please see example below.

http://img120.imageshack.us/img120/7543/test55hm3.jpgThe "~" (tilde) is the enter key. A full list of the key strokes is here

Quote

also, when i try this on say, superscan, i start it fine and now am able to input info in the box, but what would the command be to make a button click called "Me" under the ip address i entered.

Using only the keyboard, what actions do you have to take to give the "Me" button focus? It is these actions you need to script. Once the "Me" button has focus, sending the enter key will produce the button click.



Note: If your application is updated, your script may break. Just something to be aware of.

PS. I've always called the tilde a squiggle, but you won't find that in any reference.

Nice site, Sidewinder.

Mobzy, I think you will want to try the following right now:

WshShell.SendKeys "~" or WshShell.SendKeys "ENTER"
and
WshShell.SendKeys "TAB"

Just imagine you don't have a mouse and you have to use your keyboard but record all the keystrokes you make and turn it into a script.Thanks for your answer and trying to help me.

ive added:

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "scanner.exe"
WScript.Sleep 100
WshShell.AppActivate "scanner"
WScript.Sleep 100
WshShell.SendKeys "Me"
WScript.Sleep 100
WshShell.SendKeys "~"
WScript.Sleep 100
WshShell.SendKeys "TAB"
WScript.Sleep 2500


and


set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "scanner.exe"
WScript.Sleep 100
WshShell.AppActivate "scanner"
WScript.Sleep 100
WshShell.SendKeys "Me"
WshShell.SendKeys "TAB"
WScript.Sleep 100
WshShell.SendKeys "~"
WScript.Sleep 100


and still the same thing. you say imagine i have no mouse, but when i try and press keys to see what buttons activate i just hear error sounds. Am i doing it right?

thanks again .SOMETHING great happened thanks to you sir. ill post more in a bit. i thankyou so much!!!!you way works perfect and i understand about the imagine no mouse thing

i was curious, say i wanted to enter an ip into the box normally id use WshShell.SendKeys "192.168.0.1"
WScript.Sleep 100

how .. now this i think is confusing, would i be able to have a small dialog popup, and user enter an IP into that, and click ok, and it echos the info back into the superscan.

hah, hard 1 ay?Glad you got it working.

Quote
how .. now this i think is confusing, would i be able to have a small dialog popup, and user enter an IP into that, and click ok, and it echos the info back into the superscan.

Why the confusion? Typing into a small dialog popup is no different from typing into the scanner GUI.

Quote
hah, hard 1 ay?

Not nearly as difficult as you might imagine. Check out this site for some ideas.

thanks for advice above mate, ill check it out in a bit.

I need some help guys.

if used TAB to cycle through menus, and also ctrl+tab..
i found more menus, n cant seem to get anywhere, no commands seem to work to cycle through. any idears?

maybe they arnt true gui buttons, but they link to say, start scan and they scan. ( not superscan ). Ive hiy a brick wall!:(

any ideas? id really appreciated it!!!

The plot thickens. With Windows objects, this can be accomplished by first writing a script to display all the verb names for an object and their values. With this information, you can work backwards to script the GUI. This was demonstrated in the second example.

If your application supplied a COM object, you may have to research either the registry or an object browser for the program id and go from there.

The sendkeys method has codes for almost every key or key combination except PRNTSCRN. You'll have to manually go through the key sequences needed to accomplish your task and then script every single keystroke. This can be a bit tedious so check out if your application has command line parameters where you can accomplish your task from the command prompt.

If you give us more info on the superscan program, exact name and version, perhaps one the the members will have some experience with this specific software.

Good luck.