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.

7801.

Solve : Syntax on bacth when sendevent?

Answer»

I am in current directory have 2 files. One is a "abc.txt" file and one is "dt2.bat"

type abc.txt = TEST2

And type the command line below and work fine.
for /f %i in (abc.txt) do sendevent -E SET_GLOBAL -G "DTRAN=%i"

autorep -G DTRAN

Global Name Value
Last Changed
DTRAN TEST2 01/11/2013 10:09:09


Now I create a batch file called: dt2.bat just like simple command on top. But run the dt2.bat not work. Keep SAY "The syntax of the command is incorrect." Please help what's wrong with this? Thanks

C:\PROGRAM Files (x86)\CA\Workload Automation AE\batch>dt2.bat

@echo off
for /f %i in (abc.txt) do sendevent -E SET_GLOBAL -G "DTRAN=%i"FOR %i in (bla bla bla) do echo %i (command line)
FOR %%i in (bla bla bla) do echo %%i (batch script)



I bet if you read the help file for the FOR command you will be enlightened. It will tell you exactly what Slamon Trout just showed you. READING is fun!Thanks SALMON Strout & Squashman. I am new with DOS batch. 😄Quote from: dtran on January 11, 2013, 10:32:35 PM

I am new with DOS batch.

All the more reason to read the documentation.
7802.

Solve : Is it possible to delay a batch file invisibly??

Answer»

I know how to delay a batch file with "pause", "timeout" or "PING", but they all show words on the screen when delaying. I want to delay a batch file without any words being showed on the screen. Is this possible?
ThanksSLEEP.EXE is what I use when i dont want text, but it will hold the window open and show nothing. But there is no way to hide the window, and I believe that this was intended in its design so that it wouldnt be used early on as a malicious tool as a hidden TSR. If you want something to run hidden and then trigger you can use Windows Scheduled Task Manager or create a macro and compile it as an exe with instructions to operate and not have a window open while its processing whatever. I use Jitbit for making such macros for custom automated mouse/keyboard functionality with redundant processes that otherwise would require a human to manually perform a tedious process.

http://www.microsoft.com/en-us/download/details.aspx?id=17657This has been talked about a lot. The general answer is that either you are not a professional or you a malicious thug looking for help in a CRIME.

Windows professionals know how to deploy system updates without causing alarm to the users. One way is to just tell them an update is now in progress.


Quote from: Whitebeard1 on October 26, 2013, 10:21:04 PM

I know how to delay a batch file with "pause", "timeout" or "ping", but they all show words on the screen when delaying.

I don't THINK he's asking about hidden batch files.

You can redirect the output of all these commands to NUL which just swallows the console output so that nothing shows on screen. E.g. PAUSE > NUL

This can be handy with e.g. PAUSE because it means you can replace the standard message with one of your own.

Example batch script below

@echo off
echo 1. Running PING hidden
echo Approximately 5 second delay
echo Starting PING. The time is %time%
PING 127.0.0.1 -n 6 > nul
echo Finished PING. The time is %time%
echo.
echo 2. Running PAUSE hidden
echo Waiting for you to press a key...
echo Starting PAUSE. The time is %time%
pause > NUL
echo Finished PAUSE. The time is %time%
echo.
Echo 3. Running TIMEOUT hidden
echo Timeout 10 seconds or when key is pressed...
echo Please Wait or press a key...
echo Starting TIMEOUT. The time is %time%
Timeout /T 10 > NUL
echo Finished TIMEOUT. The time is %time%
echo.
Echo 4. Running TIMEOUT hidden again
echo Timeout 10 seconds (keypress locked out)
echo Please Wait...
echo Starting TIMEOUT. The time is %time%
Timeout /T 10 /NOBREAK > NUL
echo Finished TIMEOUT. The time is %time%
echo.

Console output...

1. Running PING hidden
Approximately 5 second delay
Starting PING. The time is 7:42:07.44
Finished PING. The time is 7:42:12.48

2. Running PAUSE hidden
Waiting for you to press a key...
Starting PAUSE. The time is 7:42:12.49
Finished PAUSE. The time is 7:42:22.22

3. Running TIMEOUT hidden
Timeout 10 seconds or when key is pressed...
Please Wait or press a key...
Starting TIMEOUT. The time is 7:42:22.23
Finished TIMEOUT. The time is 7:42:32.17

4. Running TIMEOUT hidden again
Timeout 10 seconds (keypress locked out)
Please Wait...
Starting TIMEOUT. The time is 7:42:32.18
Finished TIMEOUT. The time is 7:42:42.11






timeout /t X >nul 2>&1

will wait for X seconds, allowing the user to break upon pressing any key. You can add /NOBREAK to disable this feature and only wait the specified NUMBER of seconds.

The >nul will suppress any regular text and the 2>&1 will suppress any error messages. >nul cannot be removed without changing 2>&1 to 2>nul.

Timeout is newly available on windows 7, so your scripts will not be backwards compatible.Quote from: Whitebeard1 on October 26, 2013, 10:21:04 PM
I know how to delay a batch file with "pause", "timeout" or "ping", but they all show words on the screen when delaying. I want to delay a batch file without any words being showed on the screen. Is this possible?
Thanks

i guess your saying

Code: [Select]@echo off
ping localhost -n 6 > nul

console output will be blank for 5 secs.
-n 6 = 5 secs.
Thanks for the reply guys. And Geek-9pm, I'm not trying to do a crime or anything, I was talking about pausing a batch file without printing out an annoying "press any key to continue"The replies were helpful. I like the >NUL command, very helpful in my batch file.Quote from: Whitebeard1 on October 27, 2013, 11:40:19 PM
Thanks for the reply guys. And Geek-9pm, I'm not trying to do a crime or anything, I was talking about pausing a batch file without printing out an annoying "press any key to continue"
Didn't mean to say you were. In the past, some have come here asked similar questions and then when the get what the want STRANGELY diaper and never return.
BTW; There are versions of SLEEP.EXE that give no output. But the >NUL is just as good and gets the job done with tools at hand.
7803.

Solve : Batch file help: Creating batch files with notepad?

Answer»

I need help creating this batch file in notepad, and I am not getting the correct results. I hope someone can help me and point me in the right direction.

Create the following batch file. These batch files should do the actions indicated. None of these files should echo any of their commands to the console. Include appropriate comment lines that state what the file will do.

1. Create a batch file that changes the command prompt based on the user’s parameter:
a) The batch file will run with a single parameter that represents one of three prompt choices.
b) Compare the parameter to each of its possible values. If there is a match: Go to a different label where a new prompt will be set. Allow for one instance where the prompt is restored to its original setting. Include at least one special code in each of them. Go to a label at the end of the file and quit.
Is this homework?

If so most of the ways to achieve this will be in the book that your studying. I feel that if we gave you a pointer on how to do it, we would be giving away the answers.

Can you share code example of what you have now and we can point out corrections maybe? I dont like to do peoples homework for them, but I dont mind pointing out corrections to be made.... I guess I am saying that I am willing to help, but not do all the work for you.

*Also a common mistake I have seen with using notepad when creating batch files is that the batch file is saved as a text file because notepad saves to .txt by default, so you will want your batch files to have the .bat file extension. Just wanted to mention in case you didnt know this. Other mistakes are in naming the batch file a similar name to that of an already existing program or command, so its best to name it something like test1.bat or homework1.bat to avoid naming conflicts.Hee...good call.This is part of a lab assignment yes. We don't have a text book, all the professor does is he gives us a couple of notes and then gives this lab. When this is your first time every using DOS you have no idea what the *censored* you are doing, its like a totally new language I'm expected to know how to speak. I have tried asking him for help but all he does is tells me the ANSWER and I never end up understanding how to do it. I have tried to figure it out. For part a) I'm just not quite sure what its asking. I guess what would be helpful is if I could come to UNDERSTAND batch files. I don't expect you to tell me the answers but to give me more of an understanding. I know how to save the file to make it a batch file. I'm just confused where it says in the question about the parameter representing one of three prompt choices. I learned that prompt -is what gets displayed in the terminal when you want to enter something; it's part of some initial configurations. h:\>prompt Hey! Result: Hey! I just don't understand what the question means. I'm really sorry if I'm not making sense its just this stuff is so over my head its hard to wrap my mind around it.
So, for a) would I go:

@echo off
rem Create a batch file that will use a single parameter to represent one of three prompt choices and compare the parameter to its values.
:loop -no idea what this is for he didn't really explain it.
echo Hello %1
not sure what to do for the other three prompt choices that need to be here. would it be using a label like with a COLON eg. :prompt1? oh and would i need to use goto?

I'm pretty sure I'm way off, so if you can't explain it without giving the answers thats okay I'll try to figure it out on my own. Thanks though.


Here's a framework for you to run and examine. Hopefully you can follow it and change it to suit you.

It starts a new session of cmd so that the prompt changes can be seen.

Code: [Select]@echo off
if "%~1"=="" (
echo enter an argument at the command line
pause
goto :EOF
)

if /i "%~1"=="A" goto :labelA
if /i "%~1"=="B" goto :labelB
if /i "%~1"=="C" goto :labelC
goto :EOF

:labelA
prompt letter A - $P$G
cmd /k echo Type EXIT to quit
goto :EOF

:labelB
prompt letter B - $P$G
cmd /k echo Type EXIT to quit
goto :EOF

:labelC
prompt $P$G
cmd /k echo Type EXIT to quit
goto :EOFQuote from: foxidrive on October 23, 2013, 03:04:10 AM

Here's a framework for you to run and examine. Hopefully you can follow it and change it to suit you.

It starts a new session of cmd so that the prompt changes can be seen.


That's a pretty simple way of doing what you want... but remember that if this is for an intro class, using foxi's exact script will get you busted. That doesn't look like a beginner's script.

If you can understand that, then you'll know what the teacher/prof is expecting of you and you'll be able to WRITE your own (more basic) script.

Also, you said:
Quote from: alice8 on October 22, 2013, 04:50:43 PM
None of these files should echo any of their commands to the console.

was one of the requirements. If that's the case, you'll just need to modify a few things that foxi put... I'll let you figure out what things. Run foxi's script if you need to to see what actually echoes to the console.

Last thing - if you don't have to use notepad.exe I'd personally recommend Notepad++. It's FREE and has syntax highlighting as well as language presets. Makes things a lot easier for me personally. Thanks foxidrive, this is very helpful! And kyle_engineer I will make sure its a more basic script, thanks! If you get into programming .bat files heavily, you might want to use this program:

http://www.contexteditor.org/

It has the syntax highlighting & language presets, plus you can also program a button to testrun your batch file.
I use it to 'save and run' in one click.

After every major change I make in my .bat file, I click the button to run it. Saves a lot of time.
7804.

Solve : with code i need to use!?

Answer»

Hello,
i don't kon't how to read only the first/second/thirt/fourth/etc
i know a code to read only the first line:
Quote

@echo off
for /f "delims=" %%k in ( ' type "something.txt" ' ) do (
set A=%%k
goto 2
)

:2
echo %A%
pause

and something.txt list look like this:
Quote
1
2
3
4
5
6
7
8
9

if you know a code to do this,
pleas answere

