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.

7501.

Solve : Downloading a file using a dos command?

Answer» HI All,

Do we have any MS DOS COMMAND to download a file from the internet.?
I m sure there is one.. could you please help me with the syntax.
http://stackoverflow.com/questions/1615612/how-can-you-download-a-file-zip-from-the-dos-commandline-using-putty
This may help.the one I generally USE is wget.exe which you can GET here

http://users.ugent.be/~bpuype/cgi-bin/fetch.pl?dl=wget/wget-1.10.2.exe

7502.

Solve : Installing fonts?

Answer»

Hi! At my job I am working with a strictly DOS system, no version of Windows is installed on this computer, and I have some fonts that I NEED to install. I have the fonts on a disk, and I can pull up the directory of that disk and see the fonts on it, but what commands do I use to find the font directory on the c: drive? And once I have found the font directory on c:, what commands do I use to copy the fonts from the disk to that directory? I am experienced working with Windows, but when it comes to DOS I know very little.DOS doesn't even have a concept of fonts.
Quote

DOS doesn't even have a concept of fonts.
Quote
MS-DOS does not support the concept of DIFFERENT fonts, it does (or at least the graphics card does) support the concept of changing screen resolution, which has the effect of changing the font.
http://www.jasspa.com/me/m2cmd027.htmlA:)

DOS doesn't support fonts, aside from the default, VIDEO card-provided text mode font. PERIOD. no exceptions. DOS APPLICATIONS might, DOS itself does not. the only "font" support is by hacking around video memory and changing the bitmaps for the text mode display, which doesn't change a font any more then drawing a picture in paint is changing a font.

At the DOS prompt- that is, when you are RUNNING only DOS- you cannot change the video resolution, except for a few instances such as mode commands or changing the number of columns or rows. In those cases, it doesn't use "fonts" any more then it is using "predefined bitmaps in video memory". Can you change those? yes. That doesn't mean they are fonts, nor does it necessarily mean that DOS supports fonts because it happens to be running while all this is going on.

There is no "fonts" directory in DOS. you cannot install Fonts in DOS.

7503.

Solve : Batch Program: flush dns and reboot?

Answer»

This is for use on a Windows XP/NT environment
I want the file to flush the dns, prompt the user to disconnect and reconnect to the network, and then REBOOT when ready
The current batch stops after the prompt for network reconnection. Not sure what I did wrong.
This is edited code that I put together from online searching:

Code: [Select]@echo off
IPCONFIG /FLUSHDNS
pause
CLS
:start
cls
set choice1=
set /p choice1=Have you disconnected and RECONNECTED to the network? (Y or N)
IF NOT '%choice1%'=='' set choice1=%choice1:~0,1%
If '%choice1%'=='N' goto end
If '%choice1%'=='Y' goto Next
cls
ECHO "%choice1%" is not valid please try again
ECHO.
pause
goto start
:Next
cls
set choice2=
set /p choice2=Your computer will restart.Do you wish to continue? (Y or N)
IF NOT '%choice2%'=='' set choice2=%choice2:~0,1%
If '%choice2%'=='N' shutdown -a
If '%choice2%'=='Y' shutdown -r
cls
ECHO "%choice2%" is not valid please try again
pause
goto Next
ECHO.
:end
exit
Thank you so much, in advance, for the help!AS your script is at the moment, you have to hold down the shift key to answer Y or N because the IF tests are case sensitive; you can use IF /I to get around that. (I for Insensitive)

I have altered your script to make debugging easier; also I have prettied up the set /p lines to make the (Y or N) parts line up vertically to LOOK NEATER, also I have used quotes so the response is spaced away from the prompt; and I have commented out the CLS commands so you can see what is happening better

Code: [Select]@echo off
echo [simulate] IPCONFIG /FLUSHDNS
pause
rem CLS
:start
rem cls
set choice1=
set /p choice1="Have you disconnected and reconnected to the network? (Y or N) "
IF NOT '%choice1%'=='' set choice1=%choice1:~0,1%
If /i '%choice1%'=='N' goto end
If /i '%choice1%'=='Y' goto Next
rem cls
ECHO "%choice1%" is not valid please try again
ECHO.
pause
goto start
:Next
rem cls
set choice2=
set /p choice2="Your computer will restart.Do you wish to continue? (Y or N) "
IF NOT '%choice2%'=='' set choice2=%choice2:~0,1%
If /i '%choice2%'=='N' echo [simulate] shutdown -a
If /i '%choice2%'=='Y' echo [simulate] shutdown -r
rem cls
ECHO "%choice2%" is not valid please try again
pause
goto Next
ECHO.
:end
echo exit
pause

Code: [Select]S:\TEST>test.bat
[simulate] IPCONFIG /FLUSHDNS
Press any key to continue . . .
Have you disconnected and reconnected to the network? (Y or N) n
[simulate] exit

S:\Test>test.bat
[simulate] IPCONFIG /FLUSHDNS
Press any key to continue . . .
Have you disconnected and reconnected to the network? (Y or N) y
Your computer will restart.Do you wish to continue? (Y or N) n
[simulate] shutdown -a

S:\Test>test.bat
[simulate] IPCONFIG /FLUSHDNS
Press any key to continue . . .
Have you disconnected and reconnected to the network? (Y or N) y
Your computer will restart.Do you wish to continue? (Y or N) y
[simulate] shutdown -r

I cannot thank you enough!

7504.

Solve : How to delete ext dos partition, when it says it has logical drives, but doesn't?

Answer»

Hi, I'm working on a friends MACHINE, and trying to DELETE this ext dos partition. It says it has logical drives, but when I try to delete them, it says it doesn't. Any ideas?

THANKS for any help

SueI finally GOT it !!!!! Thanks anyways!!!

7505.

Solve : password batch?

Answer»

ok i have a flash drive that if lost has personal numbers and such that i dont want just anyone to find... if i place all the documents into one folder and make it so when u open that folder a batch starts up can i have that batch prompt a password? and if u enter the wrong password it doesnt let u access the document? if so please POST the script or whateverits called. im a noob in need of advice im trying to teach myself batches but this is a lil complexWhat software did you use to create these documents? Microsoft Office programs have built-in security methods at the document level. You probably COULD set passwords on documents programmatically with VBSCRIPT. Other publishers may also have security methods you can use. Caution: If you lose or forget your password, it can't be recovered, and you won't be able to open your document/database. You'd be surprised how often that COMES up,

A batch file in this situation would be next to useless. They can be easily canceled, and if not, the NT window they run in can be closed, bypassing whatever security you might have.

You might Google for a third party program or it may be possible to encrypt the document data using Powershell or some other Windows script language.

Good luck. used notepad and this info isnt top secret just personal so it just needs to stop ur basic computer user not a wiz kid...Quote from: cmdpro on January 04, 2011, 01:53:23 PM

used notepad and this info isnt top secret just personal so it just needs to stop ur basic computer user not a wiz kid...

It doesn't take a "Wiz kid" to hit the X button. You've been TOLD this countless times. Let's have a recap:

Quote
[16:10] <cmdpro> so culd i write a batch
[16:10] <+pottsi> no
[16:10] <cmdpro> i have a batch that firsts prompts for a password
[16:10] <+pottsi> no
[16:11] <&BC_Programming> yes you <could> but it would be pretty crappy


Basically- No. you can't. If you are using XP pro you can encrypt the file.You can always give this a try....

http://keepass.info/

7506.

Solve : Multiple batch file option?

Answer»

Hi,

I have multiple batch files in a folder ,i want find out if batch A is running then batch B should not run and vice versa.

Any type of help will be appriciated.

regards,

GajananScripts and batch files have interpreters for execution and do nor run as processes. This SNIPPET shows a method for querying the window title but is not idiot proof. Depending how the batch file is launched will determine the actual window title and there are too many variations for a DEFINITIVE response.

Code: [Select]@echo off
setlocal

for /f %%i in ('tasklist /nh /FI "WINDOWTITLE EQ Command Prompt - BatchA" ^| find /i "cmd.exe"') do (
if errorlevel 1 (echo BatchA is NOT running
) else (echo BatchA is Running)
)

VBScript or Powershell would probably give you a better and more elegant solution.

Good luck.

It's too early for All Hallows Eve but something is about. When re-testing the code, it seems it might not work. Actually it screams, "IT WILL NOT WORK".

Try this more better code:

Code: [Select]@echo off
setlocal

for /f %%i in ('tasklist /nh /fi "WINDOWTITLE eq Command Prompt - BatchA"') do (
echo %%i | find /i "cmd.exe" > nul
if errorlevel 1 (echo BatchA is NOT running
) else echo BatchA is running)
)

Thank you very much its working for.
but if BatchA is running then it should exit from BatchB and viceversa.
so it will be very helpful if you PROVIDE me that code.
Quote from: Gajananpund on October 03, 2011, 11:02:35 PM

so it will be very helpful if you provide me that code.

Surely you can work it out for yourself?
Substitute:

if errorlevel 1...

for...

if errorlevel 0 goto eof

Quote from: Salmon Trout on October 04, 2011, 12:13:21 AM
Surely you can work it out for yourself?

Sometimes.........it just doesn't make sense. Personally what I might do is make each batch script create a lock file after first checking for the existence of the other script's lock file and exiting if it is found. Or you could make it wait in a loop until the other script's lock file becomes non-existent. If it is not found, then the script creates its own lock file, performs it operations, then finally deletes its lock file.

e.g.

REM Batch A
if exist batchB.lock exit
echo abcde > batchA.lock
bla bla
bla bla
bla bla
del batchA.lock

REM Batch B
if exist batchA.lock exit
echo abcde > batchB.lock
bla bla
bla bla
bla bla
del batchB.lock


7507.

Solve : Output Redirection Control?

Answer»

Currently I check the disk free space on several servers and day and each of them have several drives mounted. They are all MS Windows Server 2000 and up. My goal is to create a log file for the disk checking. I only have one server and one drive in the batch file while I work on this. Here is what I currently have:

IF EXIST "Z:\*.*" (
@NET USE Z: /DELETE
)
@NET USE Z: \\NACET1SQL02\C$
ECHO "%DATE%","%TIME%","NACET1SQL02","C:" >> C:\RESULTS.TXT
@DIR Z: | FIND "bytes free" >> C:\RESULTS.TXT
@NET USE Z: /DELETE
EXIT

This is the output contained in C:\RESULTS.TXT:

"Fri 01/07/2011","10:36:55.39","NACET1SQL02","C:"
16 Dir(s) 1,625,882,624 bytes free

Question - Is there any reasonably simple way to force the results onto one LINE? I can clean up the "16 Dir(s)" and "bytes free" easily enough with Excel. I would just like to put everything for a SINGLE drive onto one line. Any ideas? This one has me stumped. Microsoft Windows XP SP3 using CMD.EXE.This should do the trick:

Code: [Select]@echo off

if exist "z:\*.*" (
net use z: /delete
)
net use z: \\nacet1sql02\c$

for /f "TOKENS=* delims=" %%i in ('dir z: ^| find /i "bytes free"') do (
echo "%date%","%time%","nacet1sql02","c:","%%i">> c:\results.txt
)

net use z: /delete
exit

I'm not a big fan of caps and you don't need to prefix commands with @ if you use @echo off.

Good luck. [EDIT] I was fooling with this offline while Sidewinder was posting. I too am not a big fan of USING CAPS in batch scripts and I agree about @ as well.

You want to see this?

"Fri 01/07/2011","10:36:55.39","NACET1SQL02","C:" 1,625,882,624

You can form the first part of the string thus

Code: [Select]set string1="%DATE%","%TIME%,"NACET1SQL02","C:"
and then use FOR to get the line of DIR output that has the "bytes free" figure into another string

