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.

8451.

Solve : How to create batch file to delete files from subdirectories?

Answer»

Hi,
I was trying to create a batch file, that deletes only files with extention "TMP" from a directory and all its subdirectories.
None of the subdirectories should be deleted. I couldnt do this.
Can any one help me? I figured it out, you just have to give,
DEL /S *.tmp
to delete all the files in the subdirectories with extention tmp.
But now I have another issue, it deletes files with *.tmpl also,
I think the problem is DOS matches only 3 character extensions
Can any one suggest me a work around?what version of DOS are you using?

The behaviour you describe does not happen in Windows XP.

BEFORE

Quote


dir /b /s

F:\test\wildcard\text.tmpl
F:\test\wildcard\text.tmpm
F:\test\wildcard\text.tmpn
F:\test\wildcard\text.tmp
F:\test\wildcard\subdir\text.tmpl
F:\test\wildcard\subdir\text.tmpm
F:\test\wildcard\subdir\text.tmpn
F:\test\wildcard\subdir\text.tmp

dir /b /s *.tmp

F:\test\wildcard\text.tmp
F:\test\wildcard\subdir\text.tmp

dir /b /s *.tmp*

F:\test\wildcard\text.tmpl
F:\test\wildcard\text.tmpm
F:\test\wildcard\text.tmpn
F:\test\wildcard\text.tmp
F:\test\wildcard\subdir\text.tmpl
F:\test\wildcard\subdir\text.tmpm
F:\test\wildcard\subdir\text.tmpn
F:\test\wildcard\subdir\text.tmp


Quote

DEL /S *.tmp
Deleted file - F:\test\wildcard\text.tmp
Deleted file - F:\test\wildcard\subdir\text.tmp


AFTER

Quote

dir /b /s

F:\test\wildcard\text.tmpm
F:\test\wildcard\text.tmpn
F:\test\wildcard\text.tmpl
F:\test\wildcard\subdir\text.tmpm
F:\test\wildcard\subdir\text.tmpn
F:\test\wildcard\subdir\text.tmpl

dir /b /s *.tmp

File Not Found

dir /b /s *.tmp*

F:\test\wildcard\text.tmpm
F:\test\wildcard\text.tmpn
F:\test\wildcard\text.tmpl
F:\test\wildcard\subdir\text.tmpm
F:\test\wildcard\subdir\text.tmpn
F:\test\wildcard\subdir\text.tmpl



Thanks for your response. I am using the DOS version that comes with Windows XP Pro SP2.
I dont know why my computer is acting in this manner
PASTING the command i executed in DOS:
Quote
E:\Shared\Test>dir
Volume in drive E is New Volume
Volume Serial Number is C451-6686

Directory of E:\Shared\Test

07/27/2007 12:25 AM <DIR> .
07/27/2007 12:25 AM <DIR> ..
07/27/2007 12:24 AM 0 test.tmp
07/27/2007 12:24 AM 0 test.tmpl
07/27/2007 12:24 AM 0 test.tmpm
07/27/2007 12:24 AM 0 test.tmpp
4 File(s) 0 bytes
2 Dir(s) 34,714,984,448 bytes free

E:\Shared\Test>del /s *.tmp
Deleted file - E:\Shared\Test\test.tmp
Deleted file - E:\Shared\Test\test.tmpl
Deleted file - E:\Shared\Test\test.tmpm
Deleted file - E:\Shared\Test\test.tmpp
Can you please help me out of this?this is very strange. I am also using XP Pro SP2. I would be surprised if this is a feature of XP Home. What happens when you type VER?

Quote

F:\test\wildcard>ver

Microsoft Windows XP [Version 5.1.2600]

F:\test\wildcard>dir /s *.t*
Volume in drive F is Various
Volume Serial Number is 4CCF-8F52

Directory of F:\test\wildcard

26/07/2007 18:39 8 text.tmpm
26/07/2007 18:39 8 text.tmpn
26/07/2007 18:39 8 text.tmpl
3 File(s) 24 bytes

Directory of F:\test\wildcard\subdir

26/07/2007 18:39 8 text.tmpm
26/07/2007 18:39 8 text.tmpn
26/07/2007 18:39 8 text.tmpl
3 File(s) 24 bytes

Total Files Listed:
6 File(s) 48 bytes
0 Dir(s) 26,841,501,696 bytes free

F:\test\wildcard>del /s *.tmp
Could Not Find F:\test\wildcard\*.tmp

Really weird. The version is same,
Quote
E:\Shared\Test>ver

Microsoft Windows XP [Version 5.1.2600]

E:\Shared\Test>

Version of C:\WINDOWS\system32\cmd.exe is 5.1.2600.2180You could try asking in Google Groups in alt.msdos.batch.nt. That is where the real experts live.
Thanks for giving me this information about google groups. I have posted the question and WAITING for the reply. I have the answer to why we had different results. The behaviour you experienced happens if you are using the FAT32 filesystem. It does not happen if you are using the NTFS filesystem.

I tried the same operation on a FAT32 partition I have for use with Norton Ghost, and it happened just like you described.

Quote

D:\>del /s *.tmp
Deleted file - D:\wildcard\text.tmpl
Deleted file - D:\wildcard\text.tmpm
Deleted file - D:\wildcard\text.tmpn
Deleted file - D:\wildcard\subdir\text.tmpl
Deleted file - D:\wildcard\subdir\text.tmpm
Deleted file - D:\wildcard\subdir\text.tmpn


So, convert to NTFS for better, more predictable file name handling!

Have you got some special reason for sticking with FAT32?


Thanks a lot... i was loosing my sleep becoz of this
I tried in NTFS file system, and u r rite.. it works fine.

Actually the system where i need to run this batch file is NTFS(luckly)
I was trying it out in my system which was UNFORTUNATELY FAT32.

But that was really a good piece of knowledge.
Again thanks a lot!!if you had to do this on FAT32 you would have to use some batch tricks to filter out all the .tmpl etc extensions. An INTERESTING little project perhaps... but not tonight.

8452.

Solve : Backup Batch Problem?

Answer»

Hi all,
im making a batch file that backup ups my files into a zip file.
the problem is EVERY time i try to back it all up. the zip file gets cruptted.
heres my code. o and i got Vista
Code: [Select]@echo off
C:\&GT;backuptest.zip
move backuptest.zip C:\Users\Owner\Documents
CLS
title Backup Files
echo Backing up files.......
echo Please wait.
copy C:\Users\Owner\Documents "C:\Users\Owner\Documents\backuptest.zip" /V /Y
ECHO Backup completed!
pause
exit
thanks in advance!I'm no expert on batch scripts but I can tell you why you get a "corrupted" zip file. You're not ZIPPING anything. All you're doing is COPYING the files to a new location and calling them backuptest.zip. In order to do what you want, you'll need a command line zip utility.
7-Zip got a command line version.Thanks Deerpark.No problem... if you can't get 7-zip to work just say so and I'll try and help you out.

8453.

Solve : add date to file that is previous saturday??

Answer»

I would like to rename a file, but I don't want it to have today's DATE, I want the date to be WHATEVER the previous saturday was. For example, I want the file to have the name file.011307 which was Saturday's date. How can I do this? Thanks.Quote

I would like to rename a file, but I don't want it to have today's date, I want the date to be whatever the previous saturday was. For example, I want the file to have the name file.011307 which was Saturday's date. How can I do this? Thanks.

Check your message box here. luvsun27,

Try this:

[edit]@echo off
CALL:jdate jd
SET /a jd=jd/7*7+5
CALL:jdate2date jd y m d
echo.file.%m%%d%%y:~2%
pause
GOTO:EOF

:jdate
...
:jdate2date
...
[/edit]
Get the :jdate function from here http://www.dostips.com/DtCodeCmdLib.php#jdate
Get the :jdate2date function from here http://www.dostips.com/DtCodeCmdLib.php#jdate2date

DOS IT HELP? Why not do it the easy way. RESET the date in the computers clock. Rename the file. Set the clock to correct date.Quote
Why not do it the easy way. Reset the date in the computers clock. Rename the file. Set the clock to correct date.

You're right.

Until I read your post, I was automatically thinking that it was a task that NEEDED to be repeated periodically, and that is not what the original poster said.

I was prepared to swat a fly with an ELEPHANT gun. Sorry....I got someone to help me with a vb script to do this. And yes...this needs to be done weekly, so it's not feasible to change the clock all the time.

I appreciate the help!
8454.

Solve : How to make a prank in DOS?

Answer»