-lukeIf you want to use GnuSED than this will work for any line - this example uses line 4

Code: [Select]@echo off
for /f "delims=" %%a in (' SED 4!d "file.txt" ') do set "var=%%a"
echo "%var%"

This will do the same but it has issues with blank lines, and lines starting with ; by default.

Code: [Select]@echo off
for /f "skip=3 delims=" %%a in (' type "file.txt" ') do (
set "var=%%a"
goto :2
)
:2
echo %var%

I tend to use a counter, and an if statement. I guess it's just personal prefferance after awhile.

Code: [Select]@echo off
set a=0
setlocal EnableDelayedExpansion
for /f "delims=" %%A in (file.txt) do (
set /a a+=1
if "!a!"=="4" echo %%A
)

You don't need to have 'type' in your for loop. (FILENAME.txt) works the same way.

EDIT: Example also uses line 4.Quote from: Lemonilla on January 12, 2013, 07:21:17 AM
I tend to use a counter, and an if statement. I guess it's just personal prefferance after awhile.

You don't need to have 'type' in your for loop. (FileName.txt) works the same way.

You do need to use 'type' if there are long filename elements in the filename. Or usebackq

And yes, it is personal PREFERENCE in a lot of the things you can script. You can modify the code to get the Nth line by skipping N-1 lines if you use SKIP in the options block for example to get the 4th line you skip the first 3

@echo off
for /f "skip=3 delims=" %%k in ( ' type "something.txt" ' ) do set MyLine=%%k & goto next
:next
echo %MyLine%
pause

if you want to avoid the FOR behaviour mentioned by foxidrive you can use the old trick of FINDSTR with:

/N - which prefixes each line with a number and a colon
/R "^" - use the regular expression "^" which means "all lines"

and then by using "tokens=1* delims=:" separate the prefix and use an IF test to get the line you want

set num=4
for /f "tokens=1* delims=:" %%A in ('findstr /N /R "^" "something.txt"') do if "%%A"=="%num%" set Myline=%%B
echo %MyLine%

Quote from: Salmon Trout on January 12, 2013, 08:35:32 AM
if you want to avoid the FOR behaviour mentioned by foxidrive you can use the old trick of FINDSTR with:

That technique then has issues with leading : characters.

Sed is a tool that Microsoft should have included as it's built for editing text.
I guess Powershell has ways to do it too - and there's always VBS to fall back on.

There's more than one way to skin a cat!

Quote from: foxidrive on January 12, 2013, 08:46:30 AM
There's more than one way to skin a cat!

I guess it comes down to WHATEVER tool you feel happiest with. I tend to use VBScript these days - for the task mentioned above I would just read the file into an ARRAY and get the desired line.Thank you all for your help,
i use this code to set languages
so i can make a list of translated words/phrases

if i ready with this file i will post the finaly version if i am proud about it

-luke
7805.

Solve : Align text in batch file?

Answer»

Hi,

I am writting a batch file to print the tests results. Like

if %errorlevel%==0 (
echo Test %test% Passed >>output.txt
) else (
echo Test %test% Failed >>output.txt
)

Since the length of %test% will change for different tests, Is there any way to let "Passed" or "Failed" start at the same column for all of the tests in output.txt.
Like

Test test1 flags Passed
Test test2 Passed
...

THANKS for any help!Doubtful you can. You would need to insert a tab character (ascii 10) in each line. In an unformatted text file the tab character would be meaningless. Any of the scripting languages could do this.

Back to the drawing board. Not sure if this helps found this on the Hak5 forum MAYBE it helps

PART 1

you need to amend it for your batch file

cscript //nologo .\DUH.vbs >> ..\..\Documents\logfiles\%computername%.log 2>&1
TYPE ..\..\Documents\logfiles\%computername%.log | find ":::" | find /V "NO PASSWORD" | find /V "ASPNET" | find /V "HelpAssistant" >> ..\..\Documents\logfiles\%computername%.log

Part 2

.vbs file

on error resume next
set sh = createobject("Shell.Application")
const ssfHISTORY = 34
set history = sh.NameSpace(ssfHISTORY)
for each item in history.items
wscript.echo history.GetDetailsOf(item,-1)
if item.isFolder then
set itFol = item.GetFolder
for each item2 in itFol.items
wscript.echo vbtab & itFol.GetDetailsOf(item2,-1)
Next
wscript.echo String (80,"-")
end if
next


Keep the vbs file in the same DIRECTORY as the batch You dug up a 7 year old THREAD that I don't see how what you posted solved the OP's original question.Quote from: Squashman on January 12, 2013, 09:38:46 PM

You dug up a 7 year old thread that I don't see how what you posted solved the OP's original question.

The question as stated was essentially unanswered, so see here, Google indexer!

It is a simple matter to justify text in a batch script by padding it on the left or right with a suitable number of a pad character e.g. space, dot, whatever and then take a slice of desired length (as long as, or longer than the max length to be processed) starting at the left or right. These are just simple examples and of course refinements are possible.

REM left justify text within a column 16 characters wide
set string=some text
REM add an excess of pad characters (i.e. more than 16)
REM Note: use quotes if pad characters are spaces
set "string=%string% "
REM Show the justified column as a slice starting at position 0, of length 16
echo Prefix %string:~0,16% Suffix

REM right justify text within a column 16 characters wide
set string=some text
REM add an excess of pad characters on the left
set string= %string%
REM Show the justified column as a slice ending at the string end, of length 16
echo Prefix %string:~-16% Suffix


7806.

Solve : Need help with batch file calling text contents into batch commands?

Answer»

Please help as i would like to make the following

test1.bat

telnet %IPAddress1%
telnet %IPAddress2%

text.txt
IPAddress1 = 192.168.100.232
IPAddress2 = 192.168.100.233

how do i write so as my bat file would take the IPAddress1 from the .txt or .ini file into my bat commands?


Windows XP SP31. test.txt (NO SPACES)

IPAddress1=192.168.100.232
IPAddress2=192.168.100.233

2. test.bat

@echo off
for /f "delims=" %%A in (test.txt) do set %%A
echo IPaddress1 is %IPaddress1%
echo IPaddress2 is %IPaddress2%

3. Console output

C:\>test.bat
IPaddress1 is 192.168.100.232
IPaddress2 is 192.168.100.233


Quote from: Salmon Trout on October 25, 2013, 01:14:08 AM

1. test.txt (NO SPACES)

IPAddress1=192.168.100.232
IPAddress2=192.168.100.233

2. test.bat

@echo off
for /f "delims=" %%A in (test.txt) do set %%A
echo IPaddress1 is %IPaddress1%
echo IPaddress2 is %IPaddress2%

3. Console output

C:\>test.bat
IPaddress1 is 192.168.100.232
IPaddress2 is 192.168.100.233




With great thanks. Added knowledge
Actually what i needed is shown below.

Sorry
for not putting it clearly

1. ipadd.txt

ip1=192.168.100.232
ip2=192.168.100.233

2. ping.bat

@echo off
cls
ping %ip1%
pause

3. Console output should be

Pinging 192.168.100.232 with 32 bytes of data:

Reply from 192.168.100.232: bytes=32 time<1ms TTL=255
Reply from 192.168.100.232: bytes=32 time<1ms TTL=255
Reply from 192.168.100.232: bytes=32 time<1ms TTL=255
Reply from 192.168.100.232: bytes=32 time<1ms TTL=255

Ping statistics for 192.168.100.232:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms


Tried to research but still couldn't find the correct method
Well, all you need to do now is edit your batch file.
The most obvious problem is that you have called your batch file the name of a system command, and in this case ping.bat will call itself again and again.

Call this IPPing.bat or something simpler like IP.bat

Code: [Select]@echo off
for /f "tokens=2 delims==" %%A in (ipadd.txt) do (
cls
ping %%A
pause
)Quote from: foxidrive on October 25, 2013, 05:20:44 AM
The most obvious problem is that you have called your batch file the name of a system command, and in this case ping.bat will call itself again and again.

Call this IPPing.bat or something simpler like IP.bat

Code: [Select]@echo off
for /f "tokens=2 delims==" %%A in (ipadd.txt) do (
cls
ping %%A
pause
)

it works for the first line of the ipadd.txt
how do i ping to the 2nd line of the ipadd.txt

ip1=192.168.100.232
ip2=192.168.100.233

sorry for asking noobie QUESTIONS It pings the first IP address,
Then you press any key and it will ping the second IP address
and then when you press any key it will finally quit.Below are my scripts currently

For Main Bat file named: ServerTest.bat
Code: [Select]@echo off
cls
:start
echo ***************************************************
echo ********* Please Select The Server You WANT Ping ********
echo ***************************************************
echo.
echo 1. To Ping Server 1
echo 2. To Ping Server 2
echo.
echo 0. To Quit
echo.
set /p choice="Enter your choice: "
if "%choice%"=="1" goto Server1
if "%choice%"=="2" goto Server2
if "%choice%"=="0" exit
echo Invalid choice: %choice%
echo.
pause
cls
goto start

:Server1
cls
C:\"SScript"\"Server1"
goto :start
echo.

:Server2
cls
C:\"SScript"\"Server2"
goto :start
echo.

exit

For another bat file that was called from main as shown below;
Server1.bat

Code: [Select]@echo off
echo.
[color=RED]for /f "tokens=2 delims==" %%A in (tsip.txt) do (
cls
ping %%A[/color]
goto :start
)
:start
echo.
echo 1. If Reply. Continue Script
echo.
echo 2. Go Back to Main Menu
echo.
echo 0. To Quit
echo.

set /p choice="Enter your choice: "
if "%choice%"=="1" goto Script
if "%choice%"=="2" goto MainMenu
if "%choice%"=="0" exit
echo Invalid choice: %choice%
echo.
pause
cls
goto start

:Script
Start telnet.exe [color=red]192.168.100.232[/color]
cscript sendkeys.vbs
echo.
call "ServerTest.bat"

:MainMenu
cls
start C:\"SScript"\"ServerTest.bat"

:exit
exit

I want to avoid using many server1.bat, server2.bat, etc...

So thats why i wanted to know instead of creating so many server bat files with different IP address.
Is there a way of calling those highlighted in red from text file based on the specific lines?

IPadd.txt
Code: [Select]IP1=192.168.100.232
IP2=192.168.100.233
IP3=192.168.100.234


Appreciate with all the information given =)for /f "delims=" %%A in (IPadd.txt) do call server1.bat "%%A"
then change all INSTANCES of the ip address stored in IPadd.txt to %~1. Just make sure at the end you have an exit /b
7807.

Solve : how to "copy" using a .bat to parent directory??

Answer»