Code: [Select]or /f "delims=" %%A in ( ' DIR Z: ^| FIND "bytes free" ' ) do set string2=%%A
and finally echo the two strings one after the other to the results file

Code: [Select]echo %string1%%string2% >> C:\RESULTS.TXT
You seem to be making a csv output file, so...

Did you want quotes around the bytes free figure?

Did you want the commas (thousands separators) to be removed from that as well?

Code: [Select]@echo off
set string1="%DATE%","%TIME%","NACET1SQL02","C:"
for /f "delims=" %%A in ( ' DIR Z: ^| FIND "bytes free" ' ) do set string2=%%A
for /f "tokens=1-3 delims= " %%A in ("%string2%") do set bytesfree=%%C
set bytesfree=%bytesfree:,=%
echo [1] %string1% %string2%
echo [2] %string1%,"%bytesfree%"
the output...

Code: [Select][1] "07/01/2011","18:12:30.95","NACET1SQL02","C:" 0 Dir(s) 6,238,208 bytes free
[2] "07/01/2011","18:12:30.95","NACET1SQL02","C:","6238208"
You will see that my local %DATE% format is different from yours but that does not AFFECT the operation of the script



In my post above I missed off the first character, (F) in the code line you see below

Quote from: Salmon Trout on January 07, 2011, 11:13:10 AM

and then use FOR to get the line of DIR output that has the "bytes free" figure into another string

Code: [Select]For /f "delims=" %%A in ( ' DIR Z: ^| FIND "bytes free" ' ) do set string2=%%A
7508.

Solve : How to assign two IP address in one NIC card using batch script?

Answer»

Hello All,

Do anybody know how to assign TWO or more IP address in one NIC CARD using batch script in Windows. I currently i use the below batch script to assign one IP address, then i manually assign another IP address. I searched everywhere in net, could not find idea on this.

One more problem is run the script it executes the first line, it opens chrome and does not executes rest of the lines until i close chrome browser. I tried different option for this "start command.....etc" but nothing worked out.

Please help me out.


#################################


"C:\Documents and Settings\Administrator\Local Settings\Application Data\Google\Chrome\Application\chrome.exe"


start D:\santhosh\SBM

start D:\santhosh\DOCUMENTS

start D:\santhosh\SBM\SBM-TOKYO



@ECHO OFF


ECHO Enter INPUT for IP assigning static or dhcp


set /P INPUT=

if %INPUT% == "dhcp" goto :dhcp

if %INPUT% == "static" goto :static


:dhcp
:: ECHO RESETTING IP Address and Subnet Mask For DHCP [line commented]
netsh int ip set address name = "Local Area Connection" source = dhcp

:: ECHO Resetting DNS For DHCP
::netsh int ip set dns name = "Local Area Connection" source = dhcp

:: ECHO Resetting Windows Internet Name Service (WINS) For DHCP
::netsh int ip set wins name = "Local Area Connection" source = dhcp
:end


:static
netsh interface ip set address name = "Local Area Connection" source = static addr = 172.16.241.224 mask = 255.255.255.0
:end

###############################For your second problem, using a simple "start C:\Documents and Settings\Administrator\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" should start the program and continue on with the batch. If not, you may want to check whether command extensions are enabled or disabled. If enabled, try to write the script to disable the extensions, then start the program, then re enable command extensions afterwards.

Code: [Select]setlocal disableextensions
start C:\Documents and Settings\Administrator\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
endlocal
To set a second IP, I need to ask if you are trying to set an IP for a seperate connection or if you are wanting the one "Local Area Connection" to have two IP addresses. If this is what you are wanting, how exactly are you setting it "manually?"

7509.

Solve : batch loop?

Answer»

Code: [Select]@ECHO off
:start
IF EXIST E:\NUL
@ECHO OFF
XCOPY F: D:\backup /E /H /I /Q /Y


ELSE goto start

The idea of the program is if a drive exists then to backup the drive to D:\backup but if the drive doesn't exist then the progaram should loop until it does. Any help appreciated as i clearly am making a stupid mistake.


Quote from: tarleton on January 07, 2011, 01:56:05 AM

The idea of the program is if a drive exists then to backup the drive to D:\backup but if the drive doesn't exist then the progaram should loop until it does. Any help appreciated as i clearly am making a stupid mistake.

Looping the batch code until a drive exists might take a while. Might be better to INVENTORY the DRIVES and backup the ones that you find. Don't know your OS, so I took a guess you have the DISKPART utility.

Code: [Select]@echo off
for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "partition"') do (
xcopy %%i:\ d:\backup\%%ibackup /e /h /i /q /y
)

I added a directory level for each drive backup.

Good luck.
Thanks for that but what I want is for it to automatically backup my USB drive every time i plug it in which is why i want it to keep trying until its plugged in. Is there a way to do this even if it isn't the best way?Code: [Select]:loop
if exist "E:\NUL" goto found
goto loop
:found
XCOPY F: D:\backup /E /H /I /Q /Y
This isn't a batch but it may help, or give you an idea:


http://www.backup4all.com/kb/configuring-a-backup-to-run-automatically-when-the-usb-drive-is-plugged-in-248.html

for example, although it uses a program called "backup4all" you could use the autorun file to run a batch.
7510.

Solve : change my wallpaper each time i login?

Answer»

Hello,

I want to cycle thru a list of pictures in a directory and update my wallpaper each time i logon to windows

any ideas on the code I would need...then I assume I put this code in the startup

Thanks
SteveI found this in the snippet closet which may help:

Code: [Select]Const HKEY_CURRENT_USER = &H80000001

strComputer = "."

intLowNumber = 1
intHighNumber = 3 'Total Number Of Wallpaper Choices
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)

SET objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

Select Case intNumber 'Case Statements LowNumber to HighNumber
Case 1 : strPicture = "fully qualified path to picture 1"
Case 2 : strPicture = "fully qualified path to picture 2"
Case 3 : strPicture = "fully qualified path to picture 3"
End Select

strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"

objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strPicture

Set intHighNumber to the number of pictures you cycle through. The case statements are sequential from intLowNumber (which should be one) to intHighNumber. Set strPicture to the fully qualified path to each of your pictures.

The script will randomly select a picture each time it is run and update the registry. If you have a shutdown script, I would put it in there so the wallpaper resets at the next boot. If you put it in the startup folder, the wallpaper change may not take effect until you logoff/logon. You may have to play around with this.

Save the file with a VBS extension and run from within another script or from the command prompt as cscript scriptname.vbs

Good luck. thanks for that

what about if i wanted to do it in DOS

for example

get the oldest file in a directory
copy it to a target file that is being used for the wallpaper
change the source file so it becomes the newest file

cheersFirst a correction. The VBScript has a missing statement. The corrected version is below:

Code: [Select]Const HKEY_CURRENT_USER = &H80000001

strComputer = "."

intLowNumber = 1
intHighNumber = 3 'Total Number Of Wallpaper Choices

Randomize
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)

Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

Select Case intNumber 'Case Statements LowNumber to HighNumber
Case 1 : strPicture = ""
Case 2 : strPicture = ""
Case 3 : strPicture = ""
End Select

strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"

objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strPicture

Sorry for any confusion.

Quote

what about if i wanted to do it in DOS

First you would need a machine with DOS installed. Why do you want to use batch code anyway on a WinXP machine?

Code: [Select]@echo off

set source="source directory goes here"
set dest="destination directory goes here"

for /f "tokens=* delims=" %%i in ('dir /ta /b /o:d %source%') do (
echo y | copy "%source%\%%i" "%dest%" > nul
echo Y | copy /b "%dest%\%%i" "%source%" > nul
echo y | reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d "%dest%\%%i" > nul
goto :eof
)

Be sure to change source and dest to valid directory names otherwise its the same stuff as yesterday: The script will select a picture each time it is run and update the registry. If you have a shutdown script, I would put it in there so the wallpaper resets at the next boot. If you put it in the startup folder, the wallpaper change may not take effect until you logoff/logon. You may have to play around with this.


hello,

Im a former Cobol programmer, so im learning as i go .....so I dont have VB to develop in but I do know a little about dos...not much as you can see

if there is a way to develop in VB without having to pay for it ....i could do that ??

I tried the dos script but it gave me this

Source = "C:\path\input"
Dest = "C:\path\output"
copy ""C:\path\input"\pic1.jpg" ""C:\path\output""

and the copy didnt work

thanks for your help

cheers


Check out Microsofts Express range
http://www.microsoft.com/express/Windows/
GrahamQuote from: newkid on July 23, 2010, 04:56:36 AM
Im a former Cobol programmer

You might like COBOL.NET I guess I got a little carried away with the quotes.

Code: [Select]@echo off

set source=source directory goes here
set dest=destination directory goes here

for /f "tokens=* delims=" %%i in ('dir /a:-d /ta /b /o:d "%source%"') do (
echo y | copy "%source%\%%i" "%dest%" > nul
echo Y | copy /b "%dest%\%%i" "%source%" > nul
echo y | reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d "%dest%\%%i" > nul
goto :eof
)

Do not quote the source or dest values at the beginning of the code even if the PATHS have embedded spaces. They will be inserted at the proper time.

For the record, the first script I posted was VBScript which was installed on your system with Windows. All you need now is a DOLLAR and a dream.

There is a compiled help file for VBScript (script56.chm) which you can search for on your machine or you can download it from here

Except for REXX, IMO VBScript is one of the easiest script languages to learn and has much more functionality than batch code could ever hope to have.

Good luck. It WORKS ...thanks very much !! Hello,
As I looked for the same (i.e. a small script or tool to change the Windows wallpaper in a random way every day - and without downloading an .exe file...), I tried the VB script available at the URL: http://sites.google.com/site/sharerandomwallpapers/
It works fine and handles a variable number of files (the VB script listed above only handles 3 files or a constant number of files...).
I hope it will bring some help!
John
7511.

Solve : BATCH GAME HELP!!?

Answer»

Is there any way to make a PLAYER earn points in a batch file game??The qustion makes no sense as stated...Quote from: lewy on August 11, 2011, 01:10:46 AM

Is there any way to make a player earn points in a batch file game??

You can have a player ACCUMULATE points and on exit write the number to a file and read the score in the next time the game is run.

Please note, in English we only use ONE question mark at a time.

Code: [Select]@echo off
echo ***************
echo * *
echo * Simple Game *
echo * *
echo ***************
echo.
set /p player="Your name? "
set score=0
if exist %player%.score (
for /f %%A in (%player%.score) do set score=%%A
echo Welcome back %player%
) else (
echo Hello new player %player%
set score = 0
)
echo Your score is %score%
set /p answer="5 + 5 = "
if %answer% equ 10 (
echo correct
set /a score+=1
) else (
echo incorrect
)
echo Your score is %score%
set /p answer="8 - 3 = "
if %answer% equ 5 (
echo correct
set /a score+=1
) else (
echo incorrect
)
echo Your score is %score%
set /p answer="25 x 4 = "
if %answer% equ 100 (
echo correct
set /a score+=1
) else (
echo incorrect
)
echo Your score is %score%
echo Saving your score...
echo %score% &GT; %player%.score
echo Goodbye
Thoughts - You would NEED to think about if you want the player to retain points after they have stopped the script or if you want the points to be maintained within memory for only the time frame of running the script.

Points can be used using the math dos variable set \a points=1+%points%
and if you want it saved to a file you would redirect the points to a file name.Quote from: Darth on October 05, 2011, 06:55:15 PM
Points can be used using the math dos variable set \a points=1+%points%
and if you want it saved to a file you would redirect the points to a file name.

This is exactly what I already wrote, except you GOT the slash around the wrong way.
7512.

Solve : Batch script Echo redirection symbols.?

Answer»

Win XP Cmd.exe

A line in a file contains Detail

Is there any way to copy this to another file using the Echo command?To echo special characters such as < > etc we "escape" them. The escape character for most special characters is the caret (^)

