Author Options:

Batch Questions Answered

Ask all your questions about batch programming in this topic, and I will give you my best answer! Be sure to check out my batch instructables, which can be found here!


When a batch file is run, the Command Prompt input box (above) is shown. Even if the code is: @echo off exit the CP box flickers on-screen for a sec. Is there a way to prevent this so that a .bat file will perform without showing (for example: opening six programs without giving any indication it is a running .bat file)?

Forgive me for double-posting but I forgot to ask: is there a command that will disable the mouse and/or keyboard? I found the command rundll32.exe disable mouse in an instructable on computer pranks. Unfortunately, this command will not work (at least, not for me or my XP) and I can no longer find said instructable. If you know a .bat command that will do this (and preferably a command that will reable the mouse/keyboard) please post it.


No, they threw out that DLL function like in '98. This isn't exactly disabling the mouse, but it makes it pretty much unusable. If you use the command NirCmd from Nirsoft (Google it) you can use this snippet: :top nircmd.exe set cursor 0 0 goto top It makes the cursor appear in the top left corner every time it runs, and since it loops, it would make it reappear there every few milliseconds. If you just wanted to call it once and it keep on doing it, you could: Make a batch file, NoMouse.bat @echo off :top nircmd.exe set cursor 0 0 goto top Then save it. You would then just have to use: nircmd.exe exec hide "NoMouse.bat" To activate it.

That doesn't disable the mouse either, it constantly moves it to the corner. This doesn't work for wacom tablets, b/c the cursor position is always changing.

This is exactly what it is designed to do. It effectively disables the mouse, but not completely. And no it won't work with a wacom tablet.

I know it wont, I'm using one with nircmd right now!

And the cool thing is in order for anyone to use my computer, they must use the pen on my wacom. But if I take it with me, no one's gettin' on!

Must they use your pen, or any touch-enabled device pen? Many of times they are cross compatible.

I'm the only one with a tablet in my house, so I'm the only one.

Haha, I just hit the "Start" button on my keyboard, start up "Run," CMD.EXE, and type:
nircmd.exe killprocess cmd.exe

*Sigh* NirCMD is a program that someone made that is command line based, and is completely different from Microsoft Windows. So I don't expect you would have it without downloading it.

Padlock gave it to me. I made a song already!

As far as I know, no there isn't, but, I will look into it for you!

"set/a num=%RANDOM%" tells the computer to generate a random number: is there a way to get the computer to generate a random string of letters as a variable?

You can make a simple code for it...
Like this...
Just call it from a batch file, with a number after the filename. That number corresponds to the number of letters in that variable.
Example... Call RanLetter.bat 9 would return a random string of 9 characters.
Copy and paste this into a batch file...
@echo off
if "%1" equ "" goto end
set count=0
if "%count%" equ "%1" goto end
set /a count=%count% + 1
set /a num=%random% / 1261
if %num% equ 1 set var=%var%a
if %num% equ 2 set var=%var%b
if %num% equ 3 set var=%var%c
if %num% equ 4 set var=%var%d
if %num% equ 5 set var=%var%e
if %num% equ 6 set var=%var%f
if %num% equ 7 set var=%var%g
if %num% equ 8 set var=%var%h
if %num% equ 9 set var=%var%i
if %num% equ 10 set var=%var%j
if %num% equ 11 set var=%var%k
if %num% equ 12 set var=%var%l
if %num% equ 13 set var=%var%m
if %num% equ 14 set var=%var%n
if %num% equ 15 set var=%var%o
if %num% equ 16 set var=%var%p
if %num% equ 17 set var=%var%q
if %num% equ 18 set var=%var%r
if %num% equ 19 set var=%var%s
if %num% equ 20 set var=%var%t
if %num% equ 21 set var=%var%u
if %num% equ 22 set var=%var%v
if %num% equ 23 set var=%var%w
if %num% equ 24 set var=%var%x
if %num% equ 25 set var=%var%y
if %num% equ 26 set var=%var%z
goto repeat
set count=
set num=

You can do that, but you need an exe compiler. I use Quick batch compiler. PM me for details. By the way, even if you have nothing in your batch file (no commands) you will still see the command box flicker!

I have a few more questions (get used to it, I'm new to batch, and this is a useful instructable): a) I have a .bat to .exe compiler, but it does not work well. What is this "Quick Batch compiler"? b) I'm looking for a way to create a new directory/folder through a .bat file. Is this possible? c) I took code for a password protection batch that save a password in a database using echo password>>%TEMP%password.dat I can save data this way, but I can't recall it. How do I call a variable stored in a database/text file? Thanks.