This TYPE of POST should not be MADE on the forums.What about a LOCK, NATHAN?

8455.

Solve : ping computer if no responce do repair?

Answer»

I need to ping google.com, if i get a time out i need to have the bat FILE run all of the commands http://support.microsoft.com/kb/289256/en-us . i have been trying to figure out how to do this on my own. but with school starting it have been hard to find free time.
i am trying to have the bat file ping an ip address, export the results to a txt file. then i want to use a if statement to find "Received = 3". if it finds that string then exit and take no action. if it doesnt find that string i want it to run the repair commands that are at the website above. or if there is an easier way to do this i would appreciate it. but that is what i was thinking would work. sorry, I am new at forums... If you need more info LET me know. thanks!Why received = 3? Why not 4? On my PC ping sends 4 packets. You don't need a text file. Why bother with a packet COUNT? You can just use || to see if the ping was unsuccessful.

ping www.google.com>nul || (
echo Google did not answer
REM repair code here
)









thankyou very much. that helped so much.One more note on this:
You may want to find something different to ping. Like something on the internet that you control, so you know it will be there and allow ICPM echo requests. There is a good chance that Google will block ICMP echo requests at some point in the future, especially if more people start using it to ping for a TEST like yours. If enough computers ping google, it can be the equivalent of a DDOS attack on google.com at which point they will block it for sure. You may notice that many large sites already block ICMP echo, like www.microsoft.com. If you try to ping www.microsoft.com it will fail, even though it EXISTS because ICMP echo is blocked.

8456.

Solve : How do I get to DOS? Need to use Ghost image! Where is DOS??

Answer»

Hello there...

I feel like such a newbie STILL, but I am stuck. My brother set up Ghost at my last format and showed me how to use it, no problem. I have a saved image on D. BUT how do I get into DOS to use Ghost, and I can't remember the prompt to type once in there either? I've tried hitting all my F1, F2..... KEYS on the WAY into Windows with no luck... is there a command I'm missing? My brother disappeared... perhaps he's been rendered?

I can't believe I have forgotten how to enter DOS mode but my pc has run sweet for two years now... :-

:-) :-)

What version of Windows are you running?
I'm using XP, SP2. Is it different for different versions?

You need to boot into DOS from a floppy, a CD-ROM or a pen drive, with ghost.exe on it. Did your brother LEAVE you with any of these things?

However, a two-year-old Ghost image is not going to be much use unless you don't mind going back to how your PC was 2 years ago.

The idea behind Ghost is (I always thought) that you use it often (I do it monthly and before any big change or upgrade).

I don't use my ghost regularly, instead I keep an image of a freshly installed windows with only updates applied. Then if I need to format and reinstall, I can do in 10 min. instead of using an whole evening on it. Then I just apply new updates and update the image. It doesn't take me long to install the programs I use so I like this approach better.

If you have the ghost cd you can boot from it and the dos version of ghost will load. You can restore the image from there. (At LEAST I can do this with my version.)

8457.

Solve : Files= and buffers=?

Answer»

How do I CHANGE the value files for Files=0 Buffers=0 in Windows XP. I have a copy of QUICKEN that will not load WITHOUT these being changed to Files=50 and Buffers=10Read the file C:\WINDOWS\SYSTEM32\CONFIG.NT

Good luck

8458.

Solve : multiple steps including FTP?

Answer»

I have a bunch of STEPS I want to do....FTP files, move them, RENAME them, FTP them again. I can do them using 4 steps (1st batch is FTP, 2nd batch is moving and deleting files, 3rd batch is FTP, and 4th batch is rename files).

I would like to be able to have the user click on 1 batch to execute them all in SEQUENCE. I TRIED the CALL command, but after the first FTP, it stops. If I run each one separately, I can accomplish all my tasks, so I don't think it's my syntax in the individual files.

Can ANYONE assist? thanks.Please post your not working batchfile. It would be easier to help.

By the way:
If you use the move command you don't need to delete the files cause you move them.


uli

8459.

Solve : can't boot from CD-ROM?

Answer»

I have an old Compaq Presario 7800 (P-III, 256 Mb RAM) which I am trying to renovate by installing a new HDD and Win-XP (It used to run Win98 but the HDD went bad, I still have the Win-98 upgrade CD but I no longer have the original Win-95 discs so the Win-98 upgrade does not find the "qualifying components" which allow an upgrade to proceed).
I've installed the new HDD (80Gb partitioned C:=20G, D:= the rest) and that works fine. I have Win-XP Pro on CD but the BIOS does not offer option to boot from CD so that I can install. BIOS offers only floppy and HDD as boot options. If I disconnect the HDD the BIOS then offers floppy and CD-ROM as boot options. I can find no way to include boot from CD when the HDD is connected.
If I boot to DOS from a floppy which includes a CD-ROM driver, I can access the CD-ROM via DOS but the Win-XP SETUP does not run under DOS so I still can't install.
Can anyone please tell me how I can persuade the BIOS to allow a boot from CD when the HDD and floppy are connected ? Thank you.
Try disconnecting the floppy and see if it gives you HDD and CD-ROM as boot options then... just a thought.Thanks Deerpark, I thought of that myself last night, tried it but then it offers only HDD for boot.
Then I put the HDD in another computer (another old Compaq, I seem to have so many of them !), formatted it and installed the XP Pro. Perfect result. Put the HDD back into the Compaq I'm trying to renovate and tried to boot. No go ! This TIME I get the error message "NTLDR Couldn't open drive multi(0)disk(0)rdisk(0)PARTITION(1)" then nothing.

Any other ideas ?

Thanks. rb

You can install from DOS. Boot from a floppy with CD support. You need to load Smartdrv so put smartdrv.exe on the floppy, run it and then run \I386\WINNT.EXE on your xp cd-rom.

You COULD try without smartdrv but xp install may complain.


Thanks for that advice contrex, it led to me solving the problem although not the way you expected.
I have such a floppy with CD-ROM drivers and smartdrv so I tried to boot that way. Could yesterday, couldn't today ! So in trying to get the floppy to boot, I tried disabling the HDD and then the CD drives (there are two). I noticed that when disabling the Primary CONTROLLER I lost the CD drives and when disabling the secondary I lost the HDD. Delving into the guts of the machine I swapped the primary and secondary cables. And there you go: "Press any key to boot from CD" !!!!!
That was not my doing, I can only think that the Compaq tech put the primary and secondary the wrong way round when replacing the motherboard under warranty many years ago. Don't know why it never gave me any problem before.

Anyway, XP-Pro installed and running. Thanks for your help guys. Great job.

Only one small problem remaining, when I boot, I get offered a choice of two OSs, both XP Pro. The first one is the good one I've just installed, the second one is the inoperable one created during one of my installation attempts yesterday. How do I get rid of the one I don't want ?

Quote from: ringbinder on July 26, 2007, 07:06:52 AM

Only one small problem remaining, when I boot, I get offered a choice of two OSs, both XP Pro. The first one is the good one I've just installed, the second one is the inoperable one created during one of my installation attempts yesterday. How do I get rid of the one I don't want ?

You need to edit the c:\ boot.ini file so there is only 1 OS listed. If you paste what it contains we can advise what to do.



Hi contrex. This is the boot.ini file:
[boot loader]
timeout=30
default=multi(0)disk(0)partition(1) \windows.0="Microsoft Windows XP Professional" /noexecute=optin /fastdetect
default=multi(0)disk(0)partition(1) \windows="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

I guess I would need to delete one of those entries, but which one ?
Alternatively, since it is a new installation with no settings, extra SOFTWARE or data, it would be simple enough just to re-format the partition and start over. What do you think ?
JIf the first one you are offered is the one that works, the second one is the one to delete. The order in which they appear in the menu is the order they appear in boot.ini.

If there is only one option in boot.ini, no menu will appear, the computer will just boot straight into the OS.

Both options point to the same partition on the same disk, so you shouldn't have any files to delete.






Great ! Job done. Thanks a lot for your help.
(Great place this !)
J
8460.

Solve : NEED DOS HELP?

Answer»
Windows XP operating system.

I am trying to xcopy a set of files, etc. from one dir to another. But KEEP getting the error that the file already exists on the other dir. so it won't copy "Filename already exists"

I do not want to delete these files on that dir, so what I want to do is IF the filename exists, I want to rename the file one th second dir. Seems straightforward, but I can't get itHI, Bell
Try to CD (ChangeDirectory) in to the DIRECTORY you want to copy to and then DIR to see what your files are named, if they do EXIST there. Then do a RENAME or REN filename1 filename2 to change the name to what your heart desires. # 1 is the name it is, #2 is the name you choose.
8461.