Code: [Select]C:\>echo Detail ^<trial^>^<test1.2^>
Detail <trial><test1.2>
Code: [Select]C:\>echo Detail ^<trial^>^<test1.2^> > test.txt

C:\>TYPE test.txt
Detail <trial><test1.2>
THANK you ST.

The line is already part of a file to which I cannot add the CARETS. I can also Echo the line if it is enclosed in double quotes but then of COURSE cannot remove the " " in the output file.

Is there any code with which I can input the line, add the carets then Echo the line to an output file?Using FOR you can echo each line... This below example works. as shown.. if it is not appropriate for your problem please show an example of part of an input file and state how you are processing it in a batch


Code: [Select]@echo off
echo Detail ^<trial^>^<test1.2^> > test1.txt
echo Detail ^<trial^>^<test1.3^> >> test1.txt
echo Detail ^<trial^>^<test1.4^> >> test1.txt
echo Detail ^<trial^>^<test1.5^> >> test1.txt
echo Detail ^<trial^>^<test1.6^> >> test1.txt

echo Input file:
type test1.txt

if EXIST test2.txt del test2.txt

for /f "delims=" %%A in (test1.txt) do (
echo %%A >> test2.txt
)

echo Output file:
type test2.txt



Code: [Select]Input file:
Detail <trial><test1.2>
Detail <trial><test1.3>
Detail <trial><test1.4>
Detail <trial><test1.5>
Detail <trial><test1.6>
Output file:
Detail <trial><test1.2>
Detail <trial><test1.3>
Detail <trial><test1.4>
Detail <trial><test1.5>
Detail <trial><test1.6>"A line in a file contains" - If this is true, then you may want to look into the find or findstr command to first find a line of code before copying it out to a new file.Thank you both. Matter resolved by switching on brain.

Cheers.

7513.

Solve : Copy a File or Directory form one Drvie to Multiple Drives?

Answer»

Hi Guys,

I need to copy a directory form one directory to multiple drives (the drives are external storage devices). After the long surfing i found the MS DOS command "XCOPY C:\ F:\ /E". This command only used, when i move a file form one to one drive, it doesn't used for one to many drives. If any possibilities to copy a file form one drive to many drives. Thanks in Advance..! Simply repeat the command for each desired external drive.
Use FOR (I think that's going to become a canned response from me...FOR is all-powerful )

Have a paths.txt file with the destinations listed

type Paths.txt
e:\backup
f:\backup
g:\

for /f "delims=" %g in (paths.txt) do xcopy c:\source %g /e /c /h>>copylog.txt

Remember to double up the % SIGNS if using the above command in a batch file. The copylog.txt file would then show you what was copied.The nice thing about batch files, is that you usually write it once and run it many times, without changes.

So if you're going to copy the contents of a directory to another directory on a different hard drive(s), just
sit back, relax and retype the XCOPY line for each drive you're copying to.
This might seem like the beginners way to do it, but hey, it works and if a target drive changes, it's very
easy to change that one line in the batch file.

I do something similar on my own computer, where I back up all the contents from six different directories
on my C: drive to like named directories on my D: drive.
XCOPY has to be set up to only copy files that are not already present on the receiving drive.
When used as a daily backup routine, the batch file runs in just a few seconds.

Here's just one line from that Backup batch file:

Quote

xcopy "C:\MyFiles\*.*" "D:\MyFiles\" /s /y /H /R /D

I don't know if this will help you or not....but I do hope so.

Cheers Mate!
The Shadow
7514.

Solve : can anyone tell me that how can i close media player through a command prompt?

Answer»

can anyone TELL me that how can i close media player through a command prompt or a batch file?Which media player? If your using the Windows Media Player, you can use the /close switch at both the command LINE or in a batch file.

For more details see here.

If you're using a different player, use GOOGLE and search for the specific player and add "command line" to the search argument.

Good luck. Wasnt aware of the /Close switch option... I USUALLY just Taskkill whatever I want to close forcefully which works for everything and anything. /Close is probably a LESS abusive manner of closing an application than killing it..lol

7515.

Solve : Batch commands for 32 or 64bit?

Answer»

How would I WRITE a BATCH that allowed for registry uninstall by OS.

example:
32bit_wsam
"C:\Program Files\Juniper Networks\Secure Application Manager\UninstallSAM.exe"
32bit_networkconnect
"C:\Program Files\Juniper Networks\Network Connect 6.5.0\uninstall.exe"

64bit_wsam
"C:\Program Files (x86)\Juniper Networks\Secure Application Manager\UninstallSAM.exe"
64bit_networkconnect
"C:\Program Files (x86)\Juniper Networks\Network Connect 6.5.0\uninstall.exe"Please be a little more specific about what you are looking for. Do you have listed the uninstall programs and you WANT a batch to run them depending on WHETHER the OS is 32 or 64 bit? Or are you trying to figure out what a good uninstall string using registry values would be?To check 32 or 64 bit system, you will want to use a FOR command against the SYSTEMINFO command. Here's a basic skeleton of what you want:

Code: [Select]@echo off
setlocal enabledelayedexpansion
set errorcheck=0

for /f "tokens=1* delims=:" %%G in ('systeminfo /fo list') do (
echo %%G | find "System Type" >nul
if not errorlevel !errorcheck! (
echo %%H | find "64" >nul
if not errorlevel !errorcheck! (
start 64 bit uninstalls
) else (
start 32 bit uninstalls
)
) else (
set errorcheck=!errorlevel!
)
)
This code checks the systeminfo command (try using the command to see what it does) and checks the title of the information for system type. Once found it checks the rest of the line for 64 and executes the uninstalls based on what is found. Please post if you run into any problems.Sorry, found a small error. Need to adjust for a line right after the first IF line and move the last set errorcheck outside the IF. Check:

Code: [Select]@echo off
setlocal enabledelayedexpansion
set errorcheck=0

for /f "tokens=1* delims=:" %%G in ('systeminfo /fo list') do (
echo %%G | find "System Type" >nul
if not errorlevel !errorcheck! (
set errorcheck=!errorlevel!
echo %%H | find "64" >nul
if not errorlevel !errorcheck! (
start 64 bit uninstalls
) else (
start 32 bit uninstalls
)
)
set errorcheck=!errorlevel!
)

7516.

Solve : Find and Replace one string with another inside the file using DOS batch?

Answer»

Wow, this thread just keeps getting revived from the grave. Fun.

There is a way to do this in BATCH, though there are much better tools out there to accomplish the task as shown throughout the thread. The batch method is outlined and not fully coded below:

This command would be used for one file and would need to be embedded in another for command if multiple files were needing to be changed.
for /f "delims=" %%G in (changefile.txt) do (
set oldstring=%%G
set newstring=!oldstring:~0, 52=0, 21!
echo !newstring!&GT;>temp.txt
)
del changefile.txt
ren temp.txt changefile.txt

Again, this could be run on multiple files using this for command embedded into another for command that would determine what is PLACED in the "changefile.txt" area. Obviously you could put multiple "set newstring=" commands in if there were multiple changes that were needing to be made.

Can we LET this thread die now? It has lived a long life and should be ALLOWED to rest in peace.
Quote from: Raven19528 on September 29, 2011, 10:10:38 AM

for /f "delims=" %%G in (changefile.txt) do (
set oldstring=%%G
set newstring=!oldstring:~0, 52=0, 21!
echo !newstring!>>temp.txt
)
del changefile.txt
ren temp.txt changefile.txt

One error: there is no ~ after the colon in the set newstring line. It should read:
set newstring=!oldstring:0, 52=0, 21!
7517.

Solve : net user Error Code?

Answer»

Hi,

I am using batch file to create Users using net USER command. If a user creation fails i like to pop up a message to the user.

How can i do that. i do not know what is the condition to use if.



Thanks Use an IF statement to check the errorlevel variable. If you are doing multiple users and will need to check multiple times, you just have to set up another variable to check against that keeps the running errorlevel seperate from the errorlevel variable. I know that sounds confusing, maybe a demo will help.

Code: [Select]set errorcheck=0
...
net user username password /add

if not "%errorlevel%"=="%errorcheck%" (
set errorcheck=%errorlevel%
echo Error message
PAUSE
)
...

As you can see, the errorcheck variable will always keep the previous errorlevel seperate from the errorlevel variable so you get an accurate READING each time the errorlevel is checked.

7518.

Solve : Making [Y/N] questions in batch files?

Answer»

the NT version is the one that you would want.3.1 or 3.5?Quote from: PirateSamir on January 26, 2009, 10:57:24 AM

3.1 or 3.5?

Either, or NT4, or Win2K resource kit
k thnx, i got 3.5
gonna learn to use it now Quote from: PirateSamir on January 26, 2009, 11:38:43 AM
k thnx, i got 3.5
gonna learn to use it now
Code: [Select]Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>choice /?
CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]

/C[:]choices SPECIFIES allowable keys. Default is YN
/N Do not display choices and ? at end of prompt string.
/S Treat choice keys as case sensitive.
/T[:]c,nn Default choice to c after nn seconds
text Prompt string to display