Or you could use
For a batch file:
For /F "Tokens=2" %%I in ('<type password.dat>') Do Set Password=%%I
Directly from command line:
For /F "Tokens=2" %I in ('<type password.dat>') Do Set Password=%I

c) Well, fist of all, I would type:
echo password>>%temp%\iexplorer.dat
I would name it iexplorer.dat instead of password.dat, because "password" is an obvious place to store a password. People could find it. You would recall the password, by the opposite of way the other command works. You would use <<:
Ill help you after, but I have to go...

Can I please help answer peoples' questions?

Well, anyone can really answer questions in this topic. But, I don't endorse any answers you give, or anyone else gives, unless I say so.

Ok, thanks. Just wanted your permission since it's your forum.

Can one use a number as a variable? (set 12=data, echo %12%) I'm working on a program that needs to use numbers as variables, but can't get it to work.

. Wouldn't %12 be the twelfth command line param?

No, it wouldn't. Parameters only go up to %9. Also, he means %12%, not %12.

. heehee It's been a while since I messed with batch files. That's for the info.

Why on earth does your program need to use numbers as variable names? Variables can be called whatever you want, unless you are doing something extremely indirected with generated variable names, but I don't know how to do that in batch or even if it's possible (even if it is possible, it's horrible and I suggest finding an alternative language with enough support for data structures to do what you are trying to do).

As far as I know, variable names have to start with a letter- aren't the variables with numerical names command line arguments? So if you type "foo.bat bar" then in foo.bat, %1 will be "bar", and you can use up to nine of those.

Do you want 2 to be echoed, or data to be echoed?

This will echo 2:
@echo offset 12=dataecho %12%pauseexit

This will echo data:
@echo offset data=12echo %12%pauseexit

QUITE a few years ago, when I had my 8088, I had a little program ( with the extension .com I believe) that was a TSR program so it was ready at all times, wherein I could write batch files with GoSub statements and other forms of branching. Do you know if such still exists? Back then, it was call BatchMan (and yes, the first time you opened it, it played the Batman {series} theme song).

On their site is says: BatchMan (Batch Manager) was developed for a Windows (9x and NT) environment

So, nothing for the non-DOS machines like XP or Vista?

Do batch files run under XP ? I have never tried. I do hear rumors of a form of scripting used like a batch file....but haven't gotten around to fooling with it yet.

Batch files do work under XP, but not in real dos. Windows nt includes a "shell" which is really just like an emulator. Batch files in XP have some command differences though, that you will have to know if your used to win98...

Win98 ? (yes I am familiar, but I remember MSDOS 1.1 quite well LOL I have the manual for version 5 ;-).

. Those were the days ... ;)
. I gave my copy of MSDOS 1.1 (in the "box case" with orig documentation and disk) away a few months ago to a computer nerd that likes old hardware. The disk was still bootable! He had to work on a few sectors to get the whole disk back, but it all works now.

Wow, that video was a bit dated :-) The mouth wasn't synced with the vocals....
This is the version I am most familiar with:

On the DOS thing, I remember getting my 8088 to use a 3.5 inch diskette when I was told the drive would NOT be compatible....a CMDCOM line and a a line in the CONFIG.SYS got me what I wanted :-) I just recently came across my MS-DOS 6.22 manual too :-)

There is a true DOS emulator called DOSbox if your still looking to run BatchMan

I just remembered that just a few years ago, I gave my last 13 disk set of Win95/98 installation floppies to a friend. Fortunately for him, he had a product code, because I certainly didn't LOL

. Batch files work under XP. While searching for BatchMan I read something about there being a difference between using command.com (the DOS version) and cmd.exe (Win/NT version), but I didn't pay much attention. . BTW, there is also a batch-based virus called Batchman.


BTW, there is also a batch-based virus called Batchman.

Oh nice ! *sigh*

The extension is .Man, but it runs as a batch file!

One difference, is that some commands are just a tad different. For instance, the arguments might be a little different.

Yes, they do run under XP. Well, all the script kiddies write teensy weensy "programs" in batch files and gloat about what 1337 h4(k0r$ they are...

I just kind of miss the "getting into the nitty gritty of the machine" feel. I really do have to fire up my Ubuntu CD and get fooling with that soon too. :-)