Solve : Start unless file is already open??

Answer»

i have a start command that i WANT to skip if the file is already running. Can this be done?One way shown below. I only execute the start command if it is not running elsewhere.

(Assumes the only way the command is called is via this BAT file)

Mac

Code: [Select]@echo off
if x%1==xDoIt goto DoIt
echo Stuff prior to optional START
if not exist z.go start %0 DoIt
echo Stuff after the optional START
goto Adios
:DoIt
echo x&GT;z.go
echo Stuff that was started.
pause
erase z.go
exit
:Adios
JTWork,

To test if a file is in use try this:
[edit]echo.N|copy /-y NUL "%FILENAME%">NUL&&(
echo.%filename% is not open!
)[/edit]
More details are DESCRIBED here:
http://www.dostips.com/DtTipsCopy.php#_Toc131269956

DOS IT HELP?

8462.

Solve : Batch File error handling using Net Use?

Answer»

I am creating a batch FILE that allows users to re-map their Home network share drive after a vpn connection has been made. Since the mapping is based on their profile, this won't push unless they logon while connected to our network.

We have many offsite locations so, I made it so they have to choose their location and it will map based on their local domain controller.

However, when using NET USE there are a few instances when errors can occur (ALWAYS user error...)

For example. If they haven't vpn'd in yet, its going to throw an error stating that the network path cannot be found - I want to catch this error and replace it with something like "make SURE you have a live internet connection and you can reach the intranet home page first, and try again"
Same goes for if they are allready mapped and they are running the batch file again, it will say something about the drive letter is ALREADY in use... and i would like to replace that error with "Your drive is already mapped, open your my computer and access your H:/ Drive"

Code: [Select]title ~ AVI Information Technology ~ Map My Home Drive

@ECHO OFF
CLS
ECHO ------------------------------
ECHO Name of the Company
ECHO ------------------------------
ECHO Please select your home office location...

:LOOP
ECHO A. Altamonte
ECHO B. Atlanta
ECHO C. Cleveland
ECHO D. Columbia
ECHO E. Cypress
ECHO F. Dallas
ECHO G. Denver
ECHO H. Detroit
ECHO I. Ft. Lauderdale
ECHO J. Jacksonville
ECHO K. Lanham
ECHO L. Las Vegas
ECHO M. Nashville
ECHO N. New York
ECHO O. Orlando
ECHO P. Pittsburgh
ECHO Q. Salt Lake City
ECHO R. Tampa
ECHO Z. Quit

SET Choice=
SET /P Choice=Type the letter and press Enter:
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO ALT
IF /I '%Choice%'=='B' GOTO ATL
IF /I '%Choice%'=='C' GOTO CLE
IF /I '%Choice%'=='D' GOTO COL
IF /I '%Choice%'=='E' GOTO CYP
IF /I '%Choice%'=='F' GOTO DAL
IF /I '%Choice%'=='G' GOTO DEN
IF /I '%Choice%'=='H' GOTO DET
IF /I '%Choice%'=='I' GOTO FTL
IF /I '%Choice%'=='J' GOTO JAX
IF /I '%Choice%'=='K' GOTO LAN
IF /I '%Choice%'=='L' GOTO LSV
IF /I '%Choice%'=='M' GOTO NSV
IF /I '%Choice%'=='N' GOTO NYC
IF /I '%Choice%'=='O' GOTO ORL
IF /I '%Choice%'=='P' GOTO PIT
IF /I '%Choice%'=='Q' GOTO SLC
IF /I '%Choice%'=='R' GOTO TPA
IF /I '%Choice%'=='Z' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:ALT
net use h: \\ALTDC1\users\%USERNAME% /persistent:yes
GOTO Again
:ATL
net use h: \\atldc1\users\%USERNAME% /persistent:yes
GOTO Again
:CLE
net use h: \\CLEdc1\users\%USERNAME% /persistent:yes
GOTO Again
:COL
net use h: \\COLdc1\users\%USERNAME% /persistent:yes
GOTO Again
:CYP
net use h: \\CYPdc1\users\%USERNAME% /persistent:yes
GOTO Again
:DAL
net use h: \\DALdc1\users\%USERNAME% /persistent:yes
GOTO Again
:DEN
net use h: \\DENdc1\users\%USERNAME% /persistent:yes
GOTO Again
:DET
net use h: \\DETdc1\users\%USERNAME% /persistent:yes
GOTO Again
:FTL
net use h: \\FTLdc1\users\%USERNAME% /persistent:yes
GOTO Again
:JAX
net use h: \\JAXdc1\users\%USERNAME% /persistent:yes
GOTO Again
:LAN
net use h: \\LANdc1\users\%USERNAME% /persistent:yes
GOTO Again
:LSV
net use h: \\LSVdc1\users\%USERNAME% /persistent:yes
GOTO Again
:NSV
net use h: \\NSVdc1\users\%USERNAME% /persistent:yes
GOTO Again
:NYC
net use h: \\NYCdc1\users\%USERNAME% /persistent:yes
GOTO Again
:ORL
net use h: \\ORLdc1\users\%USERNAME% /persistent:yes
GOTO Again
:PIT
net use h: \\PITdc1\users\%USERNAME% /persistent:yes
GOTO Again
:SLC
net use h: \\SLCdc1\users\%USERNAME% /persistent:yes
GOTO Again
:TPA
net use h: \\sid\TPA-Users\%USERNAME% /persistent:yes
GOTO Again
:Again
PAUSE
CLS
:End

I've been searching and searching, and can't FIND any error handling within batch files...
is there?

Thanks in advanceYes there is, I'm not use about the 'net' command but try immediately on the line after a net send operation enter "echo %errorlevel% & pause >nul".

Intentionally cause all the errors you can think of and see what errorlevel codes, if any are created. '0' generally means it worked.DeltaSlaya - u da man.

Problem tho.

I was able to duplicate many errors as when i vpn in from home my username isn't right - so i'm able to re-create lots of stuff that i normally wouldn't. So this is cool.

However, I was getting error code number '2' for all three of my major errors:
"incorrect user name and or password"
"network path not found"
"local device name is already in use"

They all return number 2...

Am i stuck?

Maybe if... is there a way to do a test to see if drive h is being used? and/or to test connectivity to the domain controller?

Well you could see if the H: drive exists.

"if not exist "H:\" echo Not exist H: & pause >nul"

For testing the connectivity you could try pinging it. Though I don't think there are errorlevel codes for ping. If you supply more information regarding if thats possible I'll write some code to do it.I dont get how that works?

Code: [Select]if not exist "H:\" echo Not exist H: & pause >nul


If i could atelast get rid of one type of error, that would be cool. Well if there is no H: drive on the person's computer it echos "Not exist H:".dude. my bad.
You have helped out alot! Thanks man.

Enjoy ur weekend.No problem.One thing I should add.. which is what threw me off.

If the drive you're mapping is an empty cd rom drive - it will test out as "not exist" when infact it does.

just fyi.



Well that is logical. If there is no disc in the drive it means there is no storage, and if there is no storage it means nothing can be read or written to. Therefore there is no drive, it is essentially a placeholder until it is able to access data.

8463.

Solve : A batch file that can lock the computer??

Answer»

Is there a WAY to lock the computer through a batch file? But I need a way to unlock it too besides restarting.What do you mean by lock? Putting it on standby (if it is on standby, if RETURNS to the Log On menu without actually logging off your account, and you would still need to ENTER the PASSWORD if you have ONE)?

If so...

rundll32.exe user32.dll, LockWorkStationThanks for the reply, you got to what I was looking for.

8464.

Solve : Capture the systems year, month, date, hours, mins, and second.?

Answer»

I would like to capture the systems year, month, date, hours, mins, and second as a parameter. As a NAME to rename one of my file. How can i do it .

@set a=%date:~0,2%-%date:~3,2%-%date:~6,8%-%TIME:~1,1%-%time:~3,2%-%time:~6,2%-%time:~9,3%


you can use vbscript to get the date/time, independent of your COMP's regional settings
then use the batch for loop, set tokens, can capture the output
Code: [Select]WScript.Echo DatePart("yyyy" , Now),DatePart("d" , Now),DatePart("m" , Now),DatePart("h", Now),DatePart("n" , Now),DatePart("s" , Now)

Quote from: Diablo416 on August 17, 2007, 05:46:40 AM