ERRORLEVEL is set to OFFSET of key user presses in choices.
ok, 2 questions
how would define your default choice?
and
what is errorlevel? (i've seen it quite oftenly in batch files) Quote from: PirateSamir on January 26, 2009, 11:55:00 AM
ok, 2 questions
how would define your default choice?
and
what is errorlevel? (i've seen it quite oftenly in batch files)


Example

Default choice is Y, timeout is 10 seconds

Code: [Select]choice /C:YN /T:Y,10 Press Y or N
echo errorlevel is: %errorlevel%

If Y was PRESSED (or timeout occurred) the %errorlevel% will be 1 (because Y is choice 1) and if N was pressed %errorlevel% will be 2 (because N is the second choice)

errorlevel is a system variable which is set by a program. Often 0=no ERROR, 1 or more means an error. Choice uses it to PASS the key pressed.

Code: [Select]S:\>chtest1.bat
Press Y or N [Y,N]?Y
errorlevel is: 1

S:\>chtest1.bat
Press Y or N [Y,N]?N
errorlevel is: 2so can errorlevel be used for anything else?Quote from: PirateSamir on January 26, 2009, 12:49:58 PM
so can errorlevel be used for anything else?

Yes.

Code: [Select]dir *.txt
if %errorlevel% GTR 0 echo "No text files"

Plenty of information if you use Google.

ok thnx Quote from: hiteshsavla on January 23, 2009, 03:16:25 PM
Code: [Select]@ECHO OFF

:choice
set /P c=Are you sure you want to continue[Y/N]?
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
goto :choice


:somewhere

echo "I am here because you typed Y"
pause
exit

:somewhere_else

echo "I am here because you typed N"
pause
exit


Thanks hiteshsavla - Exactly what I required, saved me a lot of time. (I write batch files so infrequently these days that it takes time to get back into it)
7519.

Solve : loop a batch file that reaads parameter from an external file in XP?

Answer»

here is what i am trying to doI'm not UNDERSTANDING the question. Are these parameters in response to a PROMPT issued by the program? or are they VARIABLES for the batch code itself? It would help if you would show your code and exactly what you need to do.

Let us know. C:\TEST>type notepid.txt
sleep.exe 2476 Console 1 1,000 K
sleep.exe 2952 Console 1 996 K

Code: [Select]@echo off

start notepad joe.txt

sleep 6
tasklist
pause

tasklist | findstr "%1" > notepid.txt

for /f "tokens=1,2 delims= " %%i in (notepid.txt) do (
echo pid=%%j

taskkill /pid %%j

)
Bill's back! Another nonsense post.

7520.

Solve : Batch file only processing a number of records instead of the full file?

Answer»

Hi,

I'm new to batch processing and am really STRUGGLING with this problem. I've a txt file which is created by the below bcp command:

bcp "Select field1,field2 from database_table" queryout c:\OrigFile.txt -c -t, -T

which creates a txt file with the below sample data:
Paddy,O'Culleton
Frank,McPhillips
Patrick J,Hall
T,Martin
,Markey Ltd
Elizabeth,O'Meel
T,Conlan

I then NEED to edit the txt file to remove the occurances of ' in it e.g. O'Culleton should changed to be OCulleton so I put together the following batch script:
@echo off > c:\NewFile.txt & setLocal enableDELAYedeXpansion

for /f "tokens=* delims=," %%a in (c:\OrigFile.txt) do (
set str=%%a
echo !str:^'=! >> c:\NewFile.txt
)

If I run the bcp and then run the above script it does create a new txt file but only outputs the following lines:
Paddy,O'Culleton
Frank,McPhillips
Patrick J,Hall
T,Martin

I have tested loads of different things and I KNOW that if I run the bcp command and then open the actually OrigFile.txt that's created and just manually save this file the above script will work perfectly and output all the records into the NewFile.txt with no problems, however if I run both scripts straight after each other I only get the about 4 records outputed to the NewFile.txt.

I'm thinking the problem is caused by the delims because the first field in the problem line ( ,Markey Ltd) is a space and it's seeing it as delimiter as the default delimiter are and . Is there anyway of limiting the delims command to just use a comma as a delimiter and not a space? Or is there a better way of doing this?

Thanks.
I would try changing the query to directly extract the data as you want it and totally forget about post-processing the file.
So in your case:

bcp "Select replace(field1,'''',''), replace(field2,'''','') from database_table" queryout c:\OrigFile.txt -c -t, -TCode: [Select]import java.util.Scanner;
import java.io.*;
public class ReplacePattern {
public static void main(String[] args) throws FileNotFoundException, IOException{
if ( args.length!=2 ){
System.out.println("Usage: java ReplacePattern [pattern] [filename]");
System.exit(1);
}
Scanner sc = new Scanner(new File(args[1]));
String INPUT=null;
while( sc.hasNext() ){
input = sc.nextLine().replaceAll(args[0],"") ;
System.out.println(input);
}
}
}


use java to run the class file. To replace single quotes,
Code: [Select]java ReplacePattern "'" file



[recovering disk space - OLD attachment deleted by admin]This little ditty might help.

Code: [Select]@echo off > c:\NewFile.txt
setlocal enabledelayedexpansion

for /f "tokens=* delims=" %%a in (c:\OrigFile.txt) do (
set str=%%a
set str=!str:'=!
echo !str! >> c:\NewFile.txt
)

Good luck. Thanks a mil for your all replies, working like a treat now!

Went in the end with the replace SQL command, (had never heard of it before!) as now I only need to run one batch job.
Very happy chappie here! remove '

Paddy,O'Culleton
Frank,McPhillips
Patrick J,Hall
T,Martin
,Markey Ltd
Elizabeth,O'Meel
T,Conlan


C:\test>sed s/'//g OrigFile.txt
Paddy,OCulleton
Frank,McPhillips
Patrick J,Hall
T,Martin
,Markey Ltd
Elizabeth,OMeel
T,Conlan


donpage is Billrich. Ignore.
well, the only thing we can't ignore is he provided a legit solution, so there's nothing really "wrong" with that. Quote from: ghostdog74 on January 09, 2011, 04:55:48 AM

well, the only thing we can't ignore is he provided a legit solution, so there's nothing really "wrong" with that.

I suppose you have a point, but he shouldn't be encouraged!
7521.

Solve : Batch Files and Deleting Subdirectories?

Answer»

Alright lets say for example I have the following file structure C:\Users\user name\DOWNLOADS\

Now in downloads, there are folders. If I ONLY wanted to delete the folders in "Downloads" but not anything else how would I go about doing that. So to reiterate, I want to delete the sub-directories in Downloads, but not "Downloads" itself.
How would I do that in Command Prompt Windows 7.
del c:\src\file.txt
Deletes c:\src\file.txt.

echo.y|del c:\temp\*.*
Deletes all files in c:\temp without stalling for the usual Y es/ N o confirmation. The pipe replies Y es. The exact reply letter required is LANGUAGE specific.

del c:\temp\*?.*
Deletes all files in c:\temp without stalling for the usual Y es/ N o confirmation. The WILDCARD *?.* is EQUIVALENT to the global *.* (since all files have at least one character in their base name), but *?.* avoids a stall. This alternative isn't language specific.

del "c:\my src\*.TMP"
Deletes all files with extension TMP in c:\my src ("quote" path or name if it contains Space s).
That's only for files. I want to remove sub directories without calling the specific name. I want remove the sub directories in the "Downloads" folder, but leave Downloads itself. I can't use a wild card, is there anyway to delete them without calling each one specifically?

Code: [Select]@echo off
cd c:\Users\User\Downloads
dir /AD /b > subdir.txt
for /f "delims=" %%i in (subdir.txt) do (
echo %%i
cd %%i
echo Y | del *.*
cd ..
rd %%i
)
Output:
C:\Users\User\Downloads>subdir.bat
temp
C:\Users\User\Downloads\temp\*.*, Are you sure (Y/N)? Y
tmp
C:\Users\User\Downloads\tmp\*.*, Are you sure (Y/N)? Y

C:\Users\User\Downloads>dir /AD /b

C:\Users\User\Downloads>

7522.

Solve : De-mute and pump up the volume?

Answer»

I want to make a batch-file that should turn off MUTING (you know, the one that resides in the systray) and then set the volume at maximum.

It is going to be part of a batch file that, when finished, warns users if errors occured during processing. Some of these users have their volumes down or muted.

Any help would be great.

WinXP Pro SP1I don't think I like this idea. It sounds suspiciously like a "prank", or worse, especially when read alongside your other post about hiding Media Player.
Sorry i don't know how to but i would ALSO like to know.You may have problems attempting a batch solution. Better to use a VBScript where you can interact with the Volume Control.

There are ways of warning users to errors other than to blast them out of their chairs! A popup message would be a gentler and kinder solution.

Message BOXES



Quote from: Sidewinder on July 09, 2008, 12:20:50 PM

You may have problems attempting a batch solution. Better to use a VBScript where you can interact with the Volume Control.

There are ways of warning users to errors other than to blast them out of their chairs! A popup message would be a gentler and kinder solution.
Message Boxes


@sidewinder:
No VBScripting since I'm totally unfamiliar with that.
BTW, we do not have external speakers, so even with the volume at max it would be close to inaudible. But I realize now this warning could scare the begeebers out off persons if they run it at a place that does have speakers PLUGGED in.

Quote from: Dias de verano on July 09, 2008, 08:42:00 AM
I don't think I like this idea. It sounds suspiciously like a "prank", or worse, especially when read alongside your other post about hiding Media Player.

@Dias: This was meant to run mediaplayer on the background, yes. I did not want users to drag or close screens before the process is finished. Loading time tends to be extremely slow at times and people can be impatient. I 'm new to this and got carried away a little, reading this site. Thought of this solution at first as a funny way to warn. Forgot the KISS principle.


Popup messages appear allmost instantly and stay on screen until user input. Sounds do neither. Using messages is indeed a gentler way, as Sidewinder stated and I 'm looking into it right now.

Thank you both for your feedback and showing me the right path.

Dramklukkel
7523.

Solve : Using variables inside variables?

Answer»
i'm trying to make a simple way to block websites if i lock my machine, the problem is i have a bunch of variables with . . . . . in them and they are set to v.0 v.1 v.2 ect and i need to seperate the variable and have a variable that can increase , this is what i have so far

@echo off
set c=0
set d=0
for /f "tokens=1* skip=1" %%a in ('ipconfig /displaydns') do echo %%b>>%temp%\v.t
for /f "tokens=1* skip=1" %%a in ('findstr .COM %temp%\v.t') do (
call set /a c=%%c%%+1
call set c.%%c%%=%%b
call set d=%c%
)


i need a way to use a variable inside another variable because i dont know how many there is going to be for example, %c.%d%:~11,100% instead of %c.1:~11,100%well you realy need use a Code: [Select]setlocal enabledelayedexpansion for seting variable in loopthanks, so i've been reading more about how this makes it so the variable expansion takes place before the execution of the for command, i understand how it works just not the syntax

@echo off
setlocal enabledelayedexpansion
set c=0
set d=0
for /f "tokens=1* skip=1" %%a in ('ipconfig /displaydns') do echo %%b>>%temp%\v.t
for /f "tokens=1* skip=1" %%a in ('findstr .com %temp%\v.t') do (
call set /a c=%%c%%+1
call set c.%%c%%=%%b
setlocal d=%c%
)


what am i doing wrong?diablo, could you explain in a bit more detail just what it is you are trying to do? In words, I mean?



I'm creating a lock similar to winkey + L only without the password it disables .exe programs and webpages, i noticed recently active connections are viewable using ipconfig /displaydns, the part i dident bother typing was adding them to the host file
when i use FOR to get the tokens , the closest i can get it down too is . . . . . : www.weburl.com , as an example i'm not sure why there is . . . . . : infront of it anyways, to solve this problem i decided to set it into variables and split up the variable to ignore the . . . . . : because i didnt think there was ANYWAY to set delims for charachters, without it ignoring the entire line.. , so i already know splitting the variable to ignore the first 11 charachters is what i want, so %c.1:~11,100% my problem is , there could be well over 100 of them.. and i need to add an ADDITIONAL variable, since all the variables set are c.1,c.2,c.3 , and since i will never know how many there are, and want to avoid lots of lines of code .. i need to use the variable already being set as D , witch is the number of Times LOOPED or in this case would be used as the number of the variable set , and total number set when its finished' i need to use it as a way to increase itself without adding lots of lines.. like for example


for /f "tokens=1* skip=1" %%a in ('findstr .com %temp%\v.t') do (
call set /a c=%%c%%+1
call set c.%%c%%=%%b
setlocal d=%c%
call echo 127.0.0.1 %C.%d%:~11,145%>>hostfiledir\hostfile
)
You want to process the output of ipconfig /displaydns? and grab something? What?

Code: [Select]www.kuching.co.uk
----------------------------------------
Record NAME . . . . . : www.kuching.co.uk
Record Type . . . . . : 5
Time To Live . . . . : 11313
Data Length . . . . . : 4
Section . . . . . . . : Answer
CNAME Record . . . . : homepages.plus.net


pop3.blueyonder.co.uk
----------------------------------------
Record Name . . . . . : pop3.blueyonder.co.uk
Record Type . . . . . : 1
Time To Live . . . . : 14192
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 195.188.53.61


www.onvon.com
----------------------------------------
Record Name . . . . . : www.onvon.com
Record Type . . . . . : 5
Time To Live . . . . : 8243
Data Length . . . . . : 4
Section . . . . . . . : Answer
CNAME Record . . . . : onvon.com


news-text.blueyonder.co.uk
----------------------------------------
Record Name . . . . . : news-text.blueyonder.co.uk
Record Type . . . . . : 1
Time To Live . . . . : 3879
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 195.188.240.200
here is example of using setlocal

with

Code: [Select]setlocal enabledelayedexpansion

if 1 equ 1 (
set var=END
goto !var!
)
exit
:END
pause
without

Code: [Select]if 1 equ 1 (
set var=END
goto %var%
)
exit
:END
pausein the second example, in the third line, %var% will be blank.thanks, but i still dont understand..

setlocal enabledelayedexpansion
set h.0=3985u90289g28gj2
set var=0
echo %h.!var!:~0,1%

and yes im trying to process the output of ipconfig /displaydns, except i cant seem to get just the host name, like www.google.com when i use for i get . . . . : www.google.com and since i need to echo more then one of these variables into the host file, i need it to count automatically.. like echo %c.%d%:~11,100% instead of having to type

echo %c.0:~11,100%
echo %c.1:~11,100%
echo %c.2:~11,100%
echo %c.3:~11,100%
echo %c.4:~11,100%
echo %c.5:~11,100%

because i wont know how many variables it sets to begin with..Is this going in the right direction?

Code: [Select]@echo off
setlocal enabledelayedexpansion

REM for each section, isolate the Record Name line
REM use the colon symbol as delimiter
REM so that there are 2 tokens
REM grab the 2nd token
REM and remove the leading space it will contain
for /f "tokens=1,2 delims=:" %%A in ('ipconfig /displaydns ^| find "Record Name"') do (
set recname=%%B
set recname=!recname: =!
echo !recname!
)

thanks dias and devcom i understand now.
This wont work at all will it? lol , i just realized ipconfig /displaydns is whats already in my hostfileNo it isn't only what is in your hosts file. It shows the contents of the Domain Name System (DNS) client resolver cache, which includes entries that are preloaded from the local Hosts file, as well as any recently obtained resource records for name queries that were resolved by the system.
7524.

Solve : Creating folders using the date?

Answer»

I am trying to figure out how to create new folders in DOS by using a date stamp.

I have tried "mk C:\folder\%date%", but I get a syntax error when doing that. I want the format to be MMDDYYY or MMDDYY doesn't matter.

Help??Try md instead of mkThe md error was just part of the problem. You'll need to parse the date to eliminate the forward slashes (MMDDYYYY).

CODE: [Select]@echo off
for /f "tokens=2-4 delims=/ " %%i in ('date /t') do (
md c:\folder\%%i%%j%%k
)



Any code CONCERNING dates is dependent on your LOCAL settings. You may have to make some minor adjustments to the code.Quote

You'll need to parse the date to eliminate the forward slashes (MMDDYYYY)
Ah right. My format is DD-MM-YY Quote
Ah right. My format is DD-MM-YY

Changing the delimiters and flipping the variables would be what I meant by:

Quote
Any code concerning dates is dependent on your local settings. You may have to make some minor adjustments to the code.

Code: [Select]@echo off
for /f "tokens=2-4 delims=- " %%i in ('date /t') do (
md c:\folder\%%j%%i%%k
)

Many languages have functions for returning singular values for day, month and year regardless of format. Batch code can return the date; the USER has to be aware of the format.

7525.

Solve : Computer language and the meaning and the definition?

Answer»

I would like to DEFINITION and what it means and what it says and stands for such as dos, alo, bsd, linus, unix, and all the other definition LETTERS that are use when trying to understand or FIX something that only gives letters and you must know what those letters STAND for thank you [removed]

Email Address removed to prevent unwanted spam.
-Carbon Dudeoxide
Please provide a valid reason for your question.Google is your friend.

7526.

Solve : how do you copy a hidden file?

Answer»

Hi,

Does ANYONE know how you copy a hidden file.
The file is in the same map.

If you use the "xcopy" command he doesn't find the hidden file.
thanks in advantage

GhihCheck the Attributes of the file you want to copy and change them if necessary...my version of xcopy has the /h SWITCH which can copy hidden/system files.
you can check yours.Perfect that "/h" command works excellent.
thanks a lot.
do you know if that command works with all files (eg. "REG." files)?
I don't want to TEST it cuz than i have the prob that I can't find the reg files anymore.i suppose u mean .reg files?? well, u can always create a dummy .reg file and test it.
xcopy /h is suppose to copy hidden and system files as well, so i guess its the same for .reg files.


This will export or copy a reg file

@echo off

regedit /e files.txt "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceEx"

notepad files.txt

cls
exit

7527.

Solve : Problem using DOS xcopy and a French keybaord?

Answer»

Hi all, I need someone with more knowledge than I have!

I am writing a DOS command set to back up my files to another hard disk. I am USING xcopy and all worked fine until I moved to France. I now have an AZERTY rather than a QWERTY keyboard and Windows XP is a French version.

To save the folder 'Mes DOCUMENTS' (My Documents) I have to enter ""C:\Documents and Settings\Propriétaire\Mes Documents\*.*". However the xcopy fails with the message that it cannot find ""C:\Documents and Settings\Propriútaire\Mes Documents\*.*" See the difference? The é has been seen as ú.

Any bright ideas on how to fix would be much appreciated. I have tried renaming my 'Propriétaire' folder 'owner' but Windows won't let me.

Best regards and thanks !I think Mac runs a French and English XP. Perhaps he will be along to assist. Thanks for your suggestions MAC and others:

Although fearful that it's me that hasn't understood fully what to do, here's where I now stand:
1) My account name is simply 'Home'. Propriétaire doesn't appear anywhere, so I'm unable to change it.
2) I've tried putting the short names in my launched bat file , but this makes no difference. DOS still reports that it can't find my source file.