hi,
I want to USE a simple batch file to copy a given file (in the same batch file's directory) to the parent directory (of that batch file), how?
I use "copy filename.ext CD.." but doesn't WORK!
thanksDon't put the 'cd' in the copy COMMAND; it's not needed. ".." by itself is the parent directory (of the current directory, which will be the same as the batch file's location if you double-click the file in EXPLORER)copy filename.ext ..\



7808.

Solve : Task Scheduler?

Answer»

Is it possbile to have a batch or vbscript to change the passwords for all your WINDOW task shedules in Windows xp? It really PAIN to go into each shedule and change the password everytime we have to change our password for windows.
OK i figured out how to do it if ANYONE need it

Code: [Select]

SCHTASKS /Change /s \\computername /RU username /RP Newpass /TN my_task_name

7809.

Solve : Can't get batch file to start program in partition?

Answer»

I've researched this a fair bit. Can't get an exe on a different partition (M:\program files\grisoft\avg free\avgw.exe) to open when I'm logged into my D: drive partition. Tried the quotes (start "M:\program files\grisoft\avg free\avgw.exe") & short filename (start M:\progra~1\grisoft\avgfre~1\avgw.exe)(ALSO tried it in quotes). Windows XP, Fat32 on the D partition, M partiton is formatted Fat32, no o/s.What error message did you receive? "Bad command or filename" usually means a typo or the file does not exist. Some programs need components to run. If you run from an icon, the "Start in" parameter usually takes care of where to look. In a batch file or at the command line you may have to change directory to the .exe location before you can run.

Hope this helps. Thanx for the quick response, Sidewinder. There's no error message per se. The only window showing is a dos-like window named "M:\program files\grisoft\avg free\avgw.exe" & at the prompt it shows the location of the batchfile D:\....desktop. Yes, when this particular exe (avgw.exe)is run from an icon (shortcut on my desktop), the "start in" is where the program folder is located (M:\). After some searching, I followed a recommendation to d/l Cmdhere MS powertoys, which gave me the ability to open a dos window in the M:\ partiton. Typing M:\program files\grisoft\avg free\avgw.exe did open the exe I wanted. However, when in the D:\ partition, I can't get the dos prompt to cd to M:\, or is "cd" the wrong command for that? Or do you know what the syntax is for cd M:\ in a batchfile? TYOn XP you can change drive and directory with one command:

cd /d m:\

pushd m:\ also works.

Hey S/W! TY for the info. We're getting much closer! Yes, I can switch the partitions using the syntax you suggested, however, I can't seem to start the exe from the commandline nor incorporate the syntax into a batchfile... Here's an example of what I've been using in a batch;

cd /d m:\
start M:\PROGRA~1\Grisoft\AVGFre~1\avgw.exe

When I use the above, I get an error saying "windows cannot find" the file. Yet when I use the home drive in that commandline, it works fine (minus the "cd /d m:\", of course)



At the prompt I've used this (among other variations);

M:\> start "m:\program files\grisoft\avg free\avgw.exe"

When I do this, it just brings up another dos window. :-/

I just tried the short filename convention at the prompt & got the same "windows cannot find" file error.
You could try this:

Code: [Select]
cd /d M:\PROGRA~1\Grisoft\AVGFre~1
start avgw


If that doesn't work, try WITHOUT the START.There may be a message in the Window that flies by. Check to make sure that AVGW is in fact the correct executable.

Curious: is AVG installed to the OS on the C drive? There could be references to files not logically connected to the XP system....just a thought

Good luck. Hi Sidewinder. You are da man! Yupper, the last syntax got it! As far as your question as to where AVG is installed, my rig has 2 hd's & 13 partitions (various windows o/s's, some blank or formatted partitions & soon to be Mepis Linux). AVG is on the partition that has most of my progs, M:\. I typically run my desktop off of the D or I xp partitons. C is win98.
I'll tell ya what I'm up to. I want to have AVG (or any other program) run, delete any viruses (or whatever), close, then have a report generated on all the activity. I've dabbled with Visual Basic 6 & various batchfile programs (Batchrun, Autoit, etc) & so far, batchfiles look like what I'll be using to accomplish this. Yes, I know I could just make a shortcut to AVG's selfgenerated report to see what it's done, but I'm just testing out various methods on AVG. Thank you for all your input. Whaddaya think? MikeWith 2 HDDs with 13 partitions and various OS versions, you hardly need my thoughts. I agree with you that batch files are the way to go since they are the lowest common denominator. With Scripts you may find that some versions of Windows do not support all the COM objects needed.

I never FOUND third party tools (Batchrun and Autoit) to be much help, but some people swear by them. Personally I find them redundant since Windows has most of the tools you need...just hard to find sometimes.

Maybe you should try something like VMWare ($$$). You could have all the OSes running concurrently and hotkey between them. Should make for some really spectacular fireworks.

One question: How do you maintain all this?

Good luck. Heh... It's not as impressive as it might SOUND. Although, with this many partitions, there's a piece of free software called 'Restart' by Gabriele Ponti (http://www.gabrieleponti.com/software) that is great for restarting into various partitions with 1 click (in combination with batchfiles) with various parameters for forced shutdown, etc. Gabriele is very responsive & community oriented, just a great guy.

You mentioned that windows has most of the tools you need to automate tasks, but that they can be hard to find. I guess mine is a case in point. How did you learn so much about batchfiles?

Ya, using VMWare to hotkey between os's would come in handy at times for sure. I service people's computers & to have various configurations so readily available would definitely make my job EASIER (maybe even make some fireworks! ).

When you say 'maintain all this', do you mean updates,etc? There are only 2 partitions that I typically boot to, the others are more for troubleshooting or testing, so they aren't really maintained. My E partiton I used for a year or so, then when it got too unwieldy, I migrated to another. That sort of thing.

Mike

7810.

Solve : command to list filenames in dir into a textfile?

Answer»

a COMMAND to list every FILENAME in dir into a textfile.... i believe this is possible i think someone i WORKED with in the past did this...

any help would be greatly appreciated...

Vin Figured it out...

incase someone else wants to KNOW it's

DIR &GT; myfile.txt



Vin
It's always heartwarming when someone can find their own solution to a problem.

Good luck Vin.

7811.

Solve : Batch file to make new folder fails to work?

Answer»

Hello,

I have attached a batch file that i use to make a new folder in date format in a certain directory.
when i run the file as it is it does'nt work.

if i CHANGE the file to run on c directory i have no problems but when i change it to example on attached
it fails.
The u drive in example is on a shared network drive.

This is puzzling since it works on c drive.

Any advice would be great.
Thanks

[recovering disk space, attachment deleted by admin]This is your code:

Code: [Select]@echo off
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date="%date:~0,2%-%date:~3,2%-%date:~6,6%"
md 'filesvr-tms' u:\dropsets\before\testerpost\%date%
The last line should be something like this:

Code: [Select]md "u:\dropsets\before\testerpost\%date%"

The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.

Code: [Select]@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
echo datestamp: "%datestamp%"
echo timestamp: "%timestamp%"
echo fullstamp: "%fullstamp%"
pause
md 'filesvr-tms' u:\dropsets\before\testerpost\%date%
^^^^^^^^^^^^^
|
what is this supposed to do?


C:\>md /?
Creates a directory.

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

Hello,

On a shared drive "U" ,everyday i have to scroll to that drive and create a new folder with the current DAYS date.

so i figured creating a batch file that could sit on the desktop and when clicked would do such a task.
When i run the attached file at home it writes it with no problems.
But in work it does'nt seem to work so i thought maybe i need to include the filesvr-tms for the file server running it
but still no joy.

I can't figure why it works at home but not in work.Quote from: ftfk on October 24, 2013, 02:03:32 PM

I can't figure why it works at home but not in work.

Possibly you do not have sufficient permissions. If this is a work computer you need to contact the system administrator. Also, does the %date% variable CONTAIN characters that would be illegal in a file or folder name?
usually permission restrictions on the network gives a pop up message.
But running this gives nothing.

The date variable as from attached example contains nothing illegal.Quote from: ftfk on October 24, 2013, 02:14:10 PM
usually permission restrictions on the network gives a pop up message.
But running this gives nothing.

The date variable as from attached example contains nothing illegal.

You won't necessarily get a POPUP with a batch script. Try adding this one line to the end of the batch script:

PAUSE

Then the command window will stay open until you press a key and you can see if the system is trying to tell you anything.





7812.

Solve : Closing by Batch FIle?

Answer»

[size=16]Is there any command for a batch filethrough which i can close a program or WINDOW?[/size]

A couple of possibilities. TaskKill is installed with some versions of Windows. If you want to close the command window where the batch file is running, use the exit command. Otherwise you need to write a Windows Script.

Code: [Select]
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")

For Each objProcess in colProcessList
objProcess.Terminate()
Next


Save the script with a VBS extension and change notepad.exe accordingly.

Hope this helps. Thanks
But after saving the above script as script.vbs

when I double Clicked it I got the following message:

script: C:\Windows\Desktop\script.vbs
Line Number: 2 Column: 0
Category: Microsoft VBScript Runtime Error
Description: File name or class name not found during Automation operation: 'GetObject'[/color]

Note: I have Win98 SE

[/font]Very pretty Shouvik but totally unnecessaryIt may also help people ,if they new what animal they are dealing with......like win95 etc.........pascal/borland etc.This seems to be the most POPULAR QUESTION this week. If the script didn't work (probably an old version of the script INTERPRETER or non-existant COM OBJECTS) check to see if you have a version of tskill.
If you do check out your options with tskill /?. If not you may just have to use the task manager.

7813.

Solve : how to lanch game from foppy?

Answer»

how do i lanch a game from a FOPPY in DOS. i was told you can do it. the NAME of the EXE is ROF.exe PLZ tell me how to do itChampagne launches ships! MAY be the run command.

7814.

Solve : asking for help with text management in batch files?

Answer»

Hi,

I'm WORKING in Win XP SP3.

I have a text file with bunch of topics and various number values after them, like:
apples=4
grapes=5
bananas=3

I'd like to have a batch command that will open the file, find the line with the bananas and add a line before/above it, like:
apples=4
grapes=5
pears=7
bananas=3

I've used the 'set' and 'if' well ENOUGH, but my results come out missing the line break, like:
pears=7 bananas=3

I can't seem to get the added line break. Can someone help?
Here is the code, I've tried


@echo off
SETLOCAL=ENABLEDELAYEDEXPANSION
set lf=^
rename fruitcount.txt fruitcount.tmp
for /f %%a in (fruitcount.tmp) do (
set foo=%%a
if !foo!==bananas=3 set foo=pears=7!lf!bananas=3
echo !foo! >> fruitcount.txt)
del fruitcount.tmp


ThanksWhat does !foo! MEAN?!foo! is set to %%a above.

but %lf% is broken, and the actual task will DETERMINE the best way to go about it. It seems very unlikely that that is all you need to do.

This code will do as you ask
(get the batch file CALLED `findrepl.bat` from - https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat and place it in the same folder as the batch file.)


Code: [Select]@echo off
move fruitcount.txt fruitcount.tmp >nul
type fruitcount.tmp |findrepl /o:1:2 >fruitcount.txt
>>fruitcount.txt echo pears=7
type fruitcount.tmp |findrepl /o:3:3 >>fruitcount.txt
pause

7815.

Solve : tranfer ms dos to diskett?

Answer»

my computer breakdown, and i can get to my files, i haVe to TRANSFER my information from MS DOS to diskett, cause i DONT want to lose all my information. how CA i so this??

PLEASE HELP ME!!!!!!!!!!!!!!!!!!!!!!!What has broken?? Are your files on your hard-disk?? Can you access your hard-disk??

What Operating System are/were you USING. Is your hard-disk formatted FAT-32 or NTFS??

More information please.

7816.

Solve : Deleting Desktop Icons using batch file?

Answer»

Hi!
I WANT to be able to delete ICONS on my desktop using the batch file.

I tried DEL Desktop\Hello where Hello represents the name of the icon. It did not work

Can somebody tell me what is the command that I can PUT in my batch file

Thanks

I'm PRETTY sure that some of the desktop icons are KEPT in:

c:\documents and settings\%username%\desktop

Note: icons have a .ICO extension.

Happy computing...

7817.

Solve : Giving ALT-F4 command in batch file?

Answer»

If I want to hit on ALT+F4 using a batch file, how would I go about by writing it in the batch file.

Is it even possible to do it in batch file

Please reply asap

ThanksWhat are you trying to do? Alt-F4 is used to kill a windows process. You would either have to write a script and use the sendkey method, or iterate the running processes and kill it that way. The problem here is that you need a way to direct the alt-f4 key code to the proper application.

Alt-F4 could be a BIT of a catch-22. If you use that key combo in an editor, the editor will shutdown! Not too cool.

Some but not all versions of Windows have the taskkill command, which could be hepful. What version are you using?

In a batch file, use the exit COMMMAND to shutdown the command window.

Happy computing... I am using Windows XP.

This is what I am trying to do.

I have created a batch file which installs a number of applications onto an end user's computer. The problem is that the first application installed by the user gets launched as SOON as the installation is finished. I dont want it to get launched. I can't change the way the installation is DONE because the first application was not packaged by me. I need it for my application to run.

The only way to kill the application and proceed with the rest of the installation process is pressing ALT-F4. I am trying to include this in the batch file but I don't know how to give the command so that ALT-F4 is pressed (functionality wise not literally) as soon as the installation is finished.

I hope I am clear in what I want to do.

If nothing works I might just include a pop-up window application that warns the user.
Thanks for all the help
If you are using XP Pro, I think you can use taskkill which will make it simple. If not this little script will do the job:

Code: [Select]
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")

For Each objProcess in colProcessList
objProcess.Terminate()
Next


Change notepad.exe to your applicaton name. Save the file with a VBS extension and call it from your batch file. You cannot mix batch code and script code within the same file. Well you can, but it sure does create a mess when you run it.

Good luck.

7818.

Solve : Finding files?

Answer»

I don't know the directory a file is saved in, is there a command that can tell me where it's located?In WINDOWS (some VERSIONS): Start--&GT;Search

OR

In Windows (other versions): Start-->Find

OR

In DOS: dir filename.ext /s
(from root directory of drive)

You can use WILDCARDS with any method.

7819.

Solve : How to open windows command prompt with admin rights???

Answer»

i need to CHANGE the PC IP ADDRESS from command prompt which is possible when we have admin RIGHTS,So is it possible to change the rights from local to admin from windows CMD prompt. .Have you tried using RUNAS and then the command?

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=trueQuote from: gopal1 on OCTOBER 17, 2013, 03:00:42 AM

i need to change the PC IP address from command prompt which is possible when we have admin rights,So is it possible to change the rights from local to admin from windows CMD prompt. .

Does this need to be done from command prompt? Because it will require the same right/privledges from command prompt as it does from the TCP/IP Config GUI...
7820.

Solve : samsung hd103sj faulty!!?

Answer»

In the control PANEL USER applet you can remove users.
No that doesn't help !!. There is only my account and a GUEST which not in use. HOME GROUP is listing this "ghost user" !.

7821.

Solve : Update computer date, time, and timezone?

Answer»

Is there any way to update the current date, time, and timezone from time.gov or time.windows.com without requiring the user to make any manual adjustments? I currently have my script to do a resync, but it doesn't automatically update the current date, time, and timezone if they're incorrect. For my work-around, I start the timedate.cpl so the user manually CONFIGURES it, but I need something that is automated.

w32tm /resync >nulI found this script but coming up with errors with the first line. My next big ISSUE is setting timezone, is there ANYWAY the time servers can set time zone by iprecognition?

w32tm /config /sychfromflags:manual /manualpeerlist:time.nist.gov
-The following arguments were unexpected:
-/sychfromflags:manual
net stop w32time && net start w32time
w32tm /config /update
w32tm /resync /force

To CLARIFY the purpose of this script is simply to update my companies customers time and date to prevent a login loop issue. I'm not doing anything malicious at all for those who may think otherwise. I would appreciate any help that I can get on this. Thank you.I figured it out. For those of you who need a script to automate the Date, Time, and Timezone to update, here you go:

w32tm /config /manualpeerlist:time.nist.gov
net stop w32time && net start w32time
w32tm /config /update
w32tm /resync /force
tzutil.exe /s "Enter Time Zone"

If you want to know the list of time zones available, enter: tzutil /L in the command line.

7822.

Solve : Xcopy Batch File?

Answer»

Hi,

I created a batch file to perform a daily backup of changed files from my hard disk to a large (Fat32) flash drive using xcopy. I've used the xcopy command successfully with Windows XP for years. But after switching to Windows 7 I've been having difficulty getting the batch file to work correctly with some directories.

The problem is that it doesn't drill down into my users/username/appdata/roaming/Microsoft directories. It does work correctly in most other directories (such as documents), but it doesn't copy SUB directories in certain places such as users, and program data.

Here it is:

cd\
xcopy c:\*.* f:\ /s /m /y /c /EXCLUDE:C:\exclude.txt
cd\

The exclude part works fine. I've been excluding the C:\windows folder and C:\program files folders.

I've tried using the /n /r and /i switches with no luck. I close down all programs before running the batch file. I did try to use Rich Copy but I couldn't figure that program out to save my LIFE :-)

Am I missing something, or is there no way to get xcopy to work properly with Win7?

Thanks.

A bunch of questions to try to get a better idea of the problem.

  • Can you list some of the specific files that are having this issue?
  • Have you checked that the archive attribute is set for those files? Because of the /M flag.
  • Do you have permission to access/modify the flag attributes of those files?
  • Are there any error messages displayed for those specific files? Remove the /C SWITCH.
  • Have you tried also just using the /L switch and running on the directories in question?
Yes to all your questions. :-)

I'm wondering if this COULD be a limitation of xcopy itself.

In another forum this is what someone said:

"xcopy cannot copy open/locked files and an admin doesn't own all the file system in Windows now."

What doesn't make sense is that I do have access to these files, but xcopy doesn't for some reason. Is there any way to run a batch file in some kind of admin mode?

As another option I would be happy to buy a program to do this for me. All I'm looking for is a program that copies changed files to a flash drive and then resets the archive bit on the source file. I would like to have the files be readable on any PC, so compression or proprietary formats wouldn't work. An image or clone program wouldn't be the answer either.

Do you know of any programs that could do this?

Thanks.Quote from: DigitalDawn on January 15, 2013, 04:04:32 AM
Is there any way to run a batch file in some kind of admin mode?

Right click the batch file and run it as admin/with elevated permissions.

See if that does it as you expect it should.No that didn't work either. :-(
The essence of the problem has to do with ownership of files and folders.
Windows can have multiple users on a machine and the expectation is that they can each have files which other users cannot view or use.

This user system LEADS to admin users and other classes who can use takeown.exe and cacls.exe to change permissions on the file system and give the ability to access certain system and user folders.

If you have no expectation of security on your computer then you can give permission to each file and folder to "Everyone" which is a user privilege that is very low in the security hierarchy. Windows isn't designed to allow this - some folders will revert to system access repeatedly - and this will allow malware to gain access easily too.

Another way around this is to create a folder which you use to save every personal file into, in a category of sub folders, and then backup this 'master' folder which contains all your files.

You might also like to investigate XXclone which can backup the entire hard drive to a USB device (or internal drive) in file mode - and each backup only copies the changed/new files and gives you a mirror and bootable backup. The benefit is that after the initial backup then each subsequent backup is very swift, of the entire system. You can access every file in the backup the same way you can on your master drive. The backup hard drive only needs to be as large as the files, so you can backup to a smaller HDD than the primary c: drive.

Robocopy is a command line tool that is similar to xcopy but it also skips existing files in the backup, so is swift. It has mirror backup capability too.
Similar to xcopy, it cannot copy files and folders that your user does not have permissions to access.

I hope that illuminates the issue somewhat...Thanks for your detailed response.

I checked out XXClone and it really isn't going to work because it requires a full-clone backup initially, which I can't do with a flash drive. Same thing for Acronis and other similar programs.



7823.

Solve : call another batch file on a particular day?

Answer»

I have been given the job of creating a script to call five scripts called Monday to friday on a domain controller. So instead of five tasks in windows backup i create ONE script that calls one of the other day scripts i suppose it would go along like this.

If monday, run Monday script
If Tuesday, run tuesday script.

And so on, is there an easy way to get this happening. Or would i be better of just creating 5 task in windows backup to run the individual scripts.

Im not a script person but i know the very basics.

Thanks for any helpThere are 2 ways to achieve this that I can think of.

#1 - scheduled task to trigger the BATCH to execute, using the built in task scheduler. http://technet.microsoft.com/en-us/library/cc748993.aspx

#2 - create a custom service ( requires adequate programming experience to create a custom service ) that triggers at say 12:01am and it calls to the batch file to execute. Then the service sits idle until the next day and it triggers the batch associated with what day it is.here is how you check day in batch, in case you only want it to run while your script is running.

if 'echo %date%' outputs
Code: [Select]10/16/2013 Wed
we can count over to where the day of the week starts:
Code: [Select]1 0 / 1 6 / 2 0 1 3 _ W e d
1 2 3 4 5 6 7 8 9 10 11 12

This means that the 12th character of the output of %date% is W. Using this, we can tell %date% to start on the 11th character (12-1 because we want it to display the W) and output everything after that. To do this we use the syntax "%date:~11%".

On an off topic, we can add a stopping point by using %date:~11,1%. This will start on the 11th character, and display only 1 character.


Another (complicated) way we can do this is with 'wmic' and 'for /f'.
Code: [Select]for /f "tokens=2 delims==" %%A in ('wmic path win32_localtime get dayofweek /VALUE') do set dayofWeek=%%A
1 = Monday
...
7 = Sunday

(This method may not work. It depends on your system.)I'd say it's best to use Windows built in scheduling function. In my experience it's just been more stable and easier to maintain that way. However if you didd want to go batch for a particular reason, I'd go with Lemonilla's first recommendation and do something like:

Code: [Select]Set day="%date:~11,1%
Call %day%
Exit

Then build each of your day scripts.

You can also just build each od your day scripts into the main script as their own section and replace Code: [Select]call %day% with Code: [Select]call:%day%. I could be off on the call syntax for that... Somehow I always forget that. :/ it would also probably be wise to put an ERRORLEVEL check in there too after the CALL... Just in case.

However you decide to do it, you kinda have to use the scheduler for at least the start script... Unless you left it running constantly and just pinging or waiting for nothing... Or looping in a FOR statement... None of which are ideal or stable.

So yeah... My advice, if you want to/have to go with .BAT, use the above method and build everything into a single script.This is a straight FORWARD way of doing it, but depends on the %date% variable format.

When I type this I get the following:
C:\>echo %date%
Thu 17/10/2013


So this batch file checks for the day name and launches the appropriate batch file.

Code: [Select]@echo off
echo %date%|find "Mon" >nul &AMP;& "monday.bat"
echo %date%|find "Tue" >nul && "tuesday.bat"
echo %date%|find "Wed" >nul && "wednesday.bat"
echo %date%|find "Thu" >nul && "thursday.bat"
echo %date%|find "Fri" >nul && "friday.bat"
Quote from: foxidrive on October 17, 2013, 01:15:13 AM

This is a straight forward way of doing it, but depends on the %date% variable format.

When I type this I get the following:
C:\>echo %date%
Thu 17/10/2013


So this batch file checks for the day name and launches the appropriate batch file.

Code: [Select]@echo off
echo %date%|find "Mon" >nul && "monday.bat"
echo %date%|find "Tue" >nul && "tuesday.bat"
echo %date%|find "Wed" >nul && "wednesday.bat"
echo %date%|find "Thu" >nul && "thursday.bat"
echo %date%|find "Fri" >nul && "friday.bat"

Also a workable method!
7824.

Solve : Batch list and create a txt from listing inside another txt!?

Answer»

Hi!

I created a batch file to list every .apk file inside that same directory!

with the code:

Code: [Select]@echo
for /r . %%g in (*.apk) do echo %%~nxg >> list.txt
The final listing (list.txt) is for example:

Code: [Select]AccuweatherDaemon.apk
AccuWeatherDaemonService.apk
AccuweatherWidget.apk
AccuweatherWidget_Main.apk
After i get this listing i created another batch to create a specific code to create specific list for the files inside the list.txt:

Code: [Select]@echo off
for /F "TOKENS=*" %%A in (list.txt) do (
echo.symlink("/preload/symlink/system/app/%%~nA.apk","/system/app/%%~nA.apk"); >> symlinks.txt
)
And i wanted the final listing to appear as:

Code: [Select]symlink("/preload/symlink/system/app/AccuweatherDaemon.apk","/system/app/AccuweatherDaemon.apk");
symlink("/preload/symlink/system/app/AccuWeatherDaemonService.apk","/system/app/AccuWeatherDaemonService.apk");
symlink("/preload/symlink/system/app/AccuweatherWidget.apk","/system/app/AccuweatherWidget.apk");
symlink("/preload/symlink/system/app/AccuweatherWidget_Main.apk","/system/app/AccuweatherWidget_Main.apk");
But what i get is:

Code: [Select]symlink("/preload/symlink/system/app/AccuweatherDaemon.apk","/system/app/AccuweatherDaemon.apk"
symlink("/preload/symlink/system/app/AccuWeatherDaemonService.apk","/system/app/AccuWeatherDaemonService.apk"
symlink("/preload/symlink/system/app/AccuweatherWidget.apk","/system/app/AccuweatherWidget.apk"
symlink("/preload/symlink/system/app/AccuweatherWidget_Main.apk","/system/app/AccuweatherWidget_Main.apk"
Somehow the ); is getting ignored!

Anyone know how to fix it?

ThanksCode: [Select]@echo off
for /f "tokens=*" %%A in (list.txt) do (
echo.symlink("/preload/symlink/system/app/%%~nA.apk","/system/app/%%~nA.apk"^); >> symlinks.txt
)
Add an escape character ^ before the ) close parentheses character. ) is being interpreted as the end of the LOOP because it is a special character. Escaping NEEDS to be done for all special characters used as literals not contained within double quotations.I was just replying my own post with the exact same SOLUTION as you provided my friend!

I remembered about the special characters too!

And then i found this post:

http://stackoverflow.com/questions/10021464/batch-file-to-add-characters-to-beginning-and-end-of-each-line-in-txt-file

Which clarified everything to me

Thanks for your help!

7825.

Solve : Batch quiz menu help?

Answer»

Hi, Batchmaniac800 here. I am making a simple batch quiz for fun, but I can't figure out the command to make any input besides the one I specified to make you stay on the menu. I think it's the "if not start goto MENU", but i'm not really sure. I TRIED it but it didn't work. Can ANYONE please give me the command? I have underlined the PART I have trouble with. Here is my start:

:MENU
@echo off
cls
echo Welcome the the math quiz
echo To begin, type start and press enter.
set /p input=cmd?
if %input%==start goto LOAD
if not start goto MENUJust use goto MENU after the if %input%==start statement. That way if it ever fails the if statement it will go back to the menu. No need to do a SECOND if not check.

Code: [Select]:MENU
@echo off
cls
echo Welcome the the math quiz
echo To begin, type start and press enter.
set /p input=cmd?
if %input%==start goto LOAD
goto MENUWith the EXTRA quotes you can include poison characters and also use two or more word inputs.
The /i makes the test case insensitive so if they type START, Start, or start they will all work.

Code: [Select]:MENU
@echo off
cls
echo Welcome the the math quiz
echo To begin, type start and press enter.
set /p "input=cmd? "
if /i "%input%"=="start" goto LOAD
goto MENU

7826.

Solve : Random numbers?

Answer»

Hi friends. I'm slowly coming to grips with notepad++
in a game im doing I want to get a random number between 1 and 100
so I use
set /a num=%random% * 100 + 1
I then want to use that number to goto various parts of the prog
echo number is %num%
01 - 20 goto part a
21 - 70 goto part b
71 - 95 goto part c
96 - 100 goto part d

01 - 20 I use if %num% LSS 21 goto part a

96 - 100 I use If %num% GTR 95 goto part d

how do I set the middle two (21 - 70 and 71 - 95)

Look forward to a reply

regards, Raggie









Code: [Select]if %num% gtr 20 if %num% lss 71 goto :partb
Code: [Select]set /a num=%random%*100/32768+1
set flag=0

if %num% LSS 20 set flag=1 && goto :a
if %num% LSS 70 if not "%flag%"=="1" set flag=1 && goto :b
if %num% LSS 95 if not "%flag%"=="1" set flag=1 && goto :c
if not "%flag%"=="1" goto :d
echo ERROR at random number 1-100 generation

you may not need %flag% at all, but it's never a bad idea to have fail safes.Thanks guys I will try these ASAP.Quote from: Lemonilla on October 11, 2013, 07:55:34 PM

you may not need %flag% at all, but it's never a bad idea to have fail safes.

This is what I believe is called "cargo cult programming"

http://en.wikipedia.org/wiki/Cargo_cult_programming


If X is Y {
If X is really Y {
$Do_Something
}
}


correct me if I'm wrong, but since batch is linear in its processing, you don't need anything to do that, you just need to sequence the IF statements correctly.

e.g.
Code: [Select]REM set num
set /a num=%random%*100/32768+1

REM argue num value
if '%num%' LSS '21' goto result
if '%num%' LSS '70' goto result
if '%num%' LSS '96' goto result
if '%num%' LSS 101 goto result
goto error

REM check result
:result
echo your random number is: %num%
pause &GT; nul

REM just in case
:error
cls
echo there has been an error.

Since each IF is arguing "less than (as exact value)" and it has a GOTO as the result, so it will GOTO result if in range, otherwise go on to the next argument. If a value passes through <21, then it's bound to hit one of the following segments...

Anyway... not sure if that logic MADE sense... lolIn ESSENCE you're right - but you've forced an ascii compare in your code, and got a number out by one.

Based on your code, this kind of thing will work:

Code: [Select]if %num% LSS 21 goto resultA
if %num% LSS 71 goto resultB
if %num% LSS 96 goto resultC
if %num% LSS 101 goto resultDQuote from: foxidrive on October 16, 2013, 07:03:38 AM
In essence you're right - but you've forced an ascii compare in your code, and got a number out by one.

Based on your code, this kind of thing will work:

Code: [Select]if %num% LSS 21 goto resultA
if %num% LSS 71 goto resultB
if %num% LSS 96 goto resultC
if %num% LSS 101 goto resultD

Yeah, I just kinda spat that out as an example. but since the number will only progress to the next IF argument if it exceeds the current range, then there's not really much need to scale floors and ceilings by nesting the statements - it's just letting DOS do it's thing. LOL!

Anyway, it's always nice to make the script less verbose if POSSIBLE.
7827.

Solve : help with that *.*?

Answer»

Hello,
It is my FIRST post .

i made Batch file but i have problem

i have file named virox.txt

i made Batch with this commands


@echo off
Echo. > virox.txt

this commands clears virox.txt content

if i make commands like that :
@echo off
Echo. > *.txt

it doesn't work.

if i made it like that :

@echo off
Echo. > *.*

it doesn't work also.

i'm using it to clear contents of txt,dat,biz and doc files and type new content

i want to make that with one command .
i want to use *.* with Echo. Command .

Many Thanks .Quote

Echo. > *.txt
Is always wrong.
File redirection must have a SINGLE target.
The expression *.TXT COULD mean one file, or a thousand files. It is to be used in command that can have multiple targets.

D:\>cd dos

D:\DOS>Echo. > *.txt
The filename, DIRECTORY name, or volume label syntax is incorrect.

D:\DOS>

What is it you want to do?Quote
i'm using it to clear contents of txt,dat,biz and doc files and type new content

for %%A in (*.txt *.dat *.doc) do echo. > %%AQuote from: Geek-9pm on October 14, 2013, 10:15:44 AM
Is always wrong.
File redirection must have a single target.
The expression *.TXT could mean one file, or a thousand files. It is to be used in command that can have multiple targets.

D:\>cd dos

D:\DOS>Echo. > *.txt
The filename, directory name, or volume label syntax is incorrect.

D:\DOS>

What is it you want to do?


this is my problem ...

Many Thanks for your reply Quote from: Salmon Trout on October 14, 2013, 11:46:11 AM
for %%A in (*.txt *.dat *.doc) do echo. > %%A

Many Thanks man..

This Command works with me ,,,

Many Thanks again ...
7828.

Solve : Batch "book" needs editing?

Answer»

So I spent the last while (something like 2 months) compiling all of my knowledge of Batch into a "book". The good majority of it is probably wrong. I was wondering if you guys would mind reading a BIT of it, and pointing out any errors or mistakes I may have. I don't expect anyone to read the whole thing (23 pages), but even a chapter would help immensely.

Thanks so much guys!

[year+ old attachment deleted by admin]Just did a quick skim of the first chapter and the code EXAMPLES. Might read it some more tonight. Here is what I noticed on my lunch break.

  • (Spelling) VERIABLE
  • Quote
    Whereas REM is a command, '::' is simply not compiled (convert written code to code that the computer can understand) with the script. This means that when run, '::' is nowhere in the program."
    :: is a hack to the label : modifier and batch is not compiled. Batch is passed to the cmd.exe parser line by line and interpreted. Therefore, the :: is still passed to the parser but is processed as a label, essentially ignoring it; while the rem is passed to the parser and is executed as the rem command.
Quote from: DigitalSnow on January 15, 2013, 11:07:59 AM
Just did a quick skim of the first chapter and the code examples. Might read it some more tonight. Here is what I noticed on my lunch break.
  • (Spelling) VERIABLE
Oops... Can't believe I made that mistake.
Quote from: DigitalSnow on January 15, 2013, 11:07:59 AM
  • :: is a hack to the label : modifier and batch is not compiled. Batch is passed to the cmd.exe parser line by line and interpreted. Therefore, the :: is still passed to the parser but is processed as a label, essentially ignoring it; while the rem is passed to the parser and is executed as the rem command.
I didn't know that. Thanks, I'll be sure to make the changes. Not sure if you ever heard of the M.U.F's listing before, but there is a Microsofts Undocumented Features txt file out on the net that has a list of neat features that have been discovered. Worth looking into if you haven't already. Some undocumented features still work, while others are degraded or no longer active. Might be something to add link to in your book for anyone who might need a DOS command to do something special in a batch file. This hasn't been updated in years though, and any use of such instructions is at own risk: http://archive.hmvh.net/txtfiles/it/MUF15.TXTQuote
If you've read many of these books, this SECTION is usually used to explain the inner workings of a computer and it's history.

There should not be an apostrophe in its.

Quote
Any word (or string of characters) beginning with a single colon ( [but not two] is what I like to call a 'flag'.

I like to call them 'labels', like Microsoft does.

Quote
but to that my friend I say Nay!

I think you need to develop a more serious and formal English style, and also there are lots and lots of spelling mistakes.



Quote from: DaveLembke on January 15, 2013, 03:13:54 PM
Not sure if you ever heard of the M.U.F's listing before, but there is a Microsofts Undocumented Features txt file out on the net that has a list of neat features that have been discovered. Worth looking into if you haven't already. Some undocumented features still work, while others are degraded or no longer active. Might be something to add link to in your book for anyone who might need a DOS command to do something special in a batch file. This hasn't been updated in years though, and any use of such instructions is at own risk: http://archive.hmvh.net/txtfiles/it/MUF15.TXT
I have not heard of it, but will look into it. Thanks!

Quote from: Salmon Trout on January 15, 2013, 03:32:48 PM
I like to call them 'labels', like Microsoft does.
I mainly learned from analyzing pre-written code, so I never did learn the names for THINGS. Thanks.

Quote from: Salmon Trout on January 15, 2013, 03:32:48 PM
I think you need to develop a more serious and formal English style, and also there are lots and lots of spelling mistakes.
I was trying to make it informal. I figured it would help readers (who don't know much about code/scripts) to better understand how things worked. I was also trying to make it more engaging, I know that the c++ book that I am working through right now, uses lots of fancy words, and its dead dry.

And I was expecting the spelling mistakes, I hope it wasn't too much of a distraction.Quote from: Lemonilla on January 15, 2013, 07:21:35 PM
I was also trying to make it more engaging

For many readers, an excessively chatty style, coupled with a zillion spelling mistakes says "I'm aged 13!" and makes it less engaging.
7829.

Solve : Delete spaces from filenames??

Answer»

Hi,
Is it somehow possible (using DOS/batch PROG) to delete all space occurenses in filenames? The space(s) are not i a certain place, but can OCCUR wherever in the filename.

Ex.
f ile.txt
fil e.txt
file .txt

Many thanks!
-ronThis is a trick question, right? Using your example, the code will crash and burn with duplicate file names.

Code: [Select]
@echo off
for /f "tokens=1-2 delims=." %%a in ('dir /b DIRNAME') do (
for /f "tokens=1-6" %%i in ("%%a") do (
for /f %%x in ("%%b") do (
ren "dirname\%%a.%%b" %%i%%j%%K%%l%%m%%n.%%x
)
)
)


Replace dirname with a valid value. This will work for up to six embedded spaces. If you SUSPECT you have more, change accordingly.

Happy Computing...

7830.

Solve : Help with this script please?

Answer»

I'm trying to GET the desktop shortcut that contains the url of alldata to be deleted. The SCRIPT locates the file, but for some reason doesn't delete it. Please help!

Script:
@echo
for /f "tokens=* delims=" %%i in ('dir /a:-d /b /s "%userprofile%\desktop\*.url"') do (
findstr /m /i "alldata" "%%i"
if not errorlevel 1 del %%i
)


Result:
C:\Documents and Settings\user.TSXP\Desktop>(
findstr /m /i "alldata" "C:\Documents and Settings\user.TSXP\desktop\MyALLDATA -
24-7 Self-Help Articles & Videos.url"
if not errorlevel 1 del C:\Documents and Settings\user.TSXP\desktop\MyALLDATA -
24-7 Self-Help Articles & Videos.url
)
C:\Documents and Settings\user.TSXP\desktop\MyALLDATA - 24-7 Self-Help Articles
& Videos.url
The SYSTEM cannot find the path specified.

C:\Documents and Settings\user.TSXP\Desktop>(
findstr /m /i "alldata" "C:\Documents and Settings\user.TSXP\desktop\Repair - Lo
gin.url"
if not errorlevel 1 del C:\Documents and Settings\user.TSXP\desktop\Repair - Lo
gin.url
)
C:\Documents and Settings\user.TSXP\desktop\Repair - Login.url
The system cannot find the path specified.I actually fixed it, just needed quotes around the last %%i.You have participated in the NEW COMPUTER Hope
Subliminal Stimuli assistant.

7831.

Solve : MS DOS can not identify pipeline charactor?

Answer»

Hello all,

I am using Windows 7.

My Dos prompt is unable to identify the | character.
The following error occurs.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Anuradha\Desktop>time /t
04:24 PM

C:\UsersAnuradha\Desktop>echo |time
The system cannot find the path specified.


Can somebody kindly help me to resolve the issue?
Thanks in advance.

Anuradha
.check for an
echo.bat
echo.com
echo.exe
or a file just called echo
somewhere in the current directory or the path

Then try this to see if it also complains.

CODE: [Select]time /t|sortMicrosoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Anuradha>time /t|sort
The system cannot find the path specified.

C:\Users\Anuradha>time /t
09:35 AM

C:\Users\Anuradha>time /t sort
09:35 AM

C:\Users\Anuradha>time /t|sort
The system cannot find the path specified.
\

It also complains and as I feel the error is generated from the "|" pipeline charactor

Thanks.
Anuradha
Does it also complain when you type this?

Code: [Select]ver|sort
Yes.
The results attached for your referernce.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Anuradha>ver

Microsoft Windows [Version 6.1.7601]

C:\Users\Anuradha>ver |sort
The system cannot find the path specified.

C:\Users\Anuradha>


Thank you.
Anuradha
can you try these commands, in case there is an issue with your temp folder?

echo "%temp%"
cd /d "%temp%"Hi,
It seems to be there is no error with the temp folder.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\bgf478>echo "%temp%"
"C:\Users\bgf478\AppData\Local\Temp"

C:\Users\bgf478>cd /d "%temp%"

C:\Users\bgf478\AppData\Local\Temp>

It's an odd error.

Run this command (assuming your windows drive is c:) and let it run on reboot.

Code: [Select]chkdsk c: /f
See if that makes any difference.

Also try deleting files from temp, in case some process has created millions of files.

Code: [Select]del "%temp%\*.*" /s /qI suggested the %temp% issue but a pipe doesn't create temp files like it used to in Win9x etc. It uses the registry.

Maybe there is an issue with your registry being corrupted in some way. I tried to GOOGLE for the error but with no luck.
If chkdsk and freeing up temp files doesn't help then maybe a repair install is what I would try next.

EDIT: Check your %path% statement for illegal syntax or charactersHi,

Thanks for your suggestions.
Both chkdsk and deleting temp files did not resolve the issue.
Yes, it can be a registry issue.
Because my machine used to work properly earlier and the malfunctioning was observed from about four weeks time.

Yes. There is the option of formatting the machine which would be painful.
I WANTED to avoid that.

Here is the %path% variable content

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\bgf478>set %path%
Environment variable C:\Program Files\Common Files\Microsoft Shared\Microsoft On
line Services;
C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services;
C:\Program Files (x86)\IBM\RationalSDLC\common;
C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\IBM\RationalSDLC\ClearCase\bin;
c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;
C:\Program Files (x86)\IDM COMPUTER Solutions\UltraEdit\ not defined


Regards,
AnuradhaTry this:
Code: [Select]Type "ver" (without quotes) then press "ALT+0124" (without quotes) then type "sort" (without quotes) and press enter.Hi,

Thanks for suggestion.
But it too behaves same as earlier.


C:\AnuProjects\MPA3p0\CETK\CETK SRC\SensorMicroTest\Util\CETKUtil


Thanks.
AnuradhaVerify that the file "sort.exe" exists in C:\Windows\System32
You can use SFC.EXE to scan the system files after you open an admin elevated cmd prompt

Code: [Select]sfc /SCANNOW
I suspect that cmd.exe itself might be corrupt.


But if that fails you can try a system restore to a point four or five weeks ago.

7832.

Solve : Batch File with variable Filenames?

Answer»

Hi!

I'm new in the batch file things and i need help...
What I want to do is to create a batch file that LOADS files into a specific software...

there is a command that we use to load a file such as:

"load -a "
basically the server and application are known and constant... what is changing is the filename.
I have a folder that contains over 200 files and I want to load them all...
so how can I create a batch file that will load each file of the 200 ?

Please help
thank you in advance!forgot to tell you i'm running windows 2000 SP4....I'm not sure that load is a valid command. That said, you would have to script your application not the command processor.

On the other hand, if load is valid then something like this might work:

CODE: [Select]
for /f %%a in ('dir /b path\*.ext') do (load <server> -a <application> %%a)


Fixup path\*.ext and fill in and with real world values.

Thank you very much for your time and effort!!
It worked perfectly fine!



Hey!

I have another question...

After the above loop is DONE, no files should remain in the directory because the load command actually deletes the files after a successfull load... So I need to check if the directory is empty. If not empty I need an error message to be displayed....

Thank you for your support! hope to hear from you soon....Why do you insist on punishing yourself with these CRYPTIC batch files?

[sigh]

Code: [Select]
@echo off
for /f "tokens=1-3" %%a in ('dir yourdirgoeshere ^| find /i "file(s)"') do (
if %%c==0 echo Directory is Empty
if not %%c==0 echo Directory NOT Empty
)


Fill in yourdirgoeshere and you should be good to go.

Hope this helps.

7833.

Solve : Kill command in DOS?

Answer»

Hi! Is there a command that can be USED to kill an application. I know one in unix but not too sure abt DOS

if so can u let me know

in terms of killing the application do we need to enter the entire path or just .exe would be good.

ThanksIn DOS use an applications exit FUNCTION to shutdown a job. If a job is running at the console, use ctl-c.

In Windows, use either an applications exit function to shutdown a job or use the task manager (ctl-alt-del).

You could also use a SCRIPT to iterate all the running processes and based on user input, kill the job that way.

The UTILITY taskkill is not included with all versions of Windows.

Happy Computing...

7834.

Solve : Password Protecting Files?

Answer»

How do you protect a file with PASSWORDS using MS-DOS?
MS-DOS? You can't. PASSWORD protected files are LOCATED in compressed folders using NTFS.

You might try WinZip which MAY ALLOW you to password protect files on a FAT drive.

Good luck.

7835.

Solve : Long File Names?

Answer»

I have jsut started working with the Command Line on my microsoft xp and I have a few questions about how i do some things. I know the commands to everything i just dont know how to type it all correctly.

First off: I WANT to know how to correctly type the commands when files are involved in the command. For example: When I COPY a file. or when I want to ACCESS the file.

Second: Alot of my files have extremely long file names and i want to know how to make the typing alot quiker.

Third: Is there any books anyone recomends to help with this related stuff.I see those long, flowing, descriptive file names have come back to bite you.

When dealing with long file names you can enclose them in quotes to prevent any misinterpretation.

If you run a directory list with the /X switch, the old SHORT file name (8.3 format) will be listed and you can use them to cut down on your typing.

If you need help with command line commands, type the command name with the /? switch for documentation.

Hope this helps. Thank you sidewinder. Your info was very helpful.

7836.

Solve : How to modify the default printer in a Batch ????

Answer»

Hi everybody !

I hope SOMEONE can tell me how to set the default PRINTER in a dos batch ?
I want to CALL my batch program with the printer name as a parameter.

The batch have to set the windows default printer.

Thanks in advance !Generally this is DONE with a script or manually thru the GUI, but batch is what you want, and batch you SHALL get:

rundll32 printui.dll,PrintUIEntry /y /n "printer"

The above line is case sensitive. Replace the word printer with the printer name or a command line parameter.

Hope this helps.

7837.

Solve : Run exe (with answering promoted questions) in a batch mode?

Answer»

Hi All,

Could anyone help me with coding a batch file I want?

I have one exe file. Once I double click it, a black DOS window pops up and ask me "what name the text file has". I have to type in the full name with extension. After pressing enter, one more question followed up in the same black DOS window something LIKE "how many columns in your file? 1. 10 columns; 2. 100 columns: 3. 150 columns. Thereafter, the exe file will ask a few more similar questions.

I want to let the exe process a number of input text files, only the names and data of input files are different, but actually the number of columns and the number of rows etc. are all the same.

So I thought maybe a batch file can run this exe (with answering promoted questions) in a batch mode.

The code in a bat file may look like:

@ECHO off
:: Let the exe run and process file1
start C:\Batexe\myprogram.exe
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?

:: Let the exe run and process file2
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?

:: Let the exe run and process file3
.
.
.
I have maybe 100 text input files. The above code blocks I may repeat 100 times (feel stupid). Hope I have made myself clear. So could anyone help me? Thanks in advance!!!

Put the ANSWERS to the questions in a text file and redirect it, or pipe it into the dos PROGRAM.

If you tell us what the dos program is than we can test if that will work and provide some code.Hi,

Thanks for your quick input.

What do you mean what the DOS is? It is a 100kb single file (xxx.exe). I got from a workmate. I can run it smoothly under my win7. I do not think I can upload the xxx.exe to this forum to share with you great guys.

What do you mean "Put the answers to the questions in a text file and redirect it, or pipe it into the dos program."
You mean a bat file containing one line:

"C:\xxxx.exe" < input.txt >>

where the input.txt contains something like the following:
1.txt
1
gaussian
y
y

Forgive me if I look like knowing nothing...
Can anyone suggest something more? Really appreciate!!!Quote from: Batexe on January 19, 2013, 05:29:42 AM

What do you mean "Put the answers to the questions in a text file and redirect it, or pipe it into the dos program."
You mean a bat file containing one line:

"C:\xxxx.exe" < input.txt
or
type input.txt | "C:\xxxx.exe"



where the input.txt contains something like the following:
1.txt
1
gaussian
y
y


Yes, that is the technique. See above for the command lines.

You can put the filenames in a single text file and read them in for you 100 loops.I have to say - super!

Thank you a lot! You simply make my day!
7838.

Solve : Batch file to add to a text file?

Answer»

I need to create a batch file, that can open a text file, add 4 lines of text to it, save and close it.

How can i do that?

Thanks for your help.Code: [Select]
@echo off
echo line1 >> filename.txt
echo line2 >> filename.txt
echo line3 >> filename.txt
echo line4 >> filename.txt


If filename.txt exists before the batch file is run, the four lines will be appended to the end. If filename.txt does not exist before the batch file is run, it will be created.

Hope this HELPS. That helps, but i wasn't clear enough.

I want to write the following lines in win.ini

Code: [Select][Internal]
Device=zcvMvMu+zr2+vbnGurnJz8e7zcY=
Install=1124174943
Install2=1124174943
Device2=zcvMvMu+zr2+vbnGurnJz8e7zcY=

The solution you gave me helps, but these lines have to be written at the BOTTOM of win.ini in a new line.

When i tried what you told me, it just wrote EVERYTHING on the first line.I don't KNOW how you got everything on one line, but:

Code: [Select]
echo [Internal] >> win.ini
echo Device=zcvMvMu+zr2+vbnGurnJz8e7zcY= >> win.ini
echo Install=1124174943 >> win.ini
echo Install2=1124174943 >> win.ini
echo Device2=zcvMvMu+zr2+vbnGurnJz8e7zcY= >> win.ini


No charge for the FIFTH line.

7839.

Solve : autoexec.bat?

Answer»

Hi there,
I have 3 directories on c:drive: folde1, folde2 and folder, which each folder has different funktion.
a.exe will run succesfull if "folder" name exist.

If I want to test folde1
rename c:\folder folder3
clear
rename c:\folde1 folder
echo -- run a.exe --
a.exe

After test folde1, let say I want to test folde2
rename c:\folder (back to ORIGINAL name) folde1
clear
rename c:\folde2 folder
echo -- run a.exe --
a.exe

and so on
Every time I have to look C:drive where I am now:
folder from folde1 or
folder from folde2 or
folder from folde3

Is possible to make it automatic and create batch file "autoexec.bat"?

Any help?
thanks
If I understand correctly, you are typing those commands into command prompt and wish to create a batch file to automatically run (at what time?)

I don't recognize 'clear'
To check if a folder exists you want to use 'if exist FolderName Command'
To check if a folder does not exist you use 'if not exist FolderName Command'

so if you want to check if a folder named "Folde1" exists, and execute a.exe only if the folder is there, you would have something like:
'if exist Folde1 start a.exe'


If you want it to run on startup, place a shortcut into the startup folder
In Windows 7: (%appdata%\Microsoft\Windows\Start Menu\Programs\Startup)@Lemonilla
Thanks for the quick response.

It is only msdos that run in ram memory booted from FLASH drive.
All the files & directories are inside the flash drive (Nothing to do with internal HD or windows system).
I am trying to reduce the problems and just limit of 2 directories only:
folder and folde1
This is my logical thinking for autoexec.bat, it will work but I dont know how to write the script in msdos.

==>Boot dos to test folde1:
if c:\folde2 exist
do c:\a.exe
else
rename c:\folder folde2
clear
rename c:\folde1 folder
do c:\a.exe

==>boot dos to test folder:
if c:\folde1 exist
do c:\a.exe
else
rename c:\folder folde1
clear
rename c:\folde2 folder
do c:\a.exe

What do you think, is it possible to create autoexec.bat?
ThanksWhat version of MSDOS is it? In MSDOS you cannot rename directories.

Explain what you want to do (not what commands you think will work).@foxidrive
DOS version 4.10.2222
This is my autoexec.bat tested and worked ok, but I dont know how to make if condition(s) script work:

rename c:\folder folde2
clear
rename c:\folde1 folder
clear
c:\a.exe

ThxThis should let you rotate the folders - is that what you want to do?

I don't know what 'clear' does. The screen clear command is CLS

Code: [Select]@echo off
rename c:\folde abc
rename c:\folder1 folde
rename c:\folder2 folder1
rename c:\folder3 folder2
rename c:\abc folder3
c:\a.exe
Thank you very much for your help.
Without your idea may my batch file never work.

It works fine on my test.
http://www.youtube.com/watch?v=-SWBeX8Khlc

DOS doesnt support a file BIGGER than 4 Gb.
NTFS4DOS can read/write on NTFS, but it can not be automatic, because every time I have to type "yes" to agree and punch enter. Is there a magic program to make it automatic? or MAYBE you know similar freeware tools like ntfs4dos?

Thank you very much!
This sort of thing works in some cases. Assuming you are typing the whole word 'yes'

echo yes|ntfsdos commands

or
echo yes>yes.txt
ntfsdos commands del yes.txt@foxidrive
Ntfs4dos can not be use for my build. There is c: drive, but no file found.
Thanks for your script, hope I can use it one day.

7840.

Solve : Emachines Format?

Answer»

I am haveing TROUBLE manually formating my emachines COMPUTER. I need to completely remove windows Xp so I can do an uninstall.
When i go into dos it will not give me access to the C: drive at all just the A: drive. In the emachines computer the format UTILITY on the restore cd just does a quick format when i want to do a full format. It gives you two CHOICES when you inscert the cd. To run their quick format utility or to run dos. So I runs msdos off the cd. When typing in the format c: it give me "bad command". Any help would be appreciated.Download and create a Win98 boot floppy from Boot Disks. That done, boot from the floppy and then format c:

Good luck.

7841.

Solve : Batch File FTP Help Needed?

Answer»

I'm trying to make an FTP updater using a batch file so I use two files; one the script, and one the batch file that runs it.

ftp.bat
Code: [Select]ftp -i -s:"script.bat"
script.bat
Code: [Select]open FTP.SITE
USERNAME
PASSWORD

Using the LCD command in ftp, you can change the working directory on the local computer as far as I know.
I want to know if it is possible for the directory you enter after LCD to be a variable. EX: %location%

I want to do something like this for the script.bat:
Code: [Select]open FTP.SITE
USERNAME
PASSWORD
lcd %CD%
%cd% as in using the current directory that the script and ftp batch files are in.

Is there any way of achieving this?

Thanks \\NathansswellYour syntax should work but this is probably better, as it should HANDLE pathnames with LONG filename elements.

lcd "%cd%"Hmm, that's weird. The first TIME I tried this with the quotations, it gave me some error like: could not find the directory %cd% or something. But I tried it again and it worked. Either way, I'm glad. Thanks.

7842.

Solve : Deleting file older that a certain date?

Answer»

Does anyone know how I can write a bat file to delete files in a directory that are more than say 31 days old?
This is for use on Windows 2000Batch language does not do date arithmetic unless you are prepared to write a boatload of IF statements.

This script may help you out:

Code: [Select]
dim fso, f, fs, fc
set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.GetFolder("YourFolderGoeshere") ' <== CHG
set fc = f.files
for each fs in fc
if datediff("d", fs.datelastmodified, date) > 31 Then ' <== CHG
fso.deletefile fs, true
end if
next


Replace YourFolderGoesHere with a valid directory. You can also use DateLastAccessed or DateCreated in place of DateLastModified. Save the script with a VBS EXTENSION and run from the command line.

You could write a batch file using XCOPY to copy all files newer than 31 days to a temp directory, delete all files from your directory, then copy all the temp directory files back. Very DINKY and you WOULD have to hardcode a date.

Hope this helps. Looks good will give this a go. I had tried the xcopy option but the folder is receiving database archived logfiles from another LOCATION on a regular basis and I could not chance a transfer hitting the folder while it was being renamed and before a new folder had been created.
MANY thanks
Mike Tomlinson

7843.

Solve : Arrays in batch files?

Answer» HI,

i write a code to read the input values while running the SCRIPT. I want to store those values in array and use them later in the script. How can i GET this?


thanks,
Use the set command in a loop.


Quote
@echo off
setlocal enabledelayedexpansion
set c=0
for /F "delims=" %%a in ('type "file.txt"') do (
set /a c=c+1
set cnt=0000!c!
set cnt=!cnt:~-4!
set array!cnt!=%%a
)
set array


If you DESCRIBE exactly what you want to do it would help us to provide some code.
7844.

Solve : Batch File Using Wget?

Answer»

I'm trying to write a basic batch file that will download files from an ftp site that contain a date/time stamp, but I'm having difficulties.

The main part is below. The MODELTIME is a combination of the date and hour variables:

SET MODELTIME=%DATE1%%RUNTIME%
ECHO %MODELTIME%

wget ftp://xxxxxx.com/%MODELTIME%*.GRB


But, this won't work; I'm not sure how to pass the %MODELTIME% variable in the site name.

Thanks in advanceIt is not clear what you want to do or why? Is this just an exercise, or is the a piratical need?

Why use Wget?
http://gnuwin32.sourceforge.net/packages/wget.htm

The standard FTP commands in windows are here:
http://www.nsftools.com/tips/MSFTP.htm

Why not just download all the files in a directory and then select the ones that match the time stamp you want?
BRIAN, you'll need to explain fully and perhaps provide URL info if that is were the issue LIES.

@Geek-9pm: ftp normally uses the system time for downloaded files.

I think brian wants folders that contain a date or time - if they are part of the URL.One of the commands in FTP is to show the current directory. Most SYSTEMS will give time stamps. Here is a picture.

In the above, the name, date and size are shown. Using FTP at the command line should give the same information. But the time is from the date created on the remote computer in the format using by its own system.
But like you said, he needs to clarify what he wants. We were talking about a batch file, not a gui tool though.

And you can't do this because FTP uses the system date and time for creation time.

Quote from: Geek-9pm on January 23, 2013, 05:43:50 PM

Why not just download all the files in a directory and then select the ones that match the time stamp you want?
Thanks for the replies. I could do what Geek suggested and download all files on the FTP site and just KEEP the current files, based on the datestamp, but I'm sure there is an easier way of passing the date/time stamp into the filename.

Foxidrive, you are right that the files from the ftp site have the date/time stamp in their name, so I only wanted to download the current ones. A sample URL is below:

ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2013012400/

So, how can I put the time/date stamp (2013012400) into the wget command:

wget ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.%MODELTIME%/Another approach might be to use WGET to get a file listing of what is in the ftp directory:

Code: [Select]wget ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/

This will produce an index.html file. You could try using batch, but a better solution would be VBScript or Powershell (both available on your machine) to parse the index data and find the most recent files.

Next step would be to use WGET again, this time with specific file names.

Just a thought.
7845.

Solve : Please assist with a small script?

Answer»

I have a small script that I got from the net. This script basically reads the information (ip addresses) from a file and pings them and then inserts the results a text file. This script does exactly what I need but the issue is that instead of ping I need “pathping” which I change in the script. The issue is that during pathping if there is a delay the script sits for like 3 minutes or maybe 5 MINUTE depending on the response.

All I want is some KIND of time out basically maybe like 20 sec and move to the next record regardless of what the response is. Can someone please modify the script below so that the pathping command waits for like 30 sec and then move to the next row of information. Any tips or direction would be appreciated…Thanks

@echo off
cls
echo PathPing test in progress...

for /F %%i in (iplist.txt) do pathping %%i >> result.txt

echo .
echo .
echo Result is ready.Thank you very much.
*Will the -w (timeout) switch option help you here.
Quote

-w timeout Wait timeout milliseconds for each reply.

Such as 5000 millisecond timeout window to timeout after 5 sec with no response?

Quote
for /F %%i in (iplist.txt) do pathping -w 5000 %%i >> result.txt

C:\>pathping /?

Usage: pathping [-g host-list] [-h maximum_hops] [-i address] [-n]
[-p period] [-q num_queries] [-w timeout] [-P] [-R] [-T]
[-4] [-6] target_name

Options:
-g host-list Loose source route along host-list.
-h maximum_hops Maximum number of hops to search for target.
-i address Use the specified source address.
-n Do not resolve addresses to hostnames.
-p period Wait period milliseconds between pings.
-q num_queries Number of queries per hop.
-w timeout Wait timeout milliseconds for each reply.
-P Test for RSVP PATH connectivity.
-R Test if each hop is RSVP aware.
-T Test connectivity to each hop with Layer-2 priority tags.
-4 Force using IPv4.
-6 Force using IPv6.Thanks for the reply. Correct though there is a w (timeout FEATURE) but it would wait for certain time (e.g 250 sec) before MOVING to the next IP. I would like it to move to the next IP right away if there is a delay of more then 10 - 15 sec...Thanks.-p period - Wait period milliseconds between pings.

-w timeout - Wait timeout milliseconds for each reply.

When -p is specified, pings are sent individually to each intermediate hop. When -w is specified, multiple pings can be sent in parallel. It's therefore possible to choose a Timeout parameter that is less than the wait Period * Number of hops.

so i think "pathping -p 15000" this will work. Try this
(15000ms i.e 15 sec)
7846.

Solve : Random number less than x?

Answer»

i am making this batch file and basically i need to generate a random number LESS than or equal to 25.

i know about the command %random% but everything i have TRIED doesn't work

thank youCode: [SELECT]@echo off
:loop
set /a "num=%random% %% 26"
if %num% EQU 0 goto :loop
echo %num%
goto :loop
Works for me.
What did you expect it to do?

You can do it in ONE line

set /a num=%random% %%25 +1
Good thinking BatmanThe number 0 is the smallest non-negative integer. He didn't actually say that zero is excluded, did he? Speaking mathematically, 0 may or may not be considered a natural number, but it is a whole number and hence a rational number and a real number (as WELL as an algebraic number and a complex number).


7847.

Solve : my computer is running in DOS mode only?

Answer»

i have a computer that has windows 98 and it is running in the DOS MODE only it logs on like it going to come up but then it jumps with back into the DOS mode what can I do do I just throw the computer away or what PLEASE help Quote

...what can I do do I just throw the computer away or what please help

If you want to throw it away, why do you come here for help?
THROWING away a computer is not very green of you. Lot's of toxic SUBSTANCES in a PC.

Anyway, just type win at the command prompt.

Hope this helps.
7848.

Solve : .bat to update hostfile?

Answer»

I need help with making a .bat to download a .zip file from http://winhelp2002.mvps.org/hosts.zip and extract and replace the file host file in C:\Windows\System32\drivers\etc automatically. I have searched researched and TRIED but cannot get to work.

thanks
Neil Unfortunately this can be used for malicious intent, so i DOUBT anyone will help with how to make a batch file that downloads from a URL that can be any good or evil URL, then zip file extracting and copying a host file overtop of someone's system which may not be your own. There are scripts to download files at many places on the net and so this task shouldn't be considered a problem.

To unzip the file you will need a third party tool, and to replace HOSTS you will have to provide admin permissions.

This batch file and associated VBS script will download a ZIP file.

Code: [Select]@echo off
start geturl.vbs http://winhelp2002.mvps.org/hosts.zip hosts.zip

:: GETURL.VBS
Code: [Select]Set objArgs = WScript.Arguments
url = objArgs(0)
pix = objArgs(1)
With CreateObject("MSXML2.XMLHTTP")
.open "GET", url, False
.send
a = .ResponseBody
End With
With CreateObject("ADODB.Stream")
.Type = 1 'adTypeBinary
.Mode = 3 'adModeReadWrite
.Open
.Write a
.SaveToFile pix, 2 'adSaveCreateOverwrite
.Close
End With
You can save yourself some time and the BOTHER of a third party zip tool by downloading the text version of the HOSTS file.

Code: [Select]
$client = New-Object System.Net.WebClient

$url = "http://www.mvps.org/winhelp2002/hosts.txt"
$hosts = "c:\windows\system32\drivers\etc\hosts"
$path = "C:\windows\system32\drivers\etc"

if (Test-Path $hosts) {
$file = Get-Item -Path $hosts -Force
$file.Attributes = 'Normal'
}

$client.DownloadFile($url, $hosts)
$file.Attributes = 'ReadOnly'

Your OS comes with Powershell installed, so you may as well take advantage. Save the script with a PS1 extension and run from an elevated Powershell command prompt.

If the script is in the current directory, run: .\scriptname.ps1

If the script is not in the current directory, run: <path>\scriptname.ps1

Good luck.

7849.

Solve : Updating window to the current date and time from time.nist.gov?

Answer»

Is there a way to update windows to the current DATE and time using time.nist.gov or time.windows.com? If I change the time and date, I would like this script to automatically update my computer to the current date and time without me setting it manually. This is what I currently have in place but doesn't set the correct date and time if altered:


w32tm /config /syncfromflags:MANUAL /manualpeerlist:time.nist.gov
net stop w32time && net start w32time
w32tm /config /update
RunDLL32.exe shell32.dll,Control_RunDLL timedate.cpl,,/Z Pacific Standard Time
w32tm /resync /nowait /rediscover
ping 127.0.0.1 -n 5 > nul

It is already in Windows.
A list of the Simple Network Time Protocol (SNTP) time servers that are available on the Internet. http://support.microsoft.com/kb/262680

The above link is a starting point to know more about Internet time sync.Here is a post of mine from SO about setting the time using a ntp server.

http://stackoverflow.com/a/13885418/891976I'm thinking the OP already has a script to retrieve and set the date/time. What's needed is a way to monitor a change and then run the script.

First you would need to check the local SECURITY policy and determine if such events are logged and if not, enable Privilege Use logging. Second would be to write a script to monitor the event log, wait for the event id to be posted and then initiate your script. The monitor script most likely be written in Powershell or VBScript but probably not batch.

If the date/time change is caused by a program, another approach would be to monitor the task list and when the program terminates, the monitor script would run your script to reset the date/time.

Question: why are you changing the date/time? Many Window functions (file/directory time stamping and the task scheduler among others) are affected by such an event.

This may help checking your local security policy.

Thanks for the replies. @Sidewinder - I'm running this script for our customers that have a login loop issue with our website which is normally caused by the date/time/timezone being incorrect. We deal with a lot of MECHANICS that just know how to fix cars, not computers. I'm creating a .exe that will help my customer support agents save an average of 30-40 minutes on the phone from having to manually do this with the customers. I'm most likely just going to have the Date and Time Properties pop-up for the customer for them to manually make the changes rather than make it automated. Too many issues with firewalls and access rights, so manual adjustments are the safest bet. Thanks again for your input, and if you have an easier solution, that would be most appreciated!

7850.

Solve : Batch files and typing words?

Answer»

I have MADE a file that opens up a page on the internet which requires you to sign in. I was wondering if there was a way for the file to automatically type in username, and (TAB) and then password, and then enter to LOGIN. is it possible for the .bat file to type in buttons on the keyboard??Sendkeys using VBS or an AutoIt script should work.