@set a=%date:~0,2%-%date:~3,2%-%date:~6,8%-%time:~1,1%-%time:~3,2%-%time:~6,2%-%time:~9,3%




Would you mind EXPLAIN the logic to me.

sure,

today is 17/08/2007 according to %date%
if you typed echo %date:~0,2% it would echo only 17
echo %date:~0,3% would echo 17/ , if you typed echo %date:~2,3%
it would echo /08,expand the variable after the letter with :~ the numbers 0,0
are line positions

@set a=%date:~0,2%-%date:~3,2%-%date:~6,8%-%time:~1,1%-%time:~3,2%-%time:~6,2%-%time:~9,3% &LT;< here i used postions that wont show a \ ,so that when you use %A% as a file name. because \ might not allow it, i replaced them with dashes -
8465.

Solve : EvID4226Patch Script?

Answer»

I am looking to script the "patch" EvID4226Patch. So far all i can find to do this is the line (EvID4226Patch /L = ##) this works fine but it comes up and asks me if I am sure and I am not sure how to CODE the script to answer this or EVEN if it is possible? Any help would be great.


HISTORY: This is needed because of an in house APP that uses the connections fast and we jsut recently upgraded to service pack 2. have you tryed EvidID4226Patch /? to see what it says?
/L = Presents a limit (Valid Values from 10-16777214)
/F = Se the file to be patched. Does NTO touch any other files. (no /W)
/W= Set the windows directory if DETECTION fails(No /F)
/U = Uninstall patch and reinstall safety-copy (no /F or /L)

8466.

Solve : shimgvw.dll any parameters ??

Answer»

Hi !

I open a TIF file with Microsoft Fax Viewer in a BATCH file LIKE this :

rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen C:\file.tif

But I want to open the file minimized. Is there another parametre except ImageView_Fulls

Thanks

Osman

ImageView_Fullscreen
ImageView_FullscreenA
ImageView_FullscreenW
ImageView_PrintTo
ImageView_PrintToA
ImageView_PrintToW
ImageView_fullscreenW
DllCanUnloadNow
DllGetClassObject

8467.

Solve : How I can use space in name of files, addresses or folders in batch files??

Answer»

Hi All
How I can USE space in name of files, addresses or FOLDERS in BATCH files?
Thnx alotuse quotations around the word that needs a space..

PROGRAM files
"program files"

8468.

Solve : Taking files from one folder and putting them in another through dos/batch?

Answer»

I'm TRYING to create a batch file that will copy the FILES from one folder and paste them into another folder.. but I don't really know how to Code: [Select]copy /?
Or;

Code: [Select]xcopy /?
Or [if you have vista];

Code: [Select]robocopy /?
should reveal all the information you need.

Basically it's just:

Quote

copy "DIRECTORY TO COPY\*.*" "OUTPUT DIRECTORY"

Or with xcopy:


Quote
xcopy "DIRECTORY TO COPY" "DIRECTORY TO COPY TO" /E
Thanks.. erm I don't know how my eyes skipped over copy... I looked through the help list at least 5 times. But thanks again.Yea, well it's there:

Quote
COLOR Sets the default CONSOLE foreground and background colors.
COMP COMPARES the contents of TWO files or sets of files.
COMPACT Displays or alters the compression of files on NTFS partitions.
CONVERT Converts FAT volumes to NTFS. You cannot convert the
current drive.
COPY Copies one or more files to another location.
DATE Displays or sets the date.
DEL Deletes one or more files.
DIR Displays a list of files and subdirectories in a directory.
DISKCOMP Compares the contents of two floppy disks.
DISKCOPY Copies the contents of one floppy disk to another.
Heh yeah I seen it just a few minutes ago, but I got it to run so thanks.No problem. If you need any more batch / command prompt advice we're glad to help.
8469.

Solve : Capture the content of the txt?

Answer»

i would like the capature some letter within the CONTENT of the txt file.
if the content is:ABC,59.
i would like to capture to 5 and 9 it is the 5th and 6 digit as an variable. How can i do this?Quote

@ECHO off
set x=
for /f "usebackq tokens=2 delims=," %%I in ("filename") do (
set x=%%I
)
echo %x%
pause

That will only work if it's not homework.Quote from: cityjack on August 16, 2007, 11:40:43 PM
i would like the capature some letter within the content of the txt file.
if the content is:ABC,59.
i would like to capture to 5 and 9 it is the 5th and 6 digit as an variable. How can i do this?
show an actual SAMPLE of the txt file. also, is ABC always fixed?ABC is not fixed.
the sample:
234,AB

I would like to capture the 5th and 6th digit as parameter.
8470.

Solve : Some dos question?

Answer»

I would like to check the script error within the batch file.
And i find this code:
"ESSCMD LOAD.SCR (one of the script statement)
If not %errorlevel%==goto Error

Echo All operations COMPLETED successfully
EXIT

:Error
Echo There was a problem running the script"

I would like to as what is the function of == ?
and Is %errorlevel% just a varable?

if this statement is not correct, can anyone help me ?

Thanks a lot

"==" compares two strings. 'IF/?' for more information.

And yes "%errorlevel%" is a variable that commands alter, regarding how they completed, successfully or not. It is also used for 'choice'.when i try to test the following command, i get some problem.
First: it show that 'W' is not recognized as an internal or external command. operable program or batch file.
Second, if 'W' which is a bat file , it is work.

My question is i just want to check the script command correct or wrong, if correct return 0 to me , otherwise echo 1.

@echo off
LOAD.SCR
If not %errorlevel%==goto W

:W
Echo 1== MEANS "equal to"

errorlevel is not really a variable. It does not have percent signs around it and you cannot set its value, or read it, just compare it to fixed values.

It is used like this

SOME COMMAND
if errorlevel 2 goto label2
if errorlevel 1 goto label1
if errorlevel 0 goto label0
goto message

:label0
some code here
goto end

:label1
some code here
goto end

:label2
:some code here
goto end

:message
echo error code was not 0, 1 or 2

:end




Do errorlevel = 0 mean not error, not equal 0 having error ?Quote from: cityjack on August 16, 2007, 07:59:55 AM

Do errorlevel = 0 mean not error, not equal 0 having error ?

It's not "errorlevel=0" , it's "errorlevel 0".

It can mean that, but not always! It means that the program returned an errorlevel, and the errorlevel was "0". DOS Errorlevel is a return code sent by a terminating program such as batch, exe, com or any applications. ERRORLEVELS are not a standard feature of every command. What the return code means is up to the programmer. However, most (not all) programmers agree that an errorlevel 0 means the command executed successfully, and an errorlevel 1 or higher usually spells trouble. But there may be some exceptions to this general rule.



8471.

Solve : Configure proxy using cmd.exe???

Answer»

How do i CONFIGURE a proxy server in batch?that's a very VAGUE DESCRIPTION of your problem. What kind of proxy server you are using? give the forum more information.i just want to configure http proxys threw cmd.exe , for use in internet explorer.. i tryed ipconfig , an two others but no luck??

NEVERMIND , reg.exe does the trick
8472.

Solve : Batch File for AutoLogin & AutoBackup?

Answer»

Hi,
I have come here hoping i'll get a solution for the above subject.

We ahve 200+ cisco devices( switches & routers) for which ssh/putty is configured, we need to take backup of the config every week . this is a very cumbersome and time consuming.

Do anyone has script/batch file for logging into device by giving username password and run some commands. it should do the following things.

ssh to 2.2.2.2
username abcd
password xxxxx
copy running-config tftp
tftp ip 3.3.3.3

Moved to MS-DOS --Zylstra
(Thanks, DeltaSlaya for letting us know)This would have probably been better SUITED in the Microsoft DOS forum.

First off, do you know of any way of connecting to the routers in a Command Line, because I can't say I do.
What I'm asking is how do you do this currently? Through a prompt or by logging in in internet EXPLORER?

Most likely there'll be a VBS solution to this, which will be posted SOON, more information may be required.you can simply just put whatever commands you used to log in to those cisco devices into a batch file?

8473.

Solve : TXTs to XLS or TXT Merge?

Answer»

I'm tring to merge 4 txt files to 1 file (either a xls or txt) Its easy to do, but the output file list the files contents under each other. Is there dos code where by these files can be listed next to each other, EG xls into coloms and/or txt tab deliminated.

eg.

1.txt = 1,2,3 >>>> Output file 1 A
2.txt = A,B,C 2 B
3 C

Poenie
Yea I'll try do something in batch, it might take a while...Ok I'll do one where the input files are delimited by ","s and I think the input files are going to have to be the same length.

One question, WTH is this going to be used for, I can't see any use except homework?warning: not tested with different data formats. Only TEST with supplied example input files.
Code: [Select]Option Explicit
Dim objFSO,myFile1,myFile2,myLine,strF1,strF2
Dim objF1, objF2,ARRAY1,array2,bigArray1(),bigArray2(),i,J
Set objFSO=CreateObject("Scripting.FileSystemObject")
myFile1 = "C:\temp\1.txt"
myFile2 = "C:\temp\2.txt"
Set objF1=objFSO.OpenTextFile(myFile1,1)
i=0
Do Until objF1.AtEndOfLine
array1=Split(objF1.ReadLine,",")
ReDim Preserve bigArray1(i)
bigArray1(i) = array1
i=i+1
Loop
i=0
Set objF2=objFSO.OpenTextFile(myFile2,1)
Do Until objF2.AtEndOfLine
array2=Split(objF2.ReadLine,",")
ReDim Preserve bigArray2(i)
bigArray2(i) = array2
i=i+1
Loop
For j=LBound(bigArray1) To UBound(bigArray1)
For i=LBound(array1) To UBound(array1)
WScript.Echo bigArray1(j)(i),bigArray2(j)(i)
Next
Next
set objF1=Nothing
set objF2=Nothing
set objFSO=Nothing

output:
Code: [Select]C:\temp>more 1.txt
1,2,3
4,5,6

C:\temp>more 2.txt
A,B,c
D,E,F

C:\temp>cd \vbscript

C:\vbscript>cscript /nologo test.vbs
1 A
2 B
3 c
4 D
5 E
6 F

C:\vbscript>
Yea I wasn't able to figure out how to make this in Batch without being a max of 26 or having a bunch of variables.Quote from: DeltaSlaya on August 18, 2007, 03:33:50 PM

Yea I wasn't able to figure out how to make this in Batch without being a max of 26 or having a bunch of variables.
why use batch? there are many other excellent program languages around that fills in what batch lacks.I know.. The OP asked for batch so..

I know C# but I don't think you can use it for stuff like this..Quote from: DeltaSlaya on August 18, 2007, 06:06:11 PM
I know.. The OP asked for batch so..

I know C# but I don't think you can use it for stuff like this..
i think that if you know and its easier to do, just post. This forum is for learning , isn't it.? even if OP cannot or don't know how to use C#.
8474.

Solve : User authentication and opening a program?

Answer»

Hello everyone,

First time poster looking for help. You guys all seem friendly (having trawled through previous posts looking for a solution prior to posting) so i THOUGHT i'd join you and request your assistance.

I'm looking for a way of giving access to a particular part of a network and then automatically opening a program.

Basically, i am based in England (the company HQ) and we use a piece of scanning software which has it's own server on our network. We also have a satelitte office in Holland. They can connect to certain parts of our network but have to enter their username and password to authenticate themselves to gain access.

What i want to do is create a program (.BAT ) that when run (clicked) directs them to the area of the network where the program is STORED (THUS forcing the authentication prompt) and then after they've ENTERED their un & pw closes the folder and launches the scanning software.

Is this possible?

We use Windows XP sp2 on our PC's and Windows 2003 on the servers. The Dutch guys connect via a VPN.

Any other INFO required please ask.

Thanks in advance.This area of the network you're directing them to -- is this a unc path?Yes that's correct. It's:

\\INVU\INVU200 (or \\servername\foldername)

Ordinarily when attempting to access this area of the network they get a prompt to enter their username and password, which is what i want, but as i said i then want it to launch the scanning software after they've entered the required info.

Any help much appreciated. I wouldn't know how to make a program run after authenticating a unc path, but you could just write a little "runas" script which should acomplish pretty much the same thing. They wouldn't have to browse the UNC though.

8475.

Solve : VbsToEXE?

Answer»

The original program I suggested was an example, you can look for others.

If ghostdog wants to, and depending on the size of the script I guess as a last resort ghostdog COULD 'convert' it for you??Quote from: DeltaSlaya on August 18, 2007, 06:01:30 PM

I guess as a last resort ghostdog could 'convert' it for you??
hmm..not really. (unless i seen some effort). Haha, didn't think so, If he gave it to SOMEONE else maybe they'd have more luck using a program to convert it anyway?Well, I had fun and enjoyed the COMMUNITY here and did learn a couple things.

Thank you all for that.

The search continues.

Rgds
Selvan
The Last BornsQuote from: ghostdog74 on August 18, 2007, 05:55:34 PM
you should try to learn some vb instead of wasting time doing this.

I said that too. Glad I'm not the only one.



8476.

Solve : Running dos with a text file.?

Answer»

My main goal atm is to start a batch FILE by starting a txt file.

So when I click the text file I made I want it to start my batch file and start executing the commands I put in, is there a way to do this?

TY, -hertebeest-Quote

My main goal atm is to start a batch file by starting a txt file.

So when I click the text file I made I want it to start my batch file and start executing the commands I put in, is there a way to do this?

Ty, -hertebeest-

Batch files are text files.

If you want to be able to click a text file that you made and have it run, rename it.
As in foo.txt renamed to foo.bat.

If within foo.bat you want to run yet another batch file, you can do that too.

No no no I want the .txt file to become a .batch file ONLY when I start the .txt file if you get what I mean.

So if a friend of mine (WICH i SEND the .txt file to) opens it, it doesnt open .txt but it opens .bat.

So basicly make a .bat file look LIKE a .txt file ^^.

Thx in advance, -Hertebeest-I don't believe there is a way to do this. Each extension serves their own purpose. In your case .txt will open as a text file and .bat will of course open as a batch. You can't make a .bat file look like a .txt.Have a read through all of these. There is something in the 1,230,000 links that will be just right for you:


http://www.google.com/search?hl=en&q=batch+file+tutorial
>.>
8477.

Solve : kill a certain process?

Answer»

I have 2 batch scripts and i need when run ONE of them, that it to kill the other one that can't be otherwise closed.
I tried pskill.exe from http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/PsTools.mspx

pskill cmd

and the problem is that it closes both BATCHES as they have same name: cmd
How can i write the second batch to GET the PID1 of the first batch and close it by

pskill PID1

Can i assign my own Process ID to a process?
Is it any other way to kill that process?one idea is to SET a window TITLE when you run your batch using title...then you can use tasklist/tlist to find the process with that windows title.taskkill /F /IM blahblah.batThanks very much,
i don't know why i was not notified, i'll check that.

8478.

Solve : Copy to new drive?

Answer»

Okay i CANT figure this one out. I want to copy the contents of a folder to a folder on my psp and then delete what has been COPIED. Basicaly i want it moved from the psp folder on my desktop to the music folder on my psp. But i dont want to specify what is to be copied. I just want all the files moved to the PSPCopy "E:\foldername"
del "E:\foldername" /f /s

Try that. Yeah that pretty much helped. After working at it to figure it out I got:

Code: [Select]Copy music k:\music
del music /f /s
thanxokay now how do i make it so that it doesnt ask if i want to delete the folder? i still want it to just not to askCode: [Select]Copy music k:\music
del music /f /s /q
/q puts it in Quiet Mode so it will automatically delete it WITHOUT the prompt.thanx alot it works greatCan I get this to run automatically every time the K: drive is connected? And if I can how?I don't KNOW but this might work.

In notepad:

Code: [Select][arutorun]
open=file.bat
save that as autorun.inf and put it in the root of the removable drive.no i dont think that worked. but thanx anyway@Gamerx365, I'd like to know what programming language(s) are taught at your school, is batch one of them?haha all they teach at my school is typing and msword. at least so FAR but im going into the high school in about a monthWe don't learn any programming languages at my school (and i'm in year 10)
Although my class was the first class to test our new school website....yeah im going into 10th and i think my only computer class is msoffice. and i have graphic communications whatever that is lol

8479.

Solve : Edit.?

Answer»

Edit.On which os do you WORK? Do you want that something starts up with your pc trough an edit in the registry made by a batch file?
This you can do by (for winxp):
Code: [Select]&GT;>filename.reg ECHO WINDOWS Registry Editor Version 5.00
>>filename.reg ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
>>filename.reg ECHO "WH"="\"C:\\WINDOWS\\WH.bat\"" (in this example it launchec wh.bat in the windows map)
to launc the reg file
Code: [Select]REGEDIT /S filename.reg

8480.

Solve : Uneditable batch file?

Answer»

Any WAY I could make it so when you right click on the batch file you can't click edit and see all the code to it?Sorry, but no, that isn't possible.Well you could convert it to exe with a batch to executable converter. Though then technically it's no LONGER a batch file and doesn't fit your specifications..Making it into an exe was what I was looking for, I googled it and got what I WANTED. Thanks.Quote

Making it into an exe was what I was looking for, I googled it and got what I wanted. Thanks.

This isn't what you stated you wanted to do in the FIRST place...Well it didn't really matter if it was a .exe file or a .bat file, I just wanted my program's code to be HIDDEN from other users.
8481.

Solve : LOG file creation?

Answer» HI ALL,

I wanted to log the FTP status in a log FILE, for this i have created ONE script file which contains msdos commands and a batch file which contains FTP commant to execute the script file.But how can I create a log file for status USING either FTP ot ms dos commands or HELP me out nay other work arounds
.thanks
Ram
8482.

Solve : txtsetup.sif status 14 is corrupt or is missing?

Answer»

How can I fix this problem?Welcome to the CH forums.

Please read this...

Await your RESPONSE..


Sounds like the person is noodling around with WinPE. Maybe on USB. Perhaps on a server. Not exactly an everyday problem. More like a "please do my job for me" type question. Dnoonkeste, if you want any help, you should not just post a 1 LINE question. Also, do your own research first. I spent 30 seconds on Google and found what is likely to be your problem.

Im actually getting the same error. I have WinXP home edition. Ive spent this entire weekend TRYING to fix the problem. This error comes up in the boot process before i have a chance to f8 into safe mode. Last thing I did before I started getting this error was running an anti virus PROGRAM.
I have a boot utility disk that allows me to view files and edit them. So i was able to verify that this file exists but I am guessing it got corrupted by deleting a virus attached to one of the files within the txtsetup.sif file. Any suggestions? Know of any bootcd / utilities that could at least get me into safe mode so i can TRY to utilize a restore point? Anything would be appreciated

8483.

Solve : need help to create simple loop?

Answer»

Hello
I need a help to do a smple LOOP in Ms-DOS \windows XP
A loop to repeat excute file for 25 times by increasing 1 by 1( from 1 to 25)
and is it possible to open a file its name is a number corresponding to the variable no. each time(1,2,3...25)??
for example in basic:

for n=1 to 25
run n.txt
next n
end

thank you very much , I have limited experience with Ms-Dos, Please help meYou mean something like this...

Code: [Select]FOR /L %%G IN (1,1,25) DO start %%G.txt
8-)fffreakYessssssss Dear
Thats what I need
THANX a lot[size=14][/size]Please don't call me that . Also, TRY not to use DIFFERENT font colors, if you do you will get less responses to a particular problem, just stick with the default. And your welcome .

8-)fffreakOk
&AMP; thanx again