thank you Mac for your ideas.

I have now moved all my personal files out of 'Mes Documents' and rehoused them in a folder directly in C: This allows xcopy to work fine. It's a BIT inconvenient as Windows always wants to shove things into Mes Documents by default, so I'll have to go around changing all the links.

I like xcopy because I can put the bat file launching the copies as a scheduled task to RUN whenever the computer has been idle for 10 minutes. As xcopy only writes new and changed files, this gives me a MIRROR of any changes to my files ten minutes after I leave the desk. Neat.

7528.

Solve : find and copy?

Answer»

I am trying to find a list of files using wildcards (*.abcd.*) and copy them to another location. I am using xcopy to do that but the problem is that the directory has about 60000 files and it is taking for ever for me to run the batch file.

Is there anyway that I can have it to go and search for the second file in the list once it found an instance of the first file.

xcopy "c:\abcd*.r" "d:\"
xcopy "c:\efgh*.r" "d:\"

I WOULD be GLAD to know if there is any other efficient way to do it.

Thank you,

SrinivasNot really. With 60,000 files you can't expect miracles. If the C: and D: drive are different physical drives, it probably runs FASTER than if C: and D: are logical drives on the same disk. Anything that involves physical I/O tends to be slow since much is happening behind the scenes.

Be patient. Thanks for the reply. Is there anyway that I can stop it from looking through the entire directory once it finds the first occurance. I know for sure there is only one file that matches the pattern.

SrinivasIf you know for sure there is only one file, lose the wildcards and type the fully qualified name. Either way it probably won't make a nanosecond of difference. I/O operations use the file system index to find the file. If you have other I/O intensive programs running concurrently with your batch file, speeds will be reduced.

Even with the fastest disks, I/O tends to be a BOTTLENECK. 8-)

7529.

Solve : how to reject cdrom?

Answer»

RSM command can be used to reject / load for cdrom

but i can not find correct param ?

i have 2 HDDs and 1 CD-ROM 1 CD/RWNot sure what the question is. RSM manages media pools. If you truly need info on RSM, check out:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/rsm.mspx

If you just want to eject a CD drawer, this little script will do fine:

Code: [Select]SET WMP = CreateObject("WMPlayer.ocx")
Set colCDROMS = WMP.CDROMCollection

If colCDROMS.Count > -1 Then
For i = 0 to colCDROMS.Count - 1
colCDROMS.Item(i).Eject
Next
End If

Save the script with a VBS extension and RUN from the command line as: cscript scriptname.vbs

Hope this helps. 8-)THANKS

and can not we use rsm command to ecject / load CD/DWD-RW in DOS ?


i heard that it is possiple ;

7530.

Solve : batch file not working in XP?

Answer»

Can someone tell me why this does not work on XP.

@echo off
start /w regedit /e files.txt HKEY_LOCAL_MACHINE\System\CurrentControlSet\control
type files.txt | find "CURRENT User" > "Current#User.bat"
echo set CurrentUser=%%1>"Current User.bat"
call "Current#User.bat"
del "Current?User.bat" > nul
echo. Hello %CurrentUser% > files.txt
echo. WELL, what do you think? >> files.txt
rem check to see dir for tasks in xp
dir %Windir%\tasks /a >>> files.txt
echo. ****** >>>> files.txt
echo. Password List Below >>>>> files.txt
dir %Windir%\*.pwl >>>>>> files.txt
notepad files.txt
pause
cls
EXITecho set CurrentUser=%%1>"Current User.bat"

To get the first argument to a batchfile it is %1 not %%1
echo set CurrentUser=%1>"Current User.bat"

I don't really understand your batchfile.

uliokay this first section is to export a copy of the current user from the the registery key

@echo off
start /w regedit /e files.txt HKEY_LOCAL_MACHINE\System\CurrentControlSet\control
type files.txt | find "Current User" > "Current#User.bat"
echo set CurrentUser=%%1>"Current User.bat"
call "Current#User.bat"
del "Current?User.bat" > nul
----------------------------------------------------------------------------
this portion prints hello JOE BLOW (username) in the notepad file called files.txt
it also prints Well, what do you think.

echo. Hello %CurrentUser% > files.txt
echo. Well, what do you think? >> files.txt
----------------------------------------------------------------------------
this rem portion is just for my own info, I do not know for sure if C:\windows\tasks is LOCATED there for xp or not. If it is it will export a copy of any tasks waiting to be performed to the files.txt

rem check to see dir for tasks in xp


dir %Windir%\tasks /a >>> files.txt
-----------------------------------------------------------------------------

this will print a **** line to files.txt and the word Password List Below

echo. ****** >>>> files.txt
echo. Password List Below >>>>> files.txt
dir %Windir%\*.pwl >>>>>> files.txt
-----------------------------------------------------------------------------

All of it is then printed to files.txt in notepad and placed on the desktop.

notepad files.txt
----------------------------------------------------------------------------

and of course pause, cls, and exit.

pause
cls
EXIT

When I run the bat on my computer here is what I get.

Hello "Joe"
Well, what do you think?

Volume in drive C has no label
Volume Serial Number is 3031-1400
Directory of C:\WINDOWS\Tasks

. <DIR> 08-17-05 12:59p .
.. <DIR> 08-17-05 12:59p ..
SA DAT 6 10-27-05 6:48p SA.DAT
TUNE-U~1 JOB 502 05-11-98 8:01p Tune-up Application Start.job
DESKTOP INI 65 08-17-05 5:01p desktop.ini
3 file(s) 573 bytes
2 dir(s) 3,659.48 MB free
******
Password List Below

Volume in drive C has no label
Volume Serial Number is 3031-1400
Directory of C:\WINDOWS

Joe PWL 726 01-18-06 11:24a JOE.PWL
1 file(s) 726 bytes
0 dir(s) 3,659.48 MB free


For some reason I can not get it to work in WIN XP I run WIN 98
Oh by the way, if you use echo set CurrentUser=%1>"Current User.bat" it will not print the currentuser name. You must use %%1
for /f %%a in ('type files.txt ^| find "Current User"') set CurrentUser=%%a

echo %CurrentUser% >files.txt
echo Well..... >>files.txt
-----------------------------------------------

searches for the current user in the files.txt and writes it in a new files.txt file.
(If you just need the actual username you can also use the built in variable %USERNAME%)

This won´t work Win98, only in NT,W2k,Xp.

If you have the command tlist on your system, you can use this to list the running processes.

hope this helps
uli


Okay I will give it a SHOT and get back to you with the results.....Thanks ~ DwightWell, what happened was it gave me a ton of hkey listings. I do not know if that is what you intended or not.Oh no. I just wanted to find one current user. The loop finds every entry. Sorry.
I didn't consider how many entries the registry have.

uli

7531.

Solve : Run batch file based on user logged in.?

Answer»

Hi All

Can anyone HELP me out here. I want a login script to run based only on PEOPLE from a specific domain.

I want a batch file to be run based on say Domain1\authenticated users.

I cannot use group policy for this one.

ThanksOn some machines, the %userdomain% variable contains the domain name and the %username% variable contains the login name. You should be able to string them TOGETHER for your purposes: %userdomain%\%username%