8484.

Solve : opening the file with a space?

Answer»

I have the following code and it works fine until the very last line

Code: [SELECT]::QuickiHTML was created by Seth Howard on August 17, 2007

set pversion=Version 1.1
set pdate=August 20, 2007
set helpurl=http://lightstormlabs.com/quickihtml.html
set helpname=Lightstorm Labs
set color=0C
set title=QuickiHTML
set helptext=

if exist Info.txt goto start
echo THIS IS A FIRSTIME TEXT. DO NOT DELETE THE INFO FILE AND THIS>Info.txt
echo SHOULD ONLY POP-UP THE FIRST TIME YOU USE THIS PROGRAM!>>Info.txt
echo ================================================================>>Info.txt
echo.>>Info.txt
echo QuickiHTML>>Info.txt
echo By Seth Howard>>Info.txt
echo.>>Info.txt
echo ================================================================>>Info.txt
echo.>>Info.txt
echo QuickiHTML %pversion% >>Info.txt
echo %pdate%.>>Info.txt
echo.>>Info.txt
echo ================================================================>>Info.txt
echo.>>Info.txt
echo QuickiHTML was created for the following uses:>>Info.txt
echo.>>Info.txt
echo 1. To help create HTML documents much faster>>Info.txt
echo 2. To help HTML beginners>>Info.txt
echo 3. To help with DOS code peices>>Info.txt
echo 4. To GIVE new ideas to batch PROGRAMMERS>>Info.txt
echo 5. Additional Lightstorm Labs advertising>>Info.txt
echo.>>Info.txt
echo Any other use of this program is a questionable use. Thus meaning that you>>Info.txt
echo are required to visit the website and check that your use is okay. The address>>Info.txt
echo is http://lightstormlabs.com/quickihtml.html . Yes, the code is available to alter and>>Info.txt
echo be copied. The code IS NOT for resale, the batch file is not for resale, the address>>Info.txt
echo URL is not for resale, the compressed folder is not for resale. By using>>Info.txt
echo QuickiHTML, you are agreeing to all of the above. If you do not agree,>>Info.txt
echo delete QuickiHTML now.>>Info.txt
start Info.txt