This is confusing, are not all users who successfully login considered authenticated users?

Hope this helps. 8-)Yes they are but i have users logging into machines on a different domain to what the user accounts are on. For security purposes we have different domains on different vlans ie no CROSS talk between vlans

7532.

Solve : switching to windows?

Answer»

could anybody kindly let me KNOW what shortcut keys would let us switch to windows when one is playing a GAME in MS DOS mode. here it was not possible to write command.. and do anything.. when restarted again the same game comes...... not possible to exit from the game as well...

please mail me at [emailprotected]Use the windows key to BRING up the start menu, and then close the game while it is minimized.Is this a DOS window in 9x or real DOS mode? If its real DOS mode, REBOOT and hold down the ctrl key while it boots. This should bring up a boot menu. Select "normal" mode. If it is a full screen DOS window and you can't access the close button or a menu to exit, right CLICK on it in the task bar and select "close".

7533.

Solve : Testing for number of Dir's in a batchfile?

Answer»

Hi all

I am trying to test for a number of dir's within a batchfile. Basically if the number of dir's EQUALS a particular number then the script will continue, if not it shoud exit. Something like this

If (dir /AD /B| wc -l)=6 goto cont
exit

:cont
blah blah

There does not seem to be a wc -l equivalent in Windows cmd !!

I have found a utility llc.exe that will count the lines for me but I am struggling with the structure. Could I put the result into a string and do an "if string1 == 6 goto cont" ?

Your help would be appreciated

TIA

Richso
=o=Here is a native cmd solution:
(It works if "#~#" isn´t in any foldername.)

for /f "tokens=*" %%a in ('dir/b *. ^| find /v /c "#~#"') do set count=%%a

if "%count%"=="6" (goto :cont) else (ECHO ... & goto :exit)

:cont

:exit
set count=
:eof


I didn´t try wc yet.

hope this helps
uliHi uli_glueck

Yes your code almost works !

The trouble is for some reason the if statement has an extra space in it after the %count% so as you can see below you get "6 ". The if statement then fails and goes to exit. I guess I could put space after the second 6 but wondered if you knew what could cause the first space. I cant see it myself.

if "6 " == "6" (goto :cont ) else (echo ... & goto :exit )

Thanks

Richso
=o=Oh, sorry. I didn´t have this problem yet.

You can try:

if {%count%}=={6} (goto :cont) else (echo ... & goto :exit)

or

if {"%count%"}=={"6"} (goto :cont) else (echo ... & goto :exit)

I have no machine with a cmd at home, so I can't try it at the moment. There must be a workaround for this problem.
(It is a public holiday today, so I am not in the office) :-)

If this isn´t working you can do

set count=%count: =%

This will cancel eventually existing trailing spaces in the variable count.
Maybe not so elegant, but should work.

hope this helps
uli
Hi Uli

Another ISSUE with your code. It does NOT seem to like double figures. If you set the number you are matching against to say 12 like this -> {"%count%"}GEQ{"12"} and the %count% comes to say 9 then the logic falls over.

I suspect that it is only looking at the first number and as 9 is bigger than 1 it fails.

Any ideas how to RESOLVE this one please ?

Best regards


Richso
=o=Mentioning your OS would have been helpful. In any case this might work on your machine although I'm at a complete loss why it needs to be so redundant.

Code: [Select]@echo off
set count=0
for /d %%a in ('dir /a:d %cd%') do (
call set /a count=%%count%%+1
)
echo Number of sub-folders: %count%

8-)Hi Sidewinder

I thought I had mentioned my OS in my OP, anyway its Windows 2000.

The reason that its has to be "so redundant" is that the script is basically doing content deployment. I am using robocopy to do the actual deployment but beofre it can go ahead I have to know that the content is all there and the best way to do this is to test for the minimum number of dir's. I purge the source after each deployment and copy back in some static content before the new stuff gets added later.

Why dont we use a proper content deployment app I hear you ask, not my choice I can asure you !

Thanks again

Richso
=o=

The earlier code posted was incorrect. The results came up the same no matter what directory was used. This should be ok.

Code: [Select]@echo off
set count=0
for /f %%a in ('dir /a:d /b "%cd%"') do (
call set /a count=%%count%%+1
)
echo Number of sub-folders: %count%

I wasn't referring to your request as redundant; it was in reference to the code I posted.

Sorry about the confusion. 8-)Sidewinder

At the end of your code I am using:

if "%count%" GEQ "22" (goto :cont else (echo ... & goto :failed)

However, the %count% comes to 10 which means it should fail (i.e. it is less than 22) but it does'nt which suggests that only the first figure is being compared (i.e. 1 is less than 2)

What do you think ?


Regards

Richso
=o=Quote

if "%count%" GEQ "22" (goto :cont else (echo ... & goto :failed)

You could try getting rid of all those messy quotes (count has a value even if it might be zero). Also the IF statement syntax is incorrect:
Code: [Select]if %count% GEQ 22 (goto :cont) else (echo ... & goto :failed)
It's DOUBTFUL that only the first significant digit is being used in the compare.

Good luck. 8-)
7534.

Solve : Extracting directory from full path filename?

Answer»

Hi there!

I have a batch file where I GIVE a file name with full path (like C:\Windows\System32\argelbargel.dll) as parameter (%1) and I need to 'extract' the path from it (for use, not just to remove it). Giving the path as additional parameter is not an option in this case.

Possibly this is an easy one, I don't know. It's my first batch file in years. Maybe there is ALREADY a SOLUTION in the forum but the search didn't bring it up (actually I don't know what keywords would lead me there. I tried, believe me).

EDIT: Crap. I forgot the OS specs.
Win XP or Win2003, has to run on both.Without an OS I can only imagine a solution.

On some machines this might work:

CODE: [SELECT]set dirname=%~d1%~p1%
echo %dirname%
8-)I tried it and it works. Thanks!

7535.

Solve : String entry routine for DOS?

Answer»

I am looking for a "string entry" routine that can be included in a batch file; I need to enter a filename into a batch file and cannot figure out how to do it. I had a routine that I got from the internet a couple of years ago which I have reprinted below. Although I have NO CLUE how this works, it DID work FINE until the company upgraded my computer to Windows 2000 PROFESSIONAL. Now, whenever I try to use this routine, all I get is the error message:
FC: Cannot open CON - No such file or folder
Somebody please HELP!!

Old string entry routine is as follows:
> $tmp$.bat fc con nul /lbl /n|date|find " 1: "
> enter.bat echo set STR1=
>>enter.bat echo :loop
>>enter.bat echo if not '%%str1%%==' set str1=%%str1%% %%5
>>enter.bat echo if '%%str1%%' set str1=%%5
>>enter.bat echo shift
>>enter.bat echo if not '%%5==' goto loop
call $tmp$.bat
del $tmp$.bat
del enter.bat

The entered string is supposed to be in the variable %str1%
Using fc to get input from the keyboard is an old trick from Win95 days. Things are much easier today.

Code: [Select]@echo off
set /p str1=What's your name?
echo Hello %str1%!

Hope this HELPS. 8-)Works like a charm!!
Thanks a zillion.

7536.

Solve : Error 32768?

Answer»

Trying to re-install xp and KEEP GETTING a
error 32768........
\biosinfo. inf. COULD not be loaded.
Any idea how this can be CORRECTED?
Thank you for your help in advance.............Clean your XP DISK.

7537.

Solve : Password commands in batch files?

Answer»

I'm TRYING to write a batch file to automate a SQL server truncate command, but it requires a password to be put in to access the command lines. How do I write the Batch file to automatically enter the password?You might try using the pipe, but be aware that not all PROGRAMS can TAKE info this way:

ECHO password | TSQL parameters

The above is just an example. I just chose TSQL arbitrarily.

Does not placing a password in a text file (where anyone can read it) create a security hole :-?

7538.

Solve : Re: For someone else.?

Answer»

Either a VBSCRIPT, which has a sendkey method where you could send the F4 key or a program called AutoIt WOULD be a good solution.

Good luck. 8-)

7539.

Solve : complicated question?

Answer»

ok, here's the thing, perhaps anoyne in amerika looks to the tv serie lost (www.lost.abc.com). In the "hatch" there is a computer where you have to enter a code correctly and on time every 108 minutes... I was wondering if it is possible to do such thing in batch to. This is what the batch should do:


count down every 108 minutes to zero, if you enter the CORRECT code (example: it should recaunt from 108 minutes. If you don't enter the (correct) code within 108 minutes it has to say "boom" or something.

I now it isn't just "a question" and I ask here a half/whole script, but i would appreciate it if someone tels me how you do such thing or is it impossible to do that in batch?

greetz

blackberry 8-)The only thing I can think of is using the shutdown prompt, and just changing the amount of time you have.Quote

The only thing I can think of is using the shutdown prompt, and just changing the amount of time you have.

not such bad idea, but than i still don't have, the thing if you enter the code that it don't shut down. Anybody other ideas?You really need something other than a batch file for this. A HTML Application (HTA) would be a likely solution; the window object has a setinterval method that might be helpful.

The problem here is you need two threads (windows) which need some common point of communication. You ask for a dinky batch solution, so I put forth dinky:

Boom.bat
Code: [Select]@echo off
echo 0 > boom.txt
set count=0
:tag
sleep 1
for /f %%i in (boom.txt) do (
call set /a count=%%i+1
if %count%==6480 (
echo Boom!
goto :eof
) else (
echo %count% > boom.txt
)
)
goto tag

Code.bat
Code: [Select]@echo off
start boom
:tag
set /p var=Enter Code:
if .%var%==.8 (echo 0 > boom.txt)
goto tag



PS. If you need a copy of sleep, try Google for a standalone copy or download the Win2003 Resource Kit.Quote
You really need something other than a batch file for this. A HTML Application (HTA) would be a likely solution; the window object has a setinterval method that might be helpful.

The problem here is you need two threads (windows) which need some common point of communication. You ask for a dinky batch solution, so I put forth dinky:

Boom.bat
Code: [Select]@echo off
echo 0 > boom.txt
set count=0
:tag
sleep 1
for /f %%i in (boom.txt) do (
call set /a count=%%i+1
if %count%==6480 (
echo Boom!
goto :eof
) else (
echo %count% > boom.txt
)
)
goto tag

Code.bat
Code: [Select]@echo off
start boom
:tag
set /p var=Enter Code:
if .%var%==.8 (echo 0 > boom.txt)
goto tag



PS. If you need a copy of sleep, try Google for a standalone copy or download the Win2003 Resource Kit.

i tried a few things out but i don't really understand what the codes does. when i use the script (i open code.bat) i get two dos screens, one whit enter code and another that does nothing, you can't type in it. When i enter 8 nothing seems to happen. And when I enter a code nothing happens.... What i tried to get was:

counting from 108 till zero. If you enter the CORRECT code (the number example at the 70th minute, it recounts from 108 till zero, and so one. If you enter the WRONG code, it says immediately boom OR if you enter the code not at time (not within the 108 minutes) it says boom too.

so perhaps i do something wrong, because the things i want doens't seems to work, can you help me pleas...

greetz

blackberry Code: [Select]@echo off
start boom
:tag
set /p var=Enter Code:
if .%var%==.8 (echo 0 > boom.txt) else (echo 6479 > boom.txt)
goto tag

FYI: Most scripting languages can do date/time arithmetic; batch cannot. Instead of counting down, it's easier to count up to a predetermined number (60*108 with a 1 second delay between increments).

Hope this helps. 8-)There might be an easier way to do this but here is what I have. You have to use 2 batch files. The code to restart the countdown is 4, 8, 15, 16, 23, 42,

RUN this batch file to start the countdown