:start
@echo off
CLS
color %color%
title %title%
set /p name=What do you want it to be called?
set /p background=What color background?
set /p text=What color text?
set /p top=What do you want the top to say?
set /p para1=What do you want the paragraph 1 to say?
set /p para2=What do you want the paragraph 2 to say?
set /p para3=What do you want the paragraph 3 to say?
set /p bottom=What do you want the bottom to say?
echo ^<title^>%name%^</title^>^<body bgcolor="%background%"^>^<font color="%text%"^>^<big^>^<big^>^<big^>^<big^>^<center^>^<b^>%top%^<hr^>^</b^>^</big^>^</big^>^</big^>^</center^>%para1%^<br^>%para2%^<br^>%para3%^<hr^>^<big^>^<center^>%bottom%^</big^>^</big^>^</center^>^<br^>^<br^>^<br^>^<br^>^<br^>^<br^>^<br^>^<br^>^<sup^>>"%name%".html
echo This PAGE was made using QuickiHTML from ^<a href=%helpurl%^>%helpname%^</a^>>>"%name%".html
start "%name%".html
The very last line instead of opening the page, it will start command prompt. It probably has a simple fix but as the tree said to the lumberjack, I'm stumped.try

start "%name%.html"hmmm nope. still doesnt work. thanx anywayCode: [Select]start "" "file with spaces".txt
yeah that worked great thanx alot

8485.

Solve : How to get HDD ID with a batch file??

Answer»

Hi !

Is there a way to get HDD ID using a BATCH file?

Thanks

Osmannot SURE if its device id you want.
Code: [Select]Option Explicit
Dim colItems,objWMIService,objItem
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive")
For Each objItem in colItems
Wscript.Echo "Device ID: " & objItem.DeviceID
Next
save as myscript.vbs and run from command prompt: cscript /nologo myscript.vbsDear ghostdog74,

I want to get HDD Serial number.
My aim is to prevent my program to run on another PC by controlling HDD Serial number in a batch file.

Thank you for your help.wmic diskdrive get SERIALNUMBERFor me personally there is no value in the serialnumber of diskdrive. For me 'diskdrive get pnpdeviceid' seems to get some ID value.

Anyway, if you don't know how, this is how to use it in a batch file:

Quote

@echo off
set HDDID=
for /f "usebackq skip=1 delims=" %%I in (`wmic diskdrive get PNPDeviceID`) do (
set HDDID=%%I
goto out
)
:out
echo %HDDID%
pause >nul
I've found a way to control another unique number at last.

Thank you all for your help.


Osman
well, then you should say "serial number" and not "ID".
Code: [Select]Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each drives In objFSO.Drives
If drives.DriveLetter = "C" Then
WScript.Echo "Serial number is ", drives.SerialNumber
END If
Next
output:
Code: [Select]Serial number is 202343032
8486.

Solve : Finding and formatting the time of a file creation?

Answer»

Hi All.

I am wanting to write a batch file to rename a file with a date and time in the filename.

I have managed to write one that compiles the date into YYYYMMDD and the time into hhmm but I cant for the life of me make it get the seconds as well.

Below is my code for the part I have working. It produces hours and mins but the secs variable is of the form "a.m." rather than a number. I know this is because of the /t in this line "FOR /F "TOKENS=*" %%A IN ('TIME /t') DO SET TIME=%%A"

I know that I should be able to change the time /t to just time but then the code hangs for some reason, Im thinking its SOMETHING to do with the tokens bit or the delims bit.

Any advice would be greatly appreciated ESPECIALLY if it retrieves the seconds but not the decimal part of the time returned when the time command is used.

Cheers

Chris

==========================
for /f "tokens=1-8 delims=.:/- " %%d in ('date /t') do set date=%%g%%f%%e