Code: [Select]@echo off
TITLE Lost Menu
start countdown.bat
:MENU
CLS
Echo Enter in code
set /p code=
echo %code% >%temp%\entercode
GOTO MENU
Countdown batch file

Code: [Select]@echo off
:start
SET thecode=0
IF EXIST %temp%\entercode del %temp%\entercode
SET D=8
SET T=0
SET H=1
GOTO COUNTDOWN

:BEGIN
IF EXIST %temp%\entercode FOR /F "tokens=1* delims=" %%A IN ('TYPE %temp%\entercode ^| findstr /I "4, 8, 15, 16, 23, 42,"') do set thecode=1
if "%thecode%"=="1" GOTO START
IF "%COUNT%"=="099" GOTO DIGITS
IF "%COUNT%"=="009" GOTO DIGITS
IF "%COUNT%"=="100" set COUNT=099
IF "%COUNT%"=="010" set COUNT=009
IF "%COUNT%"=="099" GOTO 1SKIP
IF "%COUNT%"=="009" GOTO 1SKIP

:DIGITS
IF "%COUNT%"=="099" SET H=0
IF "%COUNT%"=="099" SET T=9
IF "%COUNT%"=="099" SET D=9
IF "%COUNT%"=="009" SET T=0
IF "%COUNT%"=="009" SET D=9
IF %D%==0 goto TENS
if %D%==1 set D=0
if %D%==2 set D=1
if %D%==3 set D=2
if %D%==4 set D=3
if %D%==5 set D=4
if %D%==6 set D=5
if %D%==7 set D=6
if %D%==8 set D=7
if %D%==9 set D=8
goto COUNTDOWN

:TENS
if %D%==0 SET D=9
if %T%==1 set T=0
if %T%==2 set T=1
if %T%==3 set T=2
if %T%==4 set T=3
if %T%==5 set T=4
if %T%==6 set T=5
if %T%==7 set T=6
if %T%==8 set T=7
if %T%==9 set T=8
if %T%==0 set T=9
goto COUNTDOWN


:COUNTDOWN
SET COUNT=%H%%T%%D%
Title Minutes Remianing %count%
IF %COUNT%==000 GOTO BAD

:1SKIP
cls
echo Time Remaining %count%
ping -n 2 127.0.0.1 >NUL
GOTO BEGIN

:BAD
CLS
Echo You are too late Process's are set in motion
pause
EXITForgot change the Ping statement to 60 seconds

ping -n 60 127.0.0.1 >NUL

If you use sleep.exe it is a little more accurate at counting.
Quote
There might be an easier way to do this but here is what I have. You have to use 2 batch files. The code to restart the countdown is 4, 8, 15, 16, 23, 42,

Run this batch file to start the countdown

Code: [Select]@echo off
TITLE Lost Menu
start countdown.bat
:MENU
CLS
Echo Enter in code
set /p code=
echo %code% >%temp%\entercode
GOTO MENU
Countdown batch file

Code: [Select]@echo off
:start
SET thecode=0
IF EXIST %temp%\entercode del %temp%\entercode
SET D=8
SET T=0
SET H=1
GOTO COUNTDOWN

:BEGIN
IF EXIST %temp%\entercode FOR /F "tokens=1* delims=" %%A IN ('TYPE %temp%\entercode ^| findstr /I "4, 8, 15, 16, 23, 42,"') do set thecode=1
if "%thecode%"=="1" GOTO START
IF "%COUNT%"=="099" GOTO DIGITS
IF "%COUNT%"=="009" GOTO DIGITS
IF "%COUNT%"=="100" set COUNT=099
IF "%COUNT%"=="010" set COUNT=009
IF "%COUNT%"=="099" GOTO 1SKIP
IF "%COUNT%"=="009" GOTO 1SKIP

:DIGITS
IF "%COUNT%"=="099" SET H=0
IF "%COUNT%"=="099" SET T=9
IF "%COUNT%"=="099" SET D=9
IF "%COUNT%"=="009" SET T=0
IF "%COUNT%"=="009" SET D=9
IF %D%==0 goto TENS
if %D%==1 set D=0
if %D%==2 set D=1
if %D%==3 set D=2
if %D%==4 set D=3
if %D%==5 set D=4
if %D%==6 set D=5
if %D%==7 set D=6
if %D%==8 set D=7
if %D%==9 set D=8
goto COUNTDOWN

:TENS
if %D%==0 SET D=9
if %T%==1 set T=0
if %T%==2 set T=1
if %T%==3 set T=2
if %T%==4 set T=3
if %T%==5 set T=4
if %T%==6 set T=5
if %T%==7 set T=6
if %T%==8 set T=7
if %T%==9 set T=8
if %T%==0 set T=9
goto COUNTDOWN


:COUNTDOWN
SET COUNT=%H%%T%%D%
Title Minutes Remianing %count%
IF %COUNT%==000 GOTO BAD

:1SKIP
cls
echo Time Remaining %count%
ping -n 2 127.0.0.1 >NUL
GOTO BEGIN

:BAD
CLS
Echo You are too late Process's are set in motion
pause
EXIT

fantastic code, but... if you enter the code wrong, nothing happens, and it should happen something. But thanx for the code yet! another problem that i like to be solved, is if you just enter 4, 8, it recounts to, so is it possible that you have enter correctly the exactly combination, nothing else
To make it require the exact code change the findstr.

This will make it require the exact passcode
Code: [Select]IF EXIST %temp%\entercode FOR /F "tokens=1* delims=" %%A IN ('TYPE %temp%\entercode ^| findstr /I /C:"4, 8, 15, 16, 23, 42,"') do set thecode=1
Insert the line below after this lineif "%thecode%"=="1" GOTO START This if they enter the wrong code.

Code: [Select]IF EXIST %temp%\entercode GOTO Wrong
then add this to the bottom of the file

Code: [Select]:wrong
cls
Echo.
Echo You Entered in the worng cade, That was a bad mistake.
echo.
pause
Have funQuote
To make it require the exact code change the findstr.

This will make it require the exact passcode
Code: [Select]IF EXIST %temp%\entercode FOR /F "tokens=1* delims=" %%A IN ('TYPE %temp%\entercode ^| findstr /I /C:"4, 8, 15, 16, 23, 42,"') do set thecode=1
Insert the line below after this lineif "%thecode%"=="1" GOTO START This if they enter the wrong code.

Code: [Select]IF EXIST %temp%\entercode GOTO Wrong
then add this to the bottom of the file

Code: [Select]:wrong
cls
Echo.
Echo You Entered in the worng cade, That was a bad mistake.
echo.
pause
Have fun

bad code, it doesn't work! nothing happens if you enter the wrong code, beside it should be possible if you just enter 4, 8 that is shows the message too, because 4, 8 is just a part of the code and is wrong, does anybody knows an other solution
Aren't you being a bit unreasonable? Two solutions have been offered and all the feedback we've gotten is "it doesn't work" or "I don't understand the code" or "this is what I want". It doesn't help that the SPECIFICATIONS keep changing with each post.

You already know quite a bit. You know you need two threads, you have two different techniques for implementing a timer, and you have enough code to choke a horse. All you need to do is put it together. The best way to learn is by doing.

8-)

Please don't post back with one your more colorful "*censored* is your problem?" comments. We've seen it all before.

I only come here for the entertainment, I am never disappointed. Quote
Aren't you being a bit unreasonable? Two solutions have been offered and all the feedback we've gotten is "it doesn't work" or "I don't understand the code" or "this is what I want". It doesn't help that the specifications keep changing with each post.

You already know quite a bit. You know you need two threads, you have two different techniques for implementing a timer, and you have enough code to choke a horse. All you need to do is put it together. The best way to learn is by doing.

8-)

Please don't post back with one your more colorful "*censored* is your problem?" comments. We've seen it all before.


lol

first of all i only use the such sentences like *censored* is your problem for peoples who really iritate me, just posting here some crap or want to make VIRUSES, or who thinks they have the right to SCOLD to someone (mostly that last reason).
now second, when I read you message it looks like you think that I don't appreciate at all the help the people gave me. That is a totaly wrong vision, I really appreciate the help people gives me, but with my last post I was a bit disappointed that it didn't worked... So I asked (perhaps on a bit impolite way) if he -or anybode else- knew an other solution. and my thirth and last point on your text, you say
you have enough code to choke a horse..... i'm here for learning and yes i learned a lot yet, but you can't expect that if you post a totaly strange code for me, that I understand it within the minute... I am still busy to decipher it.. and if you think that it isn't so hard, whell you can take my work over as seen you can understand everything in two minutes. By monday I would like to have some calculatings for my house that i'm designing now (i'm an architect)
7540.

Solve : how to catch return code/message of Cacls command?

Answer»

Does anyone know if Cacls.exe returns any code or any message? I have a system command like: system(cacls.exe ....), sometimes the command fails, I need to, instead of USE "system(...)" which does not catch any error code or message, output the error code and message and at the same TIME notify people that this permission command fails. Your help will be greatly appreciated!I GET %errorlevel% 0 if the command works. And I get %errorlevel% 0 if the command fails cause it can't find the folder.
What message do you get? (The exact output TEXT.)
The workaround for this problem could be to find / not find a search item with a for /f STATEMENT and use this %errorlevel%.
Please let us know how it goes.

hope this helps
uli

7541.

Solve : List files on drive?????

Answer»

OK This is probably a really easy question for most of you and what makes it worse is that I KNOW that I used to know the answer. Age is a nasty business. messes with the memory cells. :-?

I want a simple command to list the names and whereabouts of all files on my C: drive.

Also is it possible to list only particular file types ie doc, pdf, etc?

Muchos gracias in advance

fizsch

I use the tree command to see what is in the C: drive.Thanks for the quick responce.

I FEEL that I should have made myself clearer. I need to be able to extract the list in some kind of TEXT format so that I can edit it in excel or database.

I have a huge collection of ebooks and articles which I have neglected to catalogue and it's GETTING so big that to do it manually would take weeks, and then I'd probably miss quite a few.

I seem to recall something along the lines of "c:\dir *.*?dirlist.txt" but I've tried this and it didn't work. I've probably got for the lack of corrrect spacings.

Any thoughts?

Cheers

fizschdir /b/s *.doc >docfiles.txt
dir /b/s *.xls >exelfiles.txt
dir /b/s *.pdf >pdffiles.txt

Writes it from all subfolders of your drive in the *.txt file.

hope this helps
uli

7542.

Solve : Start XP in Dos, anyone??

Answer»

Yeah, so... I have a floppy diskette, and I want to know if there is any possible way to Boot from the disk, and Enter command/run program/satanic ritual (j/k) to start windows.

If ANYBODY has info, it would be greatly appriectiated.XP does not have DOS, and it doesn't ruin on DOS. It has a DOS emulator, but you have to start XP to get there. Umm, not sure what u mean, i want to boot xp FROM Dos mode...I don't know how much more clear I can be. Let's try again.

XP does not have DOS, and it doesn't ruin on DOS. It has a DOS emulator (command prompt), but you have to start XP to access it.

Uhh... Please explain:

I have a boot diskette, when i put it in, start it, and open Dos, I can check the version, and it doesn't say "MICROSOFT windows XP". Are you saying that the I/O THINGY I am running before I boot windows is an emulator as well, because that dowsn't make sense...

If i sounded RUDE, i'm sorry - god knows i'm a newbie at this and you... aren't, lol.Come on GX1_Man, explain it.
ROTFLMAO!

I'll start you off....

"In the beginning there was DOS and life was simple & good"....... (Your turn) then windows appeared and the dark ages began.
Dark clouds in the sky and storm. The sun dissapeared.
Many good OSs perished; the human race became enslaved...

Sorry but I had to give my 2 cents.

It is not possible to start XP from DOS-Mode. How do you want to come in DOS-mode without booting a Windows?
Starting with a DOS bootdisk is starting standalone DOS.
Maybe it might be possible to start XP after booting NTFS-DOS. (Then you can read and ,with the commercial version, write NTFS-Partitions.
I never tried that cause it doesn´t really make sense.
This should be ENOUGH explanation.

hope this helps
uliWhen the clouds cleared, there was Windows riding on DOS like a camel on a flea....and Bill Gates saw that it was good (for him)....avgjoe22..... Your seem to be reluctlant to tell us why your trying to start XP with DOS ........ It doesnt work that way ........

If Xp is installed , you simply turn on the computer and XP loads all by itself ....... Are you attempting to reinvent the wheel ?

please let us know

dl65 hmm, don't you just right click your floppy drive and select format, and then tick ENABLE boot disk and click format, then once its done reboot ur pc with the floppy disk in and make sure the bios checks for a boot disk in your floppy drive (press del at the begining of bootup to enter the bios on most pc's)

7543.

Solve : ms dos commands?

Answer»

ok this is weird, i changed it to c:\windows\system32\cmd.exe, and when i type cmd it says c:\windows\system32\cmd.exe up the top, but it doesnt work like usual, if i run c:\windows\system32\cmd.exe or type set path=C:\WINDOWS\system32 in cmd it works... well thanx for all the help ppls:DIt's not weird at all. Running the program with c:\windows\system32\cmd.exe changes the PROMPT to indicate you're logged in to the c:\windows\system32 DIRECTORY. This is where the external commands live and Windows always searches the CURRENT directory before checking the directories on the path.

If you're satisfied with this workaround , that's fine, but there was a permanent solution previously posted.

8-)Yeah i said i did that permanent thing and it didnt work for some REASON:)Are you sure you are typing the command correctly.
Put the command on your NEXT message.

7544.

Solve : Folder sharing attribute in MS-DOS.?

Answer»

Hi! I was wondering, is ther any way I can set the sharing attibutes of a folder using MS-DOS commands and assign ACCESS permissions to it?you can change or give folder / file permissions to a group or a user with:

cacls
xcacls [rk]

(Only for NTFS partitions)
A bit cryptic but possible.


hope this helps
uliCan you clearly explain this to me? As far as I know, CACLS works only for files not folders. Can you give me a sample syntax? Will it be possible assigning folder permissions from a remote computer? To be specific, I wanted to assign permissions on a folder named test from another computer, is it possible?cacls folder /E /G "Username or group":R

will change or set the permissions for the user / group in read.

/E Edits ACLs instead of replacing them
/T Processes files in the current directory and all subdirectories
/C Continues on access denied errors
/R user Revokes specified user access RIGHTS


Rights:

R Read access
C Change (write) access
F Full control
P Change permissions (special access)
X Execute (special access)
O Take ownership (special access)
E read (special access)
W Write (special access)
D Delete (special access)


It should be possible to set rights on remote pcs if you MAP a drive.

Please be careful and let us know how it goes.
I am not courios, just interested.

hope this helps
uli
Thanks for the tip. But I'm afraid that mapping drives isn't really my plan. The reson why I really wanted to know about folders and stuff is because I'd be using it in my VB application...

1. A user interacts with my application.
2. A folder will be automatically created on the server (MKDIR UNC Path).
3. Then assign permission that the owner and a few other people have permission to access it.

It's a Document Archiving Software by the way if your curious about it. I don't want them to be doing the whole document archiving process 'coz I'm trying to avoid catastrophes that might occur from their uncanny mistakes...I need to find MS-DOS for download..Thats possible.
If you can create a folder on a server you can also set the rights of this folder.
This shouldn´t be a real problem.

I can't help you with VB sorry.

uliI'm not askin' for help in VB. I just wantted to know how to share a folder once it's created and set permissions to it after being created and shared. Please help...Ok, I will post an example on monday. (I don´t have a Nt machine at home and am afraid to post something wrong.)
Which permissions do you want to give the users? read write execute?

uliI want to give some users full control whilst others complete access denial. But take not however that I'm planning to do this remotely if possible... Thanks in advance for helping me out...On this site are a few EXAMPLES which should cover your needs:

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

In generell it is better to give groups the rights they need and don't give groups the rights they don't need.
Give single users specified rights if you cannot solve it with groups.
To denie users complete access is critical. Try to avoid this method.
(Never denie a group complete access to a folder. If you are also in this group, you have lost. You don't have a CHANCE to get access!)

hope this helps
uli

Thanks for the help dude! It works like a charm. Again thanks a lot!

7545.

Solve : Getting %2 %3 %4... in one variable (Batchfile)?

Answer»

Hello...
I am working on a little tool for which I need the user Input.
It should work like:

batchname ATTRIBUT what the user types...

I want get the value of %2 %3 %4 .... in one variable.
Problem is I don't know how many values I have.
Is there a "trick" to get it in one variable?

thanks in advance for any help
uli

There are no tricks. Use the shift command inside a loop.

Something like this:

CODE: [SELECT]:TAG
if .%1==. goto getout
set var=%var% %1
shift
goto tag
:getout
echo %var%

You will end up with a concatenated string. I'll leave it you to eliminate the leading space.

Good luck. 8-)Many thanks Sidewinder.

I played around a little bit and found out that this will bring all item from %1... in the variable input:
set input=%*
set input=%input:~5%

This does the job. %1 can only have 3 characters in this case. 8-)

But I will keep the shift solution in mind.

uli

7546.

Solve : Regedit and Batch file help?

Answer»

Hello, I'm needing something probably pretty simple for some of you out there.

What I need to figure out is the commands to USE to delete the FOLLOWING entries;

AccountDomainSid
PingID
SusClientId

out of the HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\WINDOWSUPDATE directory using a batch file.

ThanksSorry, I'm using Windows XP SP/2 if that helps.takeone....... Why don't you just use the registry editor ........?

dl65 I would do that if it were ONE COMPUTER. However, I have about 150 I need to do.

7547.

Solve : C drive help?

Answer»

It's an EPIDEMIC!

7548.

Solve : Commodore64 joystick?

Answer»

Hey there everyone!

I am new here (as you may be able to see) and I have a question to ask. I was wondering how I would get a Commodore64 Joystick to work on my MS-DOS 6.22 laptop.

The joystick connects to the serial (DB-9) plug and is a basic x-axis, y-axis joy, with 1 button. Anyone got any idea of how to make third work?


Many regards to all, kosmroWelcome!
Computer HOPE is the number one location for free computer help.
The forum will help everyone with all computer questions.

Are you sure it is a serial device. I don't think so. Legacy joystick had a port just for the joystick. It was a three or four input port. It had ANALOG inputs.

If you wish to learn how to use that joystick with a modern nPC, this link may be of some help:
HTTP://en.wikipedia.org/wiki/Game_port

If you need some help, come back here. I built a joystick interface long before they were common on the IBM PC. A dual 555 timer (LM556) is used to turn the analog value into a pulse.Quote from: Geek-9pm on March 19, 2012, 12:43:57 PM

Are you sure it is a serial device. I don't think so.

Neither do I. It just happens to use a DB9 connector.

+---------> Right
| +-------> Left
| | +-----> Down
| | | +---> Up
| | | |
_____________
5 \ x o o o o / 1
\ x o x o /
9 `~~~~~~~' 6
| |
| +----> Button
+--------> Ground

OK,, ignore my post.
Commodore64 joystick was not like the Apple type joystick. Instead it was a bang-button type where it is all or nothing, no degree of movement. I was thinking of the analog joystick.Hmmm, ok. I had heard that it was possible to do it, hence why I asked. I do have an analog joystick for an old macintosh (uses the old Apple Serial plug, looks similar to the old PS/2).

Please note, the computer I'm using to run MS-DOS is a Toshiba Satellite 2520CDT. It only has 1 DB-9 (serial) and 1 parallel (printer) port, there is no game port, and no replicator expansion port like some older LAPTOPS have. Just letting you know.


So I doubt that I could get the Apple joy to work because of the port type.


So is there no way to get the Commodore64 joy to work? no driver build or config setup? I have searched around the net for a solution, and I can only get other joys and reviews of the commodore64.Quote from: kosmro on March 19, 2012, 03:46:42 PM
Hmmm, ok. I had heard that it was possible to do it, hence why I asked. I do have an analog joystick for an old macintosh (uses the old Apple Serial plug, looks similar to the old PS/2).

Please note, the computer I'm using to run MS-DOS is a Toshiba Satellite 2520CDT. It only has 1 DB-9 (serial) and 1 parallel (printer) port, there is no game port, and no replicator expansion port like some older laptops have. Just letting you know.


So I doubt that I could get the Apple joy to work because of the port type.


So is there no way to get the Commodore64 joy to work? no driver build or config setup? I have searched around the net for a solution, and I can only get other joys and reviews of the commodore64.

Build yourself an interface



Or buy one

USB Atari RetroPort (works with Atari, Commodore, and Sega Master System digital gamepads and digital joysticks)

http://www.retrousb.com/product_info.php?cPath=21&products_id=70



Stelladaptor 2600 Controller to USB Interface

http://www.stelladaptor.com/



Or buy a joystick with a USB plug



There is plenty of info out there, I'm surprised you could not find any, I just GOOGLED for "commodore joystick to pc" and found plenty of sites and this forum thread (just one of many)

http://sleepingelephant.com/ipw-web/bulletin/bb/viewtopic.php?t=4726&sid=5b9e0133ee61836a4989f19956a30f4dBut does USB work with MS-DOS?
7549.

Solve : startup in DOS not Windows 2000?

Answer»

I need to remove INFECTED files in windows temp file. I have directions from OfficeScan but it says to restart in MS-DOS mode
?#1 - I don't know how to get DOS before Win starts to open? I think it is just a keystroke or combo during that brief moment
text APPEARS in upper left corner.
My system is Win2000 Pro NT 5.0 service pack 4

Computer used to be on network workgroup, but now a stand alone at home. My computer is still SETUP with work group settings but I have all administrator permisions and the file I need to remove is in my "name".local
?#2 - Will that create any problems returning to windows?
Here is a hint. Windows 2000 and XP do not RUN on top of DOS, so there is no DOS except when the operating system is running. And that is not REAL DOS (Many are confused on this. It is command prompt - not the same!)

I have no idea what OfficeScan is. You can boot to safe mode (F8 upon booting before the windows logo) and get to a repair console. Perhaps this is what you want?

Thanks, I'll try that.
OfficeScan is from Trend MicroYou do not have to boot to safe mode nor do you have to be in Dos to remove files from the temp FOLDER. Just locate the files you want to remove and remove them.

As a matter of fact you can remove all files from your local temporary directories - typically \Temp\ or \Windows\Temp\ or \documents and settings\username\local settings\temp.

7550.

Solve : Replace '/' char in a DOS Batch File variable?

Answer»

I have captured today's date into a DOS batch file variable (under XP) using :

SET FILENAME=%date%

Now I want to create a zip file using the returned date, but unfortunately under UK REGIONAL Settings the date is returned with forward slashes as SEPARATORS eg ‘25/01/06’ so I can't create a file with a '/' illegal character in it.

Anyone know how I can replace the '/' with a '-' (or a space) so that the variable CONTAINS '25-01-06' rather than '25/01/06'.

Then I'll be able to pass it to my Zip command :

c:\apps\winzip\wzzip -ex -rP -s %FILENAME%.zip c:\DATA2\*.*


Thanks
set filename=%filename:/=-%

will replace / against - in the variable filename

uliThank you, that worked perfectly.

The only odd thing is that my next command :

c:\apps\winzip\wzzip -ex -rP -s %FILENAME%.zip c:\data2\*.*

where the %filename% variable is used, produces this message :

Warning: no files were found for this pattern that match your selection criteria
: .zip

but then goes on to zip all the correct files. Formerly, when the user supplied the filename manually to the variable, this error didn't occur....