FOR /F "TOKENS=*" %%A IN ('TIME /t') DO SET TIME=%%A
:: Delims is a TAB followed by a space
FOR /F "TOKENS=2* DELIMS= " %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v itime') DO SET iTime=%%B
FOR /F "TOKENS=2* DELIMS= " %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v stime') DO SET sTime=%%B
FOR /F "TOKENS=1,2* DELIMS=%sTime% " %%A IN ('ECHO %TIME%') DO (
SET HOUR=%%A
SET MINS=%%B
SET SECS=%%C
)
=======================================

I'm almost embarassed to post this, figuring I must have missed something. As far as I know, the registry keeps neither the date or the time; only settings on how they and other types of data are formatted.

This snippet will extract the date and time:

Code: [Select]set dt=%date:~10,4%%date:~4,2%%date:~7,2%
set tm=%time:~0,2%%time:~3,2%%time:~6,2%

You can then use the %dt% and %tm% variables to rename your file:

ren fileA.xxx fileA-%dt%-%tm%.xxx

The above is just an example; you can format the renamed file label as you wish.thats AWESOME THANKS very muchly....

The registry bit was to derermine international settings and the delimiter of the time which became obsolete as I was hardcoding the delimiters...sigh

Thanks again for the snippet.

Cheers

Chris

8487.

Solve : Looking for Ports?

Answer»

Does anyone KNOW of a command or otherwise that would enable me to scan all ports looking for one that is "listening" on my proxy server? I need to find one to download throughThat doesn't sound like something you're supposed/allowed to do.I'm at a boarding hostel that uses the school (seperate enitity) system, the blocks on the server ie MySpace, Bebo, Hotmail, etc are in order to stop the Day School students from using the computers for anything other than work but seeing as though I'm at the hostel I need to be able to do things; keep in touch with parents, download assignments, exemplars etc. I already use browsing proxies to overcome the problem of no emails, I just need to find a way of setting my explorer's download port to be an available one, so I can use my COMPUTER just as any day school student would whilst at home.

So if anyone actually has an answer to my question it would be greatly appreciated.Right, so netstat -a lists the ports on my computer that do it, any idea how to adapt this to apply it to the proxy server?This sounds.......strange.........Why would the hotel use a school system?...........Until recently they've been one and the same in terms of management but they've drifted away now in everything except for the computer systems simply because of the cost of setting up a new server and LANYou mind telling us the name of this hotel.....?In order to do what you want you would need to do a portscan on the proxy. I'm not GOING to tell you how to do that for two reasons.
1) The admins on the system have clearly decided that you're not supposed to download, whether you're downloading from the school or a hostel is irrelevant.
2). Port scanning is frown upon (since it is rarely done for a legitimate reason) and by doing so you are properly violating the usage terms for that network.

So I would suggest you either talk with an IT person and explain your situation or go google it and risk being banned from the network or worse.So you want to be able to grab your OPEN ports (which are probably not controlled by the computer anyway) and then forward this input to a proxy server, which it would then use to pass packets through in order to download files?

Firstly, I don't know if that's what you want, if it is it's probably not possible. I don't know why you can't download through the HTTP port 80, which is through what you download webpages.

I don't know much about this but could the OP and experts clarify, thanks.

8488.

Solve : Multiline Batch Files?

Answer»

Hey guys, just a quick question, how do you do more than one line in a batch FILE (i.e. one command after another etc.) I just got no idea. ThanksWhat exactly is it your trying to do? Usually you can just do something like this...And it will work fine.

Example:
Code: [Select]echo hello
echo world
pause
exit

Just try putting one command after the other on a seperate line and see if that works if not post back.
Hope that HELPS .

8-)fffreakthats what i tried before, and it didn't work, which is why I posted here. for example pinging an IP, then putting tracert on the next line - it will only do the first of those commands.Rather than working in the DARK, PLEASE post your file. It may be a simple MATTER of where the next sequential instruction is coming from.

8-)Never mind, I seem to have got it working

8489.

Solve : How to control if a folder is open ??

Answer»

Hi !

It's a bit STRANGE.
But I want to control if a FOLDER is open with a BATCH file.

Thank you,

Osman

What do you mean control if a folder is open?

Do you mean lock the folder? or open / close the folder view?My aim is to control something like this :

IF MY FOLDER IS OPEN GOTO


My batch file opens a folder minimized.

START /MIN c:\my folder

But this line is in a LOOP.

If the USER don't close the folder, "START /MIN c:\my folder" tries to open it again.
There is no fault or error in this but the folder becomes maximized and then minimized suddenly during the loop. There would be no problem if the folder stays minimized. I HOPE I COULD explain.

Osman





8490.

Solve : Change date format?

Answer» HI,
I'am writeing my application date to txtpad using a batch program.the application date looks for example 01012006.is there a way to change 01012006 to 01-01-2006?
Regs,
JeriThis is one of the those questions where the OS plays an important role. Since you failed to mention yours I can only guess WHETHER this will work or not:

Code: [Select]SET dt=01012006
set editdt=%dt:~0,2%-%dt:~2,2%-%dt:~4,4%
echo %editdt%

Good LUCK.

Note: Not sure if your date is mmddyyyy or ddmmyyyy, but you can set dt to any date provided you use the same format.Thanks for your help.
Is there a way to change the date without assigning into a variable.for example notepad will only contain 01012006.is there a way to change 01012006 to 01-01-2006.Appricate your help.
Regs,
Jeri.I admit I'm confused. Notepad is an editor; can you not simply edit the date to whatever format you want? If you want to use a batch file, you might be able to write a search and replace and eliminate Notepad altogether. Is this date always 01012006 or are we talking about the current date?

8-)Check the options for Regional settings in control panel.
8491.

Solve : Need help in writing Batch file for moving files?

Answer»

Hi Experts,

I need ur help urgently.

There is a COGNOS Decision Stream JOB running which is taking data from MULTIPLE flat files (*.txt) under a directory and the TOOL itself writing the logs for those file in a different directoy. I want to create a batch file which will be called after the execution of the Cognos job and which will read the log file and if that is success it will move the source files to a DIFFERENTS specified directory.

Please help . Regards,

8492.

Solve : Batch file ping test how to export results ? ??

Answer»

Quote

@ECHO off

:begin
if exist "ips-to-ping.txt" echo File ALREADY exists, continue? & pause

:: Start making IPs to ping.
::
:: FORMAT:
:: >>"ips-to-ping.txt" echo assetname:IP address

>"ips-to-ping.txt" echo FAULTY:19.456.789.1
>>"ips-to-ping.txt" echo Tallagh:19.456.789.3
>>"ips-to-ping.txt" echo Faulty 2:19.456.789.2
>>"ips-to-ping.txt" echo Nass:19.456.789.4

::start pinging
:ping
for /F "usebackq tokens=1,2 delims=:" %%a in ("ips-to-ping.txt") do (
ping %%b >nul || echo %%a:%%b Timed Out @ %date%:%time%>> "pingfailed.log"
)

::done
:end
echo Done.
pause

That should WORK!
8493.

Solve : indentifying latest file from its name(contains timestamp) and renaming it.?

Answer»

Hi ,

I have a requirement where i have to select LATEST file from a directory and RENAME it.

The sample files will be Epaccts20070427080147.XML .I should pick recent file and rename it to input.xml.

I'm using Microsoft Windows XP [Version 5.1.2600]

If the file already exists it should not rename.

Any help will be appreciated.

Thanks,
So you want the most recent file based on what? Last modified, creation date?

If input.xml exists you don't want ANYTHING to happen but if it doesn't you want to grab the most recent xml document in the folder and rename it to input.xml?

Quote

@ECHO off


if exist "input.xml" (
echo Input.xml already exists, will exit
pause >nul
exit
)


:find
set name=
for /f "usebackq delims=" %%I in (`dir "*.xml" /b /o:-d`) do (
set name=%%~nxI
goto rename
)


:rename
if "%name%"=="" (
echo xml not found, exiting
pause >nul
exit
)

ren "%name%" "input.xml"


echo Done
pause >nul

Somthin like that?
8494.

Solve : Log in to a ftp server using a batch file?

Answer»
Can any one please help me to login to a FTP server using a batch file and also in a telnet server please reply to my email id [emailprotected] i cannot give my user name in the field can you please help me please give me a "Test" file with commands No, posting once would have been enough. Why don't you go spam somewhere else?depending in the ftp server you're trying to CONNECT to and if you are behind a firewall, you could run into a lot of issues but here is a simple way of doing it

create a batch file ftptest.bat and put this command in it
"ftp -s: test1.txt"

then create a text file called test1.txt and put these commands in it(note: single quotes imply values you need to insert)

"
open 'ipaddress of ftp server'
'username'
'password'
bin
mget 'name of file or files'
close

"

and when you're done stop spammingHae thanks a lot yea right ill try thisYou will need to open the Telnet to do this, otherwise the commands are useless. they are not commands without using TelnetI am trying to do a similar thing, except I am using telnet instead of ftp. I can't get it to work.

my batch file:
telnet < telnet-SMTP.txt

my telnet-SMTP.txt file:
open smtp.comcast.net 25
HELO comcast.net
MAIL FROM:<[emailprotected]>
RCPT TO:<[emailprotected]>
DATA
Subject:my test message
From: [emailprotected]
To: [emailprotected]

hello from user1.
QUITwindows telnet client is not really meant for scripting telnet. I guess I was naive in assuming that ftp and telnet were simply black-box programs that wrote output and read input from a terminal (or DOS window). If one could predict the exact sequence of input/output values, then the INTERACTION could be programmed in a script.

You are stating that ftp was programmed in a special way to allow this to HAPPEN, whereas telnet was not. That gives rise the question "How does one write an interactive program (say in C) whose input/outputs CAN be scripted?" If this can be done, what would a typical script look like (with I/O redirection operators)?

I am not being argumentative, I just want to understand this issue.

Thanksthat's why there are better languages out there that has the capability to script telnet and ftp.
eg Perl. check this for eg on FTP.
Check this for EXAMPLE on telnet.
8495.

Solve : batch script help?

Answer»

i am writing a batch script to compare the time in logs with the system time to check if the process is getting delayed

the last log ENTRY generated will be at the end of the FILE with time included
i need to go that line. is there anyway to do it?One way to get the last line would be to read the file counting the number of lines. Once you have a count, you can re-read the file, skipping n-1 lines and read the last line for processing:

Code: [Select]@echo off
set count=0
for /F %%i in (time.log) do (
call set /a count=%%count%%+1
)

call set /a count=%%count%%-1

for /f "skip=%count% tokens=* delims=" %%i in (time.log) do (
echo %%i
)

If need be, FIXUP the second for statement to parse out the info you need. I ARBITRARILY chose time.log as the file name; change as needed.

Good luck.

Need more info as to where the time info is on that line and in what format.a better way is to just set the variable
Code: [Select]for /f %%i in (time.log) do (
set lastline=%%i
)
echo %lastline%

8496.

Solve : Create directory if not already existing?

Answer»

Hi,

I have a newbiee question I guess. I would like to create a directory using a bat file. If the directory already exists I dont whant to do it. Something líke this.

rem Create directory
md ..\results

rem copy log file to results directory
cp file.txt ..\results\file.txt

The thing is that I run my bat file multiple TIME so I get a warning that says that the folder already exists. This only works the first time I run the script. I am running the bat file in XP.

Is there some way to do skip the creation if the folder already exists?What Operating System is this?Quote from: Carbon Dudeoxide on AUGUST 29, 2007, 04:00:48 AM

What Operating System is this?

Read the post, dude!

Quote
I am running the bat file in XP.

The answer is...

To be found on Google.




Quote from: contrex on August 29, 2007, 04:50:15 AM
Quote from: Carbon Dudeoxide on August 29, 2007, 04:00:48 AM
What Operating System is this?

Read the post, dude!

« Last Edit: Today at 06:08:43 PM by di98mase »

Must of edited it then. Last Edit: Today at 11:08:43 AM by di98mase
Reply #1 on: Today at 11:00:48 AM by Dudeoxide

Now I call that DOWNRIGHT sneaky. I'll edit my answer now I've SEEN that.

Quote from: di98mase on August 29, 2007, 03:53:28 AM
...
Is there some way to do skip the creation if the folder already exists?

Have a look here . Experiment a bit, and let us know if that HELPED.


8497.

Solve : copy html from website?

Answer»

could i make a code that would copy a websites code into a FOLDER? i was thinking something like:Code: [Select]copy http://lightstormlabs.com C:/seth/html/but that wouldnt work for MEYOU need a way to display the source code in a COMMANDLINE, I don't know, maybe a command line program on firefox or something. Once you can do that it's all plain sailing from there.you can use wget. or use IE AUTOMATION. (vbscript)

8498.

Solve : use batch to do some decryption.?

Answer»

My case is: .
FIRST of all, someone will PASS encrypted PASSWORD to run a batch.
for example the orginal password is "123", but that guys only pass "456" as password, and the batch can decrypt "456" to "123" and USE the password to process the rest program.

i know that the encryption and decrypttion should be a pair.

Does ANYONE can suggest me that what can i do?

Many Many thanksI'm not sure I get what you mean...

Is it possible you can post what you've written here?

8499.

Solve : Copy Files to PC From a Camera That Doesn't Show Up as A Removable Drive on PC?

Answer»

Is there anyway with MS-DOS to Copy Files to the PC From a Digital Camera That Doesn't Show Up as A Removable DRIVE on a PC..??
I think The Camera USES a FireWire Connection or something else besides USB, becuz when its plugged in, it doesn't ever seem to show up as Removable drive in "MY COMPUTER" But the "AutoPlay - Camera & Scanner Wizard Menu" Comes Up Where it asks me what I want to do with the files on the DEVICE though ..??
so is there any way at all to detect this device in MS-DOS & Copy its files back to my PC with a Batch or VBS script..??glad to see you're keeping away from the caps lock key. I think the answer is going to be "no". If it ain 't got a drive letter, DOS can't see it.



is there any other way to do it then via another program language or something besides just using the "AutoPlay - Camera & Scanner Wizard" ??I've got a really revolutionary suggestion, which may blow your mind, it's so unusual and crazy! Why don't you TELL us the brand and model number of the camera? There! I said it. Crazy, I know, but, hey, that's me folks!

8500.

Solve : Redirecting output to both file and screen?

Answer»

Is it possible in DOS to print the output both in a file and stdout ?
I am aware that in Linux, you may type
ls | tee ls.log
Is there anything similar in DOS command ?
Thanks for the help !
^^


a couple of ways:
1) search for the windows port of the tee command ..you know how to right?
2) do your own, eg save the below vbscript as tee.vbs
Code: [Select]Dim StdIn, StdOut,objFSO
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
outFile = objArgs(I)
Next
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(outFile,True)
Do While Not StdIn.AtEndOfStream
str = StdIn.ReadLine
StdOut.WriteLine "Line " & (StdIn.Line - 1) & ": " & str
objFile.Write str & vbCrLf
Loop
objFile.Close
Set objFSO=Nothing
Set objFile=Nothing
Set objArgs=Nothing
Set StdOut=Nothing
Set StdIn=Nothing
example usage:
Code: [Select]c:\> dir | cscript /nologo tee.vbs outputfile
3) i believe there's some ways to do it in DOS, i will just leave it to the DOS experts to guide you. In the meantime, how about this in batch :
Code: [Select]c:\> dir
c:\> dir > outputfile
Quote from: ghostdog74 on August 29, 2007, 03:17:37 AM

1) search for the windows port of the tee command ..you know how to right?

It is surprising that someone with a Unix type background does not know how to type "tee port NT" into Google. If they did they would have found (among others) Rob van der Woude's tee.bat, or the excellent blip project's package which includes tee.cmd.

Mind you, we are assuming the OP actually meant "NT/W2k/XP/Vista command line" when they typed "DOS"... not always a safe assumption... maybe they will clarify?

For "real" MS-DOS there is FORK.COM, again findable with Google (it's in FORK33.ZIP)Quote
Mind you, we are assuming the OP actually meant "NT/W2k/XP/Vista command line" when they typed "DOS"... not always a safe assumption... maybe they will clarify?
hmm...how about another sub forum called Disk Operating System (DOS).? is it warranted? Well, to me there is MS-DOS and there is NT command prompt. They are different things, and I don't like to see them mixed up. Because the NT command language has many of the same commands as MS-DOS, with (sometimes, but not always) the same syntax, many people confuse them, or assume that the command window you get in 2K/XP/Vista is actually called "DOS".

I guess the problem is most acute among the "GUI generation" who are aged under about 25, who have grown up with Windows of one form or another.

I personally FEEL that this forum has made a rod for its own back by not SUFFICIENTLY distinguishing between them.

I can imagine that ANSWERING questions that ask about "DOS" with a purely MS-DOS based answer would pretty soon ram the point home...