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.

6151.

Solve : XP pro DOS batch file editing?

Answer»

ghostdog74 you are a star!

Your last suggestion worked like a charm.

My 5 test files to be edited all clone beatifully with the 60.0 changed to 50.0 and then back again to 60.0 as many times as I like with no additional spaces and hence no continual increase in file size. Magic!

I put a > nul at the end of the cscript line to get round the problem of MICROSOFT's header running up the screen each time that the vb script is called in the FOR DO loop.

I have cut and PASTED what I had before this addition here:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

The nub of the batch file now looks like this:

@echo off
setlocal enableextensions
setlocal enabledelayedexpansion
for /f %%x in ('dir /a:-d /s /b') do (
cscript freqconv.vbs %%x %1 %2 > nul
)
)
endlocal

And the whole lot runs from the dos prompt with: H:\TEST_DIR> VBChgFreq 50.0 60.0

where my batch file is called VBChgFreq


An observation is that although this vb script version avoids trailing spaces, my impression is that the process runs more slowly than the all batch file version.

So if contrex can crack the DOS batch file problem I may go back to that but hey what an education I have had today.

Thanks very much.

Regards,

Les.Quote from: LesD on June 07, 2007, 08:24:04 AM

An observation is that although this vb script version avoids trailing spaces, my impression is that the process runs more slowly than the all batch file version.
yes, that's because of the algorithm that is looping over the file. Its not efficient. Its left to you to find out why and improve on it if you are interested.
Also, once you become more familiar with vbscript, you will be able to do all in one script, without going through the batch for loop...i guess that would be a bit faster...well....Hi Sidewinder,

Thanks for taking another look.

The problem I have now is that even with the space removed as you show below I still get an addiitional space on all the unedited lines!

Quote from: Sidewinder on June 07, 2007, 04:54:09 AM
Code: [Select] echo !input!>> %%x.chg

In my adapted version of your original code I did remove all the spaces between input! and the > in the initial belief that this would fix it but it didn't.

This bit as shown below is taken from my earlier post above:

if %%i==%1 echo !input1!>> %%x.chg
if not %%i==%1 ( if not "%%j"=="" echo %%i,%%j>> %%x.chg )
if not %%i==%1 ( if "%%j"=="" echo %%i>> %%x.chg )

Before I did this there were two extra spaces added to the ends of the lines when they were written out again!

(The reason for the if statements is to prevent other occurrences of 60.0 in the file being changed too. I forgot to mention this in my first post)!

It is a weirdy. Microsoft would probably say, "How could you possibly not want it to work this way"!

Regards, Les.





Les,

I was able to get this to work on XP Home, but on a XP Pro rig, the batch file created the extra space. You may CALL this weirdy but Microsoft would call it a feature.

I have no answer to this other than to suggest you go with the Ghostdog solution of a VBScript. In the long run VBScript is a richer language, less cryptic, more intuitive and provides more functionality for complex situations than does batch code.

For more info on scripting in Windows check out the Script Center.

Good luck.

Sidewinder, Ghostdog, Contrex,

What can I say other than thanks again for all the help and advice it is much appreciated.

I can live with the time it takes the batch file/vb combination to make the CHANGES. This time last WEEK I was faced with 320 files to edit manually so the utility is a vast improvement on that situation.

Sidewinder,
I am perplexed that the way XP Home processes batch files is different to the way XP Pro does it. I guess we may never know why this is unless Bill Gates joins the forum!

Regards,

Les.
6152.

Solve : Removing all text after a certain line/character?

Answer»

Well, I'm trying to remove all the text after a certain character by using a batch file. For example, if I want to remove all text after the line end in the file test.txt, I've got a tiny bit of code, but I don't know what to do next.

Code: [SELECT]for /f %i in ('findstr /n end C:\test.txt') do (
REM remove all text after end
)

I think that I could remove the :end from %i (%i echos 1:end, because end is on the first line), and then do for /f again, then use "skip:%i" or something.... anyway, I'm just having trouble finding something that removes text from a file, as well as removing the :end.could we perhaps see the file test.txt?

PS I like that "REM remove all text after end". That's like "REM relational database goes here"... A good start... Shows you're making an effort...

Do you mean you want to do this?

Before:-

apples
pears
bananas
end
mangos
lemons

After:-

apples
pears
bananas
end

What confuses me, is that the obvious, the blindingly obvious way to do this is to load the file into a text editor such as NOTEPAD, highlight the text you don't want, and press "delete". I am wondering if you need to do this for homework, or possibly just because you fancy learning how to do batch programming. I'll be charitable and assume the latter, but in either case it would be unhelpful of anyone to just go ahead and write a batch file for you. You would not learn anything that way.

If you like batch programming, and you find it interesting, and you are a curious sort of person, you can hunt around just on this forum and find the answers that you need. If none of those things are true, why are you bothering?

What I am willing to do is sketch out the steps you need (in my opinion) to follow.

1. examine the first line in the file.
2. If it's not the "end" line, write the line out to another file.
3. If it is the "end" line, write the line out and jump out of the loop. (hint: to a label)
4. If it wasn't the end line, get the next line.
5. Keep going until you either find the "end" line or the end of the file.



Maybe you could start by writing a batch that just echoes each line of a file, and only then think about doing some decision making?



Yes, I could just go into the file and delete abc manually, but that's not the point here. The point is that I'm trying to learn how to do this, so I can move to harder stuff.

OK, I just made a code that echos every line of a file one at a time, except that I have to specify how many lines. I just don't know how to remove all lines after that.
Code: [Select]@echo off
set /a SKP=0

:begin
if %SKP% GTR 26 goto end
if %SKP% GTR 0 goto second

:first

for /f "delims=: " %%i in ('findstr /n . "C:\test.txt"') do (

echo %%i
goto second
)

:second
set /a SKP=%SKP%+1
for /f "delims=: skip=%SKP%" %%i in ('findstr /n . "C:\test.txt"') do (

echo %%i
goto begin
)

:end
echo.
@pause


The CONTENTS of test.txt is just the letters of the alphabet on different lines (remove delims: to see the contents).

Just wondering, how do I check how many lines there are in a file without knowing the contents? (I can check how many there are if I know what the last line/character is)This is homework, I am sure. Why do I keep seeing all these lines like this

Quote

for /f "delims=: " %%i in ('findstr /n . "C:\test.txt"') do (

I would not use that to loop through a file line by line.

OK I will slightly RELAX my rule and help you with your homework.

If you are going to blindly copy code from wherever, copy good code! What is wrong with this?...

Quote
for /F "delims=" %%L in (C:\test.txt) do (
echo %%L
)



Quote
Just wondering, how do I check how many lines there are in a file without knowing the contents? (I can check how many there are if I know what the last line/character is)

use set /a to put a variable to zero. read through the file one line at a time, each time add 1 to the variable using set /a, when the loop finishes you know how many lines it has.


Look, as much as you don't want to believe it, this is NOT homework! Also, I made this code myself, not copy it.

With that out of the way, I am still looking for a way to remove text through batch. And the reason that I use findstr is to find out what line end (or whatever a am looking for) is on.

Current Revision:
Code: [Select]@echo off
set /a LNE=0
set /a DOT=1
:find
set /a LNE=%LNE%+1
for /f "skip=%LNE%" %%m in ('findstr /n . "C:\test.txt"') do (
cls
if %DOT% EQU 1 echo Searching line amount.
if %DOT% EQU 2 echo Searching line amount..
if %DOT% EQU 3 echo Searching line amount...
if %DOT% LSS 3 set /a DOT=%DOT%+1
if %DOT% EQU 3 set /a DOT=1


goto find
)

cls
echo Running Program...
echo.
echo.

set /a SKP=0

:begin
if %SKP% GTR %LNE% goto end
if %SKP% GTR 0 goto second

:first

for /f %%i in ('findstr /n . "C:\test.txt"') do (

echo %%i
goto second
)

:second
set /a SKP=%SKP%+1
for /f "skip=%SKP%" %%i in ('findstr /n . "C:\test.txt"') do (

echo %%i
goto begin
)

:end
echo.
echo Done!
echo.
@pause
)

:end
echo.
echo Done!
echo.
@pause
Heh. I even added a little dot dot dot thing for fun.

Anyway, I am still left with the original problem of how to delete text in a batch file. That is my only question.Quote from: Dark Blade on June 07, 2007, 02:44:31 AM
Anyway, I am still left with the original problem of how to delete text in a batch file. That is my only question.

You cannot directly modify a text file stored on disk easily. You have to make a copy which has the changes you want, then delete or rename the original, then rename or copy the new file back to the first filename. This is what in fact happens when you open a text file in an editor such as Notepad, make changes, and save the changed file, only it's all hidden from you, so that you only need the concept of "altering" just the one file. When you dig deeper, as you are doing, you need to appreciate such things.
Quote from: Dark Blade on June 07, 2007, 02:44:31 AM
Anyway, I am still left with the original problem of how to delete text in a batch file. That is my only question.
a rough vbscript solution:
Code: [Select]Const ForAppending=2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\temp\test1.txt", 1)
Set objOutFile = objFSO.OpenTextFile("c:\temp\temp.txt", ForAppending,True)
Do Until objFile.AtEndOfStream
strNextLine = objFile.ReadLine
If InStr(strNextLine,"end") = 1 Then
objOutFile.Close
objFile.Close
objFSO.DeleteFile("C:\temp\test1.txt")
objFSO.MoveFile "C:\temp\temp.txt" , "C:\temp\test1.txt"
WScript.Quit
Else
objOutFile.WriteLine(strNextLine)
End If
Loop
So, contrex, all in all, is it impossible (or close to) to make a batch file that, as you put it, does this:

Before:-

apples
pears
bananas
end
mangos
lemons

After:-

apples
pears
bananas
end

You say that you have to make the changes manually to a copy of the file, and because of that I can't make a file that automatically deletes text.

Well, anyway, THANKS for the help.I repeat,

Quote
You cannot directly modify a text file stored on disk easily. You'd need to be able to alter the disk sectors directly, and update the file size data etc. You have to make a copy which has the changes you want, then delete or rename the original, then rename or copy the new file back to the first filename. This is what in fact happens when you open a text file in an editor such as Notepad, make changes, and save the changed file, only it's all hidden from you, so that you only need the concept of "altering" just the one file. When you dig deeper, as you are doing, you need to appreciate such things in order to make any progress.

Quote
You say that you have to make the changes manually to a copy of the file, and because of that I can't make a file that automatically deletes text.

I didn't say that at all. (Is English your first language?) I have said that you can write a batch file that appears to "alter" a text file, ie, before you run the file, there will be a file called fruits.txt that contains the following lines

apples
pears
bananas
end
mangos
lemons

And after the batch file has finished, there will still be a file called fruits.txt but it will have a later file modified date than the first one, and a different size, and it will contain these lines

apples
pears
bananas
end
Quote
Quote
You say that you have to make the changes manually to a copy of the file, and because of that I can't make a file that automatically deletes text.

I didn't say that at all. (Is English your first language?) I have said that you can write a batch file that appears to "alter" a text file, ie, before you run the file, there will be a file called fruits.txt that contains the following lines

Well, sorry if I misinterpreted you. I thought that was what you meant when you said:
Quote
You have to make a copy which has the changes you want

I didn't see your edit (I posted before it was written), so I didn't grasp everything you meant. Now I understand it.Quote from: Dark Blade on June 07, 2007, 03:25:00 AM
so I didn't grasp everything you meant. Now I understand it.

So now are you going to get coding and we can help you along?
I may sound repeatative, but I don't know how to alter text into files. How do you do that?

Is there any command that can alter/manipulate text? If I get that, then I'll start with some easy, like adding a 1 to the end of each file. Like this:

Before:-

apples
pears
ADD

After:-

apples
pears
ADD
bananas


I don't what exact code, just something to push me in the right direction (because making the code is half the fun!)Quote from: Dark Blade on June 07, 2007, 04:01:43 AM
I may sound repeatative, but I don't know how to alter text into files. How do you do that?
you can alter text in a number of ways
1) looping over the original file using for loop, changing whatever text then echoing the changed line out to another file
2) using available tools, like edlin, findstr , find, type, more , grep etc etc...plus using the >> , > redirection operators
3) using other languages that are more suited for text processing, eg perl/python/awk/sed/vbscript, even Java/powershell etc etc etc . They have more string functions than what DOS batch can offer you and you can have more control over what you are doing
4) others etc etc
You can just completely rewrite that file with the batch file....Quote from: Carbon Dudeoxide on June 07, 2007, 05:15:28 AM
You can just completely rewrite that file with the batch file....
huh? don't understandif the file you wanted to edit was a batch file like this:
Code: [Select]@echo off
echo hello
echo how are you
echo.
pauseand say you wanted to add a "echo i'm good", do this:
Code: [Select]@echo off
del "C:\path\file.bat"
echo @echo off >>"C:\path\file.bat"
echo echo hello >>"C:\path\file.bat"
echo echo how are you >>"C:\path\file.bat"
echo echo. >>"C:\path\file.bat"
echo echo I'm good >>"C:\path\file.bat"
echo pause >>"C:\path\file.bat"

This would delete the old one and create a new file with the added sentence.
The finished product would be:
Code: [Select]@echo off
echo hello
echo how are you
echo.
echo I'm good
pausewow fantastic! but what has this got to do with what OP wants?Quote from: ghostdog74 on June 07, 2007, 08:06:08 AM
wow fantastic! but what has this got to do with what OP wants?
well....he wanted to replace a line of text....
This is another way to 'replace' something Quote from: Carbon Dudeoxide on June 07, 2007, 08:08:43 AM
Quote from: ghostdog74 on June 07, 2007, 08:06:08 AM
wow fantastic! but what has this got to do with what OP wants?
well....he wanted to replace a line of text....
This is another way to 'replace' something
wow and if the input file has 1000000000 lines, are you going to key in a batch file with 1000000000 echo lines ?The whole idea of text processing in batch files has now been explained exhaustively in about 6 different ways, and I would have thought that if a person had not "got" it by now, it would be time to find a less taxing hobby.

Quote from: Dark Blade on June 07, 2007, 04:01:43 AM
Is there any command that can alter/manipulate text? If I get that, then I'll start with some easy, like adding a 1 to the end of each file. Like this:

Before:-

apples
pears
ADD

After:-

apples
pears
ADD
bananas
Adding a line of text to the end of a file is easy. If your file is named food.txt, then your code would be:
Code: [Select]echo bananas >>food.txtQuote from: GuruGary on June 07, 2007, 11:43:41 PM
Code: [Select]echo bananas >>food.txt
LOL funny.
That code puts the text at the end of the file you want to edit.Finally...

Adding - Can do
Replacing whole file - Can do (so many echos... )
Deleting

I just made something that deletes a file if it exists, then add lines to the new file (like what Carbon Dudeoxide did, but it adds the output of my batch file).


I'm going to start making something that deletes all text after a specified line.
6153.

Solve : command file to execute at boot before win XP launches...?

Answer»

Hello,

I was wondering if there was a WAY to execute a batch file at computer boot just before windows start.
I explain... I work for a school in which we have about 20 COMPUTERS per classroom students will soon have to experiment windows install from scratch and so all computers have to be FORMATTED so I was thinking of puting this sort of batch file I could run from SERVER to format all of them at once and not 1 by1....please help
Run Regedit.exe first
----------------------------------------------------------------------------------------------------------
to run for CurrentUser :
# goto --> HKCU\Software\Microsoft\Windows\CurrentVersion\Run
# Create New Value
type : REG_SZ
name : whatever
data : YourBatchFile.bat
---------------------------------------------------------------------------------------------------------
do same to "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" if you want to run your batch for AllUser..

6154.

Solve : close a *.bat file from another *.bat file?

Answer»

can i do that? and how?Use taskkill:

Quote

TASKKILL [/S system [/U username [/P [password]]]]
{ [/FI filter] [/PID processid | /IM imagename] } [/F] [/T]

Description:
This command line tool can be used to end one or more processes.
Processes can be killed by the process id or image name.

Parameter List:
/S system Specifies the remote system to connect to.

/U [domain\]user Specifies the user context under which
the command should execute.

/P [password] Specifies the password for the given
user context. Prompts for INPUT if omitted.

/F Specifies to forcefully terminate
process(es).

/FI filter Displays a set of tasks that match a
given criteria specified by the filter.

/PID process id Specifies the PID of the process that
has to be terminated.

/IM image name Specifies the image name of the process
that has to be terminated. Wildcard '*'
can be used to specify all image names.

/T Tree kill: terminates the specified process
and any child processes which were started by it.

/? Displays this help/usage.

Filters:
Filter Name Valid Operators Valid Value(s)
----------- --------------- --------------
STATUS eq, ne RUNNING | NOT RESPONDING
IMAGENAME eq, ne Image name
PID eq, ne, gt, lt, ge, le PID value
SESSION eq, ne, gt, lt, ge, le Session number.
CPUTIME eq, ne, gt, lt, ge, le CPU time in the format
of hh:mm:ss.
hh - hours,
mm - minutes, ss - seconds
MEMUSAGE eq, ne, gt, lt, ge, le Memory usage in KB
USERNAME eq, ne User name in [domain\]user
format
MODULES eq, ne DLL name
SERVICES eq, ne Service name
WINDOWTITLE eq, ne Window title

NOTE: Wildcard '*' for the /IM switch is accepted only with filters.

NOTE: Termination of remote processes will always be done forcefully
irrespective of whether /F option is specified or not.

Examples:
TASKKILL /S system /F /IM notepad.exe /T
TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
TASKKILL /F /IM notepad.exe /IM mspaint.exe
TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"

Reply if you want something more specific.if its not to much to ask, can it be a tad simpler, if it can't, thank you!Quote from: Amrykid on July 03, 2007, 09:23:53 PM
can i do that? and how?
show your code. Well, to simplify, I need your code, as ghostdog has just asked. But if you only hae one specif that you want to close, do this:

taskkill /f /im filename.batStart=sys\VSCAN\scanner.bat
@echo off

ping -n 1 -w 1000 1.1.1.1 >nul
echo 3 seconds to completion...
echo.
ping -n 2 -w 1000 1.1.1.1 >nul
echo 2 seconds to completion...
echo.
ping -n 2 -w 1000 1.1.1.1 >nul
echo 1 second to completion...
echo.
ping -n 2 -w 1000 1.1.1.1 >nul
echo.
echo Writing results...

REM EXIT="sys\VSCAN\scanner.bat"
ECHO Scan COMPLETED!
pause
echo Gathering scanned item data
pause
start=sys\VSCAN\results.txt
exit "sys\VSCAN\scanner.bat
_________________________________
thats the code i used for a project i was doing.
the problem in the code is exit "sys\vscan\scanner.bat"Is that the contents of scanner.bat?

And is that actual code?
\/
Start=sys\VSCAN\scanner.bat

If you want real code (you'll need to here), do the FOLLOWING:
start "scanner.bat" "filepath\filename.bat"

And for your exits, do this:
taskkill /f /im "windowtitle eq scanner.bat"


Tell me if you get all that, or to tell me if I'm wrong.Quote from: Amrykid on July 03, 2007, 11:38:43 PM
Start=sys\VSCAN\scanner.bat
@echo off

ping -n 1 -w 1000 1.1.1.1 >nul
echo 3 seconds to completion...
echo.
ping -n 2 -w 1000 1.1.1.1 >nul
echo 2 seconds to completion...
echo.
ping -n 2 -w 1000 1.1.1.1 >nul
echo 1 second to completion...
echo.
ping -n 2 -w 1000 1.1.1.1 >nul
echo.
echo Writing results...

REM EXIT="sys\VSCAN\scanner.bat"
ECHO Scan completed!
pause
echo Gathering scanned item data
pause
start=sys\VSCAN\results.txt
exit "sys\VSCAN\scanner.bat
_________________________________
thats the code i used for a project i was doing.
the problem in the code is exit "sys\vscan\scanner.bat"
I say you indeed have a design problem. Do everything in your scanner.bat BATCH file. you don't need a separate batch ...otherwise, show your scanner.bat file.i found out the problem. its was that i forgot to put exit in the choice area.
Yall remined me of that.
thanks!
6155.

Solve : Error Check?

Answer»

Hi Guys,

I am new to DOS Programming. I have a small querry and would really appreciate if you guys can help.

Overview: I want to create a script that has to find a file in a location.

Problem: Both the name of the file and the folder in which the file is created is Variable.

I have written script for 1 file.

****************************************************************************
Del P:\LDN-Results.txt
:SET_DATE
Set /p COB=Enter LDN COB:
IF %COB% ==' ' GOTO END
Else GOTO Check_LDN_Jobs
:Check_LDN_Jobs
Set CBROL_LDN_FEED_TMP=
echo. > P:\LDN-Results.txt

If exist \\xyz\BatchData\temp\20070705_RE_CBROL_LDN_JET_OTH\JetBase_LDN_Others_ErrorLog.txt echo RE_CBROL_LDN_JET_OTH having errors! > P:\LDN-Results.txt

Notepad P:\LDN-Results.txt

:END

@ECHO ========== Batch File Finished ============
PAUSE
****************************************************************************

This is RUNNING successfully for this 1 file. but i want to do the smae for all the folders in "\\xyz\BatchData\temp\" starting with a given date. And then the files ending with "ErrorLog"

Please Assist.you don't want much, do you?
Hi .. I hope you got my question. Please Assist. I'am not really cleared about your problem
but, I try to SOLVED and Hope this help :

..UNTESTED..
Code: [Select]@echo off
Del P:\LDN-Results.txt
:SET_DATE
Set /p COB=Enter LDN COB:
IF "%COB%"=="" GOTO END
:Check_LDN_Jobs
Set CLFTMP=\\xyz\BatchData\temp
for /f "tokens=*" %%a in ('Dir /b A:D "%CLFTMP%"') do (
set SPATH=%%~a
CALL set sdate=%%spath:~0,8%%
If exist "%CLFTMP%\%%~a\JetBase_LDN_Others_ErrorLog.txt" (
echo Time : %sdate% >> P:\LDN-Results.txt
echo Result : RE_CBROL_LDN_JET_OTH having errors! >> P:\LDN-Results.txt
echo. >>"P:\LDN-Results.txt"
)
)
Notepad.exe "P:\LDN-Results.txt"
:END
@ECHO ========== Batch File Finished ============
PAUSE>nul

6156.

Solve : Creating Log file?

Answer»

Anybody can help plz to find the way to CREATE a log file while I am runnning a batch file, ie all the steps performed and messages shown by RUNNING the batch file to be COPIED in a logfile.
Thanks in advance.
Hi Prince748,

You can do this by adding "debug statements" to your batch file. Here is an example of a batch file which contains four debug statements:

Code: [Select]@echo off
if exist log del log
echo Batch file started >>log
echo First parameter is "%1" >>log
echo Second parameter is "%2" >>log
echo Batch file finished >>log

Note that this batch file also contains a statement to delete the log from the previous run, if it exists.

Here is an example of running this on Windows XP:

Code: [Select]D:\test> TEST.BAT 111111

D:\test> TYPE LOG
Batch file started
First parameter is "111111"
Second parameter is ""
Batch file finished

D:\test>

Hope that helps,
James

Thanks. Actually what I wanted - if echo is not off, all the lines and action of the batch file shows on the screen. I WANT those lines to be written to a log file. What command might help?You need to redirect the output of the command processor; call your batch like this :

>> LogFileName cmd /c MyBatchFile.Bat

This will append to the contents of the logfile, if you want to create it anew each time, just USE >
Graham

6157.

Solve : Changing CMD.EXE prompt and current working directory permanently?

Answer»

Hello,

I was just wondering if anyone knew how to change the prompt and current working directory when running cmd in windows XP. My current working directory when I run the command prompt is

Windows version CRAP...

C:\Documents and Settings\jshowa>

I want my working directory to be just plain "C:\" and I want to display the date and time. I looked on this site and it said something about changing the prompt using "prompt $t $d$_$p$g" and to make the change permanent, to edit the autoexec.bat file. However when I add the "prompt $t $d$_$p$g" to the batch file, save it, then reload cmd.exe from run in Win XP it doesn't change anything. Can someone help me out?

Welcome to the CH forums.

The easiest way to achieve what you want is to set up a shortcut on your desktop to access the Command Prompt in XP.

The Target line in the shortcut (R.click the shortcut then L.click Properties>Shortcut Tab) should be edited to show:

C:\WINDOWS\SYSTEM32\CMD.EXE /T:1F /K PROMPT $T $D $P$G

and the Start In line in the shortcut should be edited to show just C:\

Upper case used for emphasis only... $_ appears to generate a Return so should not be used unless you specifically want a 2-line Command Prompt.

If you want to know what /T:1F and /K do enter cmd/? at the Command prompt.

I think you will want to SHORTEN your Command Prompt somewhat when you see what is displayed.

Good luck.

P.S. Autoexec.bat is not used with cmd.exe (I think)

The standard prompt shows the current logged directory (the directory you are in). if you want to see "C:\" at the prompt, why not just type

CD C:\

Quote from: contrex on June 28, 2007, 02:00:35 AM

The standard prompt shows the current logged directory (the directory you are in). if you want to see "C:\" at the prompt, why not just type

CD C:\


Or... just CD\ would do the same thing but then the OP would have to type his Prompt command each time or maybe set up a .bat file to create the required Prompt.. Creating the Shortcut to the Command Prompt as explained in my first response above does the lot with just ONE click and there are also other options available such as using a Window or Full Screen mode that the OP might get round to investigating..

Neither CD C:\ nor CD\ clears the version information which the Op describes as "Windows version crap", he'll have to type CLS as well!! The shortcut to Command Prompt will open either a clean Command Prompt Window or Full Screen as selected by the OP.

Problem solved. Thanks a lot.

I just used $_ to clean up the command prompt, but I can experiment a little more to figure out what I want.How will you know what directory you are in? Are you never, ever, going to be in another directory?

I tried prompt $_ and got just a blinking cursor and a two line gap between commands.

A nightmare!



I just used $_ to feed the information that I had to a new line. I didn't want the information all on one line so I had to move it down. I added $P$G to the end of the "target" for the shortcut to put my current working directory as C:\> which is the current path.

I'm pretty sure you know all of this, but here's where I have it now

Target: C:\WINDOWS\system32\cmd.exe /K PROMPT Welcome Jacob Howarth!$_$V$_$T $D$_$_$P$G

Start in: C:\

This under the shortcut tab that Dusty mentioned above.

However, I have another problem, I was wondering if I could get it to not print the same prompt EVERYTIME I enter a command. For example my current cmd.exe window shows this

Welcome Jacob Howath!
Microsoft Windows XP Version [5.1.2600]
19:24:00.46 Tue 07/03/2007

C:\

However, whenever I type a command "cd" or something it prints the same information after each command is entered. I only want it to display at start up. Does anyone have any guidance? I would gladly appreciate it.If you just want a neat opening message, you might be better off leaving the prompt alone and making the shortcut target something like this

C:\WINDOWS\system32\cmd.exe /K echo Welcome Jacob Howath! & ver & echo %time% %date%

Unfortunately I cannot get %date% to show the 3 letter day of the WEEK ("Wed"), I think this depends on your locale, in my locale, English (United Kingdom) I just get dd/mm/yyyy eg 04/07/2007 but I believe in the English (US) locale you would get "Wed 07/04/2007"

Thanks for the advice. It works perfectly.
6158.

Solve : Unable to delete hidden file?

Answer»

I have a hp machine with MS ME os. I acquired this some time ago and use it as a means to print photos. I recently found that it has been making daily backups to a directory named _restore which has the attrib of hidden. It has over 3 gigs of info in it and has the free space down to 1 gig.
I need to erase this so I can reclaim this space. I found the program that was making the backups and
deleted it. I have tried to remove the h attrib in order to do so but have not been able to. I do not know the Dos WELL enough to be sure that I am giving the correct commands as I keep getting different error messages I did get it to try to delete it but then got the error of file not found.
My question is how do I delete this file, If a dos script is the WAY to do it I need for you to tell me exactly how to enter it (How it will look on the monitor) I cannot just reformat the HARD drive as I do not have the me os or how to do so if I had it. I hope that this is enough info for you to give an answer.
This is my first try at posting so please forgive me if I have asked in the wrong place, I am legally blind so I miss a lot of instructions also I am from a generation before computers and have trouble understanding what seens to come naturally with the present generation.
Thank you George
Have you attempted to empty the folder contents in safemode ? ?

To enter safemode tap F8 repeatedly while the machine is starting before you see the WinME logo.

If this does not work i'd suggest DLoading Killbox and give it a try...

p.s. Welcome Aboard !try this :
DEL /F /Q /A:H "FileName"

6159.

Solve : Write < and > to a file with batch?

Answer»

Hi there
I wonder: how do you write the < and > signs to a (text) file, using batch under windows XP

if I use this code:

>>test.xml echo This is a test

The batch file closes, before I can even see the error.
I think the error is caused because of the < sign that is near the >> command that writes the xml file wich causes confusion for the computer. Is there any way I could solve this problem?

With kind regards

MikiCertain characters like <, >, %, |, etc which have special meaning in DOS/NT command line and batch, need to be "escaped" with a caret character (^) in front like this if you want them to show up in files.

>>test.xml echo this will appear in file ^This is a test^

Quote from: contrex on July 07, 2007, 02:23:47 AM

>>test.xml echo this will appear in file ^<TEST1^>This is a test^</test1^>

This solved my problem.

Thank you so much for your quick help, contrex

Cheers and greets You're welcome. When I wrote "... if you want them to show up in files" of COURSE I should have added "or on the screen"I have another question, if u don't mind

I'd like to somehting like this

Code: [Select]@echo off
set towrite=test (this is just a simple example, in my batch it reads from a file etc and then the batch sets towrite=test)
>>test.xml ^<%towrite%^>
pause
So, I'd like to write my towrite between the < > tags, how do I do that?

Code: [Select]@echo off
set test=test
>>test.xml ^<^%test^%^>
pause
The above code doesn't workYour code

@echo off
set test=test
>>test.xml ^<^%test^%^>
pause

1. You have set the environment variable named test to hold the string "test".

2. A SIDE issue - it can lead to bad confusion if you call variables the same as their contents.

3. You missed out "echo" in your third line which should look like this I guess

>>test.xml echo ^<^%test^%^>

4. However this will result in nothing being written to test.xml since you have escaped the % signs surrounding the variable name.

5. If you remove the carets in front of the % signs

>>test.xml echo ^<%test%^>

test.xml holds this line

<test>

6. If you escape the % signs you no longer have a variable.


6160.

Solve : Batch Files executing at shutdown?

Answer»

I am looking to execute a batch file that I have created, but I do need it to execute in a special way:

Once a user clicks on Shutdown to turn off their computer, a windows message will pop up SAYING "Have you Clocked Out?" If the user selects "YES" then windows will CONTINUE to shutdown. If the user clicks "NO", windows will open the a program/webpage so that users can clock out before shutting down windows. Does anyone know how to do this?
try this
@echo off
cls
:start
echo Have you clocked out
ECHO.
ECHO 1. YES
ECHO 2. NO
set choice=
set /p choice=Select a choice=
if '%choice%'=='1' goto 1
if '%choice%'=='2' goto 2
ECHO "%choice%" please choose one of the choices above
ECHO.
goto start
:1
(something goes here, but i dont know)
:2
start=program/webpage
exit

Code: [Select]@echo off
:start
echo Have you clocked out?
ECHO.
ECHO 1. YES
ECHO 2. NO
set choice=
set /p choice=Select a choice=
if '%choice%'=='1' goto 1
if '%choice%'=='2' goto 2
ECHO Please choose one of the choices above
ECHO.
goto start
:1
shutdown -f -t 00 -s
goto end
:2
start program/webpage
:end

I think that works. I just made a modification on Amrykid's code.Thanks Dark Blade, im a begginner at DOS and command prompt.No problem. You were pretty close, though, you just didn't add shutdown, and forgot a goto. Other than that, it was quite good
But the way I read the first post, the original poster does not need any batch code.

Quote from: rcapulong on July 03, 2007, 10:44:28 AM

I am looking to execute a batch file that I have created,



What he needs is for you to tell him how to get his batch file to run at the time he needs it run:

Quote
but I do need it to execute in a special way:

Once a user clicks on Shutdown to turn off their computer, ...

.... Does anyone know how to do this?

This is strange. I presume "clocked out" means "logged out". When somebody with sufficient privileges initiates a shutdown, all users are logged out automatically.

However, to run a script or batch at shutdown. select Start | Run and type gpedit.msc, then click OK; then look in Computer | Configuration | Windows Settings | Scripts (Startup/Shutdown). Double click Shutdown in the right-hand pane, then click Add to add one or more scripts as needed.
Is it me, or will the code posted previously not WORK because choice was replaced in Win XP. That is if he's running Win XP.Quote from: Jake1234 on July 04, 2007, 01:31:19 PM
Is it me, or will the code posted previously not work because choice

as in choice.com ?

Quote
was replaced in Win XP. That is if he's running Win XP.

choice.com is not being used in the batch FILES above.



Side note, just in case anyone is USING Search and stumbles across this thread: If you need a copy of choice , here is one place to visit.
>Click here<
Quote from: Jake1234 on July 04, 2007, 01:31:19 PM
Is it me, or will the code posted previously not work because choice was replaced in Win XP. That is if he's running Win XP.

a variable called "choice" is being used, but neither choice.com nor choice.exe is being called.

6161.

Solve : Bat PROBLEM!!!?

Answer»

i made a batch file that can make other batch real easy. since today, i made some changes to it.
the problem is i WANT it to save the contents to *.dll and then copy *.dll's contents to *.bat.
heres the code since i CHANGED it.
Code: [Select]C:\>"new.bat"
cls
@echo off
title Welcome to BATCH MAKER.
echo Welcome to BATCH MAKER.
echo You can USE this to make your own batch file.
echo When your DONE, press CTRL+Z, then enter, and your bat will be named other.bat
echo Press any key to start programming!
pause
copy con batdata.dll
pause
copy batdata.dll+new.bat
pause
exit
i dident know you could do that, "copy con"
i think what you want is , instead of copy batdata.dll+new.bat , do copy batdata.dll new.bat |del batdata.dll
i tryed that.
it SAID the syntax is incorrect.copy batdata.dll new.bat

6162.

Solve : my question is this....................pls let me know?

Answer»

Dear All Expert,

i'v run 2 java file so that TASKLIST option is showing two image Name (java.exe) and different PID (like as 2460 & 3789) now suppose if i WANT to do stop one (java.exe) whose PID is 2460. then how could i recognized that i'v closed java.exe file of a particulare PID (2460)......?

pls let me know
help me


Best Regards
Ashutoshyou should do your own homework. It's to help you learn.
thanx for UR suggestion.........!!Dear All Members,

i'm running batch file(start.bat) which run my java aaplication and this batch file stored at C:\ABC\XYZ\start.bat with PID like as 1792 and another batch file with same name run from this location C:\CMD\MNC\start.bat with PID like as 8967 and another batch file with same name run from this location C:\JKL\GHI\start.bat with PID like as 4356 now i make another batch file (kill.bat) and stored at each location. Now i run kill.bat from ( C:\CMD\MNC\kill.bat ) this location.

my question is this that how could i found the PID of start.bat which is run from this location (C:\CMD\MNC\start.bat) and kill this process by KILL.bat file.....?


If anybody help me. PLEASE revert back to me. I'v been tried two file that is KILL_FIRST.bat and KILL_LAST.bat but didnot get success.

KILL_FIRST.bat

@echo off
REM **** KILL_FIRST.BAT ****
set TASKNAME=java.exe
SETLOCAL ENABLEDELAYEDEXPANSION

echo Task LIST before KILL...

set TASKTOTAL=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKTOTAL=!TASKTOTAL!+1
echo [Task !TASKTOTAL! is "%%A %%B"]
)
echo [Task %TASKTOTAL% is last]
echo IF START
if %TASKTOTAL%==0 goto :eof
set TASKCOUNT=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKCOUNT=!TASKCOUNT!+1
if !TASKCOUNT!==1 taskkill.exe /F /PID %%B
)
echo Task list after KILL...
set TASKTOTAL=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKTOTAL=!TASKTOTAL!+1
echo [Task !TASKTOTAL! is "%%A %%B"]
)
echo LOOP-3 END
echo [Task %TASKTOTAL% is last]



KILL_LAST.bat



@echo off
REM **** KILL_LAST.BAT ****
set TASKNAME=java.EXE
SETLOCAL ENABLEDELAYEDEXPANSION

echo Task list before KILL_LAST...
set TASKTOTAL=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKTOTAL=!TASKTOTAL!+1
echo [Task !TASKTOTAL! is "%%A %%B"]
)
echo [Task %TASKTOTAL% is last]

if %TASKTOTAL%==0 goto :eof
set TASKCOUNT=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKCOUNT=!TASKCOUNT!+1
if !TASKCOUNT!==!TASKTOTAL! taskkill.exe /F /PID %%B
)

echo Task list after KILL_LAST...
set TASKTOTAL=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKTOTAL=!TASKTOTAL!+1
echo [Task !TASKTOTAL! is "%%A %%B"]
)
echo [Task %TASKTOTAL% is last]


Can anyone help me on this topic pls..........?

Best Regards
AshutoshWhy did you post this long question in 2 different threads?
toshashu123, can you just ask all of your questions in one thread, instead of asking similar questions all over the place?

6163.

Solve : Type using Dos?

Answer»

can u like make ur computer TYPE some thing using a comand PROMPT?
if so can some one tell me how to make my computer press ctrl+alt+fwith DOS, not you can't, AFAIK. but with VBSCRIPT, you can USE sendkeys. Search the FORUM with "sendkeys" as the search word. you can find many examples

6164.

Solve : RAMDRIVE AND WINDOWS XP?

Answer» HELLO,

I would like to know if there is a way to set a ramdrive under windows xp using command line in a batch file.
If yes is it possible to setup DOS 6.22 on it and use it under windows XP?
could you please help me posting examples?
thank you very much.You cannot boot a DOS disk from inside Windows XP whether the disk is a RAM disk or another kind.

maybe you are THINKING of VMWare?

no it was just the point of creating a ramdrive while under winxp with a batch file
like INSTANT ram drive
perhaps using Qemu?You need to load a ramdisk driver at start up. See here

http://support.microsoft.com/kb/257405/en-us

6165.

Solve : how to Get PID.....!!?

Answer»

how can we get PID of running batch file.....? can anyone help me on this topic...? pls it's very urgent.......!! help me......!!in batch, you can use tasklist to display your batch file's PID. eg Code: [Select]tasklist /FI "IMAGENAME eq yourbatch.bat " /NH you will then need a for loop to parse out the correct fields...
you can also experiment with this vbscript snippet.
Code: [Select]strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'yourbatch.bat'")
For Each objProcess in colProcesses
Wscript.Echo objProcess.ProcessId
Next
aren't "urgent" batch questions usually homework?


Quote from: contrex on July 04, 2007, 02:20:28 AM

aren't "urgent" batch questions usually homework?
maybe he did write a sysadmin batch and tried running it, but it hangs, so he needs to find PID to kill it? for whatever reasons he needs to do that, let's just give him the benefit of the doubt.
btw, just curious, does schools nowadays teach DOS batching?Quote
btw, just curious, does schools nowadays teach DOS batching?

They certainly do. Quite a lot teach QBasic as well. They are included in the OS, no extra licences to buy, and they do enable the learning of many programming concepts.


Quote from: contrex on July 04, 2007, 02:45:37 AM
Quote
btw, just curious, does schools nowadays teach DOS batching?

They certainly do. Quite a lot teach QBasic as well. They are included in the OS, no extra licences to buy, and they do enable the learning of many programming concepts.



thanks. I usually thought most schools would start with C/C++ for teaching programming concepts, SINCE its very close to the interaction with the OS, ie memory manipulation etc..DOS/QBASIC does not teach programming concepts, IMO.Quote from: ghostdog74 on July 04, 2007, 03:14:12 AM
[DOS/QBASIC does not teach programming concepts, IMO.

That's rather snooty. Perhaps you would care to elaborate, although we would be getting a liitle OT I guess.

I wrote "many" programming concepts. (not all, by any means)

Learning to program in ***any*** language, assembler, FORTH, SMALLTALK, C, Python, APL, BCPL, batch, is going to give the student some experience in dealing with fundamental concepts of programming.

I started with BASIC in the 1980s and it certainly was a good foundation when I later went on to use Pascal, C and Fortran.

I have taught classes of students using QBasic, and many of the more apt students went on to study computer science at a higher level.

Quote
Computer Programming-Basic I

Using a programming language called Qbasic, you will learn some fundamental programming functions which can help you learn a more advanced programming language in the future. You will use flowcharts, algebraic skills, and analogical processes to create structured programs. If students have a programming apptitude, this course teaches students to program and learn a programming language.

Students may require other courses to sharpen their basic computer literacy skills before taking this course which requires advanced computer skills. This course does not teach basic computer literacy skills. You will learn how to define problems, create algorithms and pseudocode flow charts, code your programs, test and debug your programs, and document them.

The purpose of this course is to help you a build a programming foundation that you can use when learning more advanced computer programming languages.

http://www.flvs.net/students_parents/VSACourseDetail.php?CourseID=43

Dartmouth BASIC was DEVELOPED in the 1960s to ***introduce*** students to programming concepts.

Of course, QBasic is more or less a "toy" language compared to more advanced languages such as C, C++ etc, but (I hope you will forgive me for saying this) I am afraid your comment reveals more about your pride and vanity than it does about your knowledge.
Quote from: contrex on July 04, 2007, 03:26:07 AM
That's rather snooty. Perhaps you would care to elaborate, although we would be getting a liitle OT I guess.
my little "IMO" thing sure INCURRED your "wrath" didn't it. You may be right, DOS/QBASIC does provide you basic concepts, but that's just it. Programming concepts entails alot more of other stuffs, such as OO, bits/bytes manipulation, data types eg int,float, longs, interfacing with the OS/hardware, complex maths , memory management/manipulations, algorithms, spaghetti codes, etc you name it. DOS/QBASIC just doesn't make it in some of these areas.
Like I already said, its just IMO. So no need to get agitated. Before getting real OT, i will stop here. i'v run 2 java file so that TASKLIST option is showing two image Name (java.exe) and different PID (like as 2460 & 3789) now suppose if i want to do stop one (java.exe) whose PID is 2460. then how could i recognized that i'v closed java.exe file of a particulare PID (2460)......?

pls let me know
help me


Best Regards
AshutoshQuote from: toshashu123 on July 04, 2007, 04:17:49 AM
i'v run 2 java file so that TASKLIST option is showing two image Name (java.exe) and different PID (like as 2460 & 3789) now suppose if i want to do stop one (java.exe) whose PID is 2460. then how could i recognized that i'v closed java.exe file of a particulare PID (2460)......?

Run tasklist again, and check that PID 2460 is gone

if the java.exe running and u type TASKLIST again and again then it shows same PID for that particular image name
it doesnt change. It does only change in case of another java.exe file is runDear All Members,

i'm running batch file(start.bat) which run my java aaplication and this batch file stored at C:\ABC\XYZ\start.bat with PID like as 1792 and another batch file with same name run from this location C:\CMD\MNC\start.bat with PID like as 8967 and another batch file with same name run from this location C:\JKL\GHI\start.bat with PID like as 4356 now i make another batch file (kill.bat) and stored at each location. Now i run kill.bat from ( C:\CMD\MNC\kill.bat ) this location.

my question is this that how could i found the PID of start.bat which is run from this location (C:\CMD\MNC\start.bat) and kill this process by KILL.bat file.....?


If anybody help me. please revert back to me. I'v been tried two file that is KILL_FIRST.bat and KILL_LAST.bat but didnot get success.

KILL_FIRST.bat

@echo off
REM **** KILL_FIRST.BAT ****
set TASKNAME=java.exe
SETLOCAL ENABLEDELAYEDEXPANSION

echo Task list before KILL...

set TASKTOTAL=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKTOTAL=!TASKTOTAL!+1
echo [Task !TASKTOTAL! is "%%A %%B"]
)
echo [Task %TASKTOTAL% is last]
echo IF START
if %TASKTOTAL%==0 goto :eof
set TASKCOUNT=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKCOUNT=!TASKCOUNT!+1
if !TASKCOUNT!==1 taskkill.exe /F /PID %%B
)
echo Task list after KILL...
set TASKTOTAL=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKTOTAL=!TASKTOTAL!+1
echo [Task !TASKTOTAL! is "%%A %%B"]
)
echo LOOP-3 END
echo [Task %TASKTOTAL% is last]



KILL_LAST.bat



@echo off
REM **** KILL_LAST.BAT ****
set TASKNAME=java.EXE
SETLOCAL ENABLEDELAYEDEXPANSION

echo Task list before KILL_LAST...
set TASKTOTAL=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKTOTAL=!TASKTOTAL!+1
echo [Task !TASKTOTAL! is "%%A %%B"]
)
echo [Task %TASKTOTAL% is last]

if %TASKTOTAL%==0 goto :eof
set TASKCOUNT=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKCOUNT=!TASKCOUNT!+1
if !TASKCOUNT!==!TASKTOTAL! taskkill.exe /F /PID %%B
)

echo Task list after KILL_LAST...
set TASKTOTAL=0
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do (
set /A TASKTOTAL=!TASKTOTAL!+1
echo [Task !TASKTOTAL! is "%%A %%B"]
)
echo [Task %TASKTOTAL% is last]


Can anyone help me on this topic pls..........?

Best Regards
AshutoshOK, this is the third place you've asked that question. Stop now.This might be a waste of time, but if it rids us of the nuisance it will be worth while...

Quote
my question is this that how could i found the PID of start.bat which is run from this location (C:\CMD\MNC\start.bat) and kill this process by KILL.bat file.....?

Here are DETAILED INSTRUCTIONS. Use the knowledge gained to write batch file or perform task from command line.

1. Plant an unique identifier into each start.bat. Add a line to each start.bat such as

title "identifier999"

(or some other title meaningful to you)

2. Now you can filter Tasklist output by window title
3. Use /v switch to get verbose output which includes window titles.
4. Use /NH switch to hide header lines.
5. Use /FI switch to apply filter "WINDOWTITLE eq indentifier999"
6. It is now a trivial task to extract the PID (it is the second token using space as delimiter)
7. Now use taskkill /PID NNNN to remove the task.

Example...

c:\&GT;tasklist /v /NH /FI "WINDOWTITLE eq identifier999"

cmd.exe 3916 Console 0 2,396 K Running PUPP-C92F25ED23\Mike 0:00:00 identifier999

Here PID is 3916

start1.bat
@echo off
title START_ONE
pause

start2.bat
@echo off
title START_TWO
pause

kill_start1.bat
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "windowtitle eq START_ONE"') do taskkill.exe /PID %%B

kill_start2.bat
for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "windowtitle eq START_TWO"') do taskkill.exe /PID %%B
6166.

Solve : Help setting a variable in a Batch that is copied to a text file?

Answer»

Hello,

I need to set a variable in a batch file that is then copied into a text file. I know how to set and use VARIABLES within a batch but don’t know how to pass the variable to the text file. Any help would be appreciated. Thanks
Quote from: lostdude on May 10, 2007, 03:27:36 PM

Hello,

I need to set a variable in a batch file that is then copied into a text file. I know how to set and use variables within a batch but don’t know how to pass the variable to the text file. Any help would be appreciated. Thanks


1.) Can you show us some of your code, so we can get a feel for what you
are trying to do?


2.) In the meantime, what happens if you do something like this in your
batch file? :
ECHO %variable_name_here% > filename.txt

or

echo %variable_name_here% >> filename.txt



Is this a homework assignment? And what operating system are you using?Not A homework assignment I just would like some help. Let give more details.
Hardware and operating system:
AMD Opteron 848 server running Windows Server 2003 SP1.
I need to set a variable in the batch so the users can change them in one place each month. The essmsh COMMAND starts the Essbase interface in interactive mode. The variables I'm trying to set need to update in CopySPS.txt prior to the essmsh line running. In CopySPS.txt they are set again so that Essbase can save them as user defined variables which are then used in calculation scripts.


***************BATCH SCRIPT**************************************
Set clearscen = Actual\\Forecast_2007
Set ClearStart = May

essmsh E:\Hyperion\HypData\EssAdmin\SPS\CopySPS.txt
*****************************************************************

***************************COpySPS.txt******************************
/* pdate the specified variable VALUE. !!(SV_OptA_1, SV_OptA_2, SV_OptA_3, No Change)!!*/
alter database GL.GL set variable "clearscen" "Actual\\Forecast_2007";
alter database GL.GL set variable "clearstart" "May";
********************************************************************



So you want to be able to save CLEARSCEN and SLEARSTART to a file and be able to change them in the batch file?

You can save them to a file like:
Code: [Select]Set clearscen=Actual\\Forecast_2007
Set ClearStart=May

echo %clearscen% > E:\clearscen
echo %ClearStart% > E:\ClearStart
You read them in like:
Code: [Select]set /p clearscen=<E:\clearscen
set /p ClearStart=<E:\ClearStart

echo clearscen=%clearscen%
echo ClearStart=%ClearStart%
Obviously, you don't want the static SET in your batch file if you are reading the variables from a file, you just need something to set them with the first time. Is that what you were looking for?
Hey GuruGary,

Correct I need to be able to set and change variable in the batch script and have variable change in the text file. The text file actually contains the instructions that Essbase will use. So in sequence of events it should be the following.
1 Set variable in batch and save batch
2 Kick of batch
3 Batch sends variable to a specific place in the text file
4 Batch calls text file using essmsh command which reads text file with Essbase command containing changed statement.
5 Essbase executes instructions in text file
ThanksQuote from: lostdude on May 11, 2007, 12:10:09 PM
1 Set variable in batch and save batch
Set what variable, and where do you get the information on what the variable is, and what the value is? And what do you mean "save batch"? The batch file should be static. Please explain.
6167.

Solve : How can i Enable or Disable my Lan Card vise versa in using DOS commands??

Answer»

How can i Enable or Disable my Lan Card vise versa in using DOS commands?

i have seen the DOS command Enable, but i dont know if its the right command for the job. and i dont know how to use the Enable command.What OS are you running? If Windows XP, try:
Code: [Select]NETSH interface set interface "Local Area CONNECTION" DISABLEDyup, im using XP
there is an error on the command
netsh interface set interface "Local Area Connection" DISABLED

One or more essential parameters not specified
The syntax supplied for this command is not valid. Check HELP for the correct sy
ntax.

Usage set interface [name = ] IfName
[ [admin = ] ENABLED|DISABLED
[connect = ] CONNECTED|DISCONNECTED
[newname = ] NewName ]

Sets interface parameters.

IfName - the name of the interface
admin - whether the interface should be enabled (non-LAN only).
connect - whether to connect the interface (non-LAN only).
newname - NEW name for the interface (LAN only).

Notes:
- At least one option other than the name must be specified.
- If connect = CONNECTED is specified, then the interface
is automatically enabled even if the admin = DISABLED
option is specified.
From a command prompt...ipconfig /release.

To turn back on ...ipconfig /renew.

p.s. It's not DOS in XP...it does not work

C:\>ipconfig /release
Windows IP Configuration
The operation failed as no adapter is in the state permissible for this operation.
C:\>ipconfig /renew
Windows IP Configuration
The operation failed as no adapter is in the state permissible for this operation.

by the way im using the admin account

i have tried
netsh interface set interface "Local Area Connection" connect = DISCONNECTED
but the error is
connect=DISABLE is not acceptable value for admin.
the PARAMETER is incorrect.

6168.

Solve : Logging user/computer information with batch file?

Answer»

I've created a script that will perform a certain action, but I need to know who is using the script. Is there a way to log PC and USER information in a log using a batch FILE? Also, is there a way to make this silent? Please let me know! I've seen some things that can be used like 'net session' or whoami (available in RESOURCE kit - and 'nix flavors), but where ever I look, i can't find a way to log this information. Any help would be greately appreciate! Thanks in advance! Jeremy I forgot to mention that I'm running in Windows XP environment.

Thanks!I did some digging and found some information that I could put into the batch file.


net session \\127.0.0.1 >> mwarestart.log

ECHO --------------------- >> mwarestart.log

It worked on my PC, but when I tried it from another PC it didn't work. Reason is that i have a share setup on my system and was connected to it. Is there some other command other than 'net session' that I can use to get the user ID of who is running my batch file?I assume the other users that may be accessing the file are running Windows XP also? If so, try adding this as your "log":
Code: [SELECT]echo %0 is being run by user "%username%" on computer "%computername%" >> \\computer\share\mwarestart.logHOLY USERNAME LOGGING BATMAN! WORKS like a charm! Thanks so much! Glad it works. You're welcome.

6169.

Solve : Make batch files run invisible?

Answer»

how do you make a batch file that after it opens it will carry out the commands invisibly?
Thank youBest way that I've seen is to create a shortcut to the batch file and have the shortcut run MINIMIZED. It will open a command window, but it will run minimized in the task bar. If it runs quickly, it's practically invisible.Do you want to hide the output of the batch file, or hide the whole window? Most commands allow you to redirect the output using the greater than SYMBOL "&GT;". If your batch file is small enough just redirect everything to NUL. Otherwise you COULD call your batch file with another batch file redirecting the output to NUL.

Example 1: You have a batch file called script.bat. Let's say script.bat runs the IPCONFIG command but you want to hide the output. You could change the IPCONFIG line to:
Code: [Select]ipconfig >NUL
Example 2: You have a batch file called script.bat (same as the example above). But if you don't want to edit script.bat or if it is really long and you don't want to redirect each line to NUL, then create a new batch file called invis.bat (or whatever you want to call it) that contains:
Code: [Select]@echo off
call script.bat >NULI can SEE this sort of informating getting into the wrong hands...Quote from: CBMatt on May 10, 2007, 08:11:51 PM

I can see this sort of informating getting into the wrong hands...
Same...this information can be used for.....odd purposes...Thank you
6170.

Solve : batch file as backup: delete oldest file(s)??

Answer»

Hi, and thanks in advance for reading.

I frequently use batch files for backing up important files, etc. Scheduling is done through Windows "Scheduled Tasks" applet. For example, "xcopy c:\stuff\* \\pc2\c$\backup\"... Simple xcopy stuff.

What I would like to do is to be able to keep a week's worth of revisions of a given file, with the batch commands simply killing off the oldest copy and adding the newest copy. The object is to have, at any given time, the five most recent versions of the file in backup.

Since I'm not really a programmer, just a simple batch file guy, I don't know how to do this. Any ideas? The simpler (more reliable), the BETTER!

Thanks in advance!The oldest filename can be grabbed like this :
Code: [Select]SET FileName=
> $temp$ Dir /b /od "path"
Set /P FileName=<$temp$
Del $temp$

This does a directory listing of the directory identified above as path - into a file, sorted in order of date (oldest first). The set statement takes the first line from the file and places it into the variable (the oldest file)

Good luck
Graham
To make sure I understand, you are looking for code that will keep 5 backup copies of C:\Stuff? So basically what you want is C:\Stuff to be backed up to:
\\pc2\C$\Backup\Stuff1
\\pc2\C$\Backup\Stuff2
\\pc2\C$\Backup\Stuff3
\\pc2\C$\Backup\Stuff4
\\pc2\C$\Backup\Stuff5
and then on day 6, the Stuff 5 gets DELETED, and everything gets bumped up a number?
Graham - Thanks a lot, I will try this.

Gary - Yep, that's the idea. The c:\stuff folder contains .bak files that get written every night. I'd like to keep the five most recent .bak files in the backup folder, with the oldest effectively being replaced by the newest every night. This is probably simplified by the fact that I'm not dealing with a messy folder filled with files and sub-folders, etc.

In the backup folder, at any given time, I'll have five and only five files - just the five most recent backups. On day six, and every day thereafter, the oldest gets canned and the newest gets written.

Thanks, guys!I think this is what you want:
Code: [Select]@echo off
setlocal
set NumBackups=5

if exist C:\Backup\Stuff%NumBackups% RD C:\Backup\Stuff%NumBackups% /q /s
for /l %%a in (%NumBackups%,-1,2) do call :BumpDir %%a
xcopy C:\Stuff C:\Backup\Stuff1\ /e /h /k /c
goto :EOF

:BumpDir
set /a Prev=%1-1
if exist C:\Backup\Stuff%Prev% ren C:\Backup\Stuff%Prev% Stuff%1
goto:EOF

6171.

Solve : How to wait in a batch file for ending of some event??

Answer»

So I write a batch file, which has a task to stop a Tomcat server and to start it again.
I use CALL command. For example:

CALL .\shutdown.bat
CALL .\Startup.bat

The PROBLEM is that it takes time to stop the server and it tries to start it again before it actually
stops.

Do you have any IDEA, how can i wait for the server to stop before to try starting it again?Assuming you are running under Windows 2000 / XP / 2003 / Vista, try this:
Code: [Select]start /wait .\shutdown.bat
CALL .\Startup.batThank you for your suggestion But it seems that it doesn't work, because the shutdown script terminates IMMEDIATELY and leaves the work to the proper program.

Yes, I am with Windows NT please post contents of startup.bat and shutdown.bat
ping 127.0.0.1 -n 60

Use this for a 60 second delay. It WORKS, but it sloppy. You'll see 'Reply from 127.0.0.1.......'

6172.

Solve : Help a poor noob please?

Answer»

I would like to know if it is possible using cmd to open a MESSAGE only if ANOTHER program is RUNNING
something along the lines of
IF cmd.exe open echo Hellotasklist | FIND "cmd.exe" && echo cmd.exe is running

6173.

Solve : FOR command help needed?

Answer»

Hi there

I am attempting to incorporate a FOR command into a batch file to run Altova command line stuff. MapForce to create XML files and AltovaXML to VALIDATE the newly created XML files.

I've hit a wall and this is what i have so far, and it's running the MapForce part, but returning an error on the AltovaXML part.

===================================================================
@echo off
CLS
SETLOCAL
SET MFD=C:\MDL\MFD_Mapping_Working
SET XML=C:\MDL\XML_Output_Working
SET MapForce="C:\Program Files\Altova\MapForce2007\MapForce.exe"
SET AltovaXML="C:\Program Files\Altova\AltovaXML2007\AltovaXML.exe"

CD %MFD%

FOR %%A in (*.mfd) do (
%MapForce% %%A /BUILTIN %XML%\%%A /LOG %XML%\%%A\%%A.log
%AltovaXML% /VALIDATE %XML%\%%A\%%A.xml
)
)
ENDLOCAL
pause
CLS
===================================================================

In the %MFD% folder I have a bunch of MFD files all named differently, I'll use the following, Charges_Mobile_NRC.mfd

A folder is created in the %XML% with the same name of the file, one folder for each file,
Charges_Mobile_NRC.mfd

So far so good. MapForce runs and creates 2 files in the above folder called,
Charges_Mobile_NRC.mfd.log
Charges_Mobile_NRC.xml

This is now where I am having problems.
Problem 1: I get an error from AltovaXML that says,

Error: C:\MDL\XML_Output_Working\Charges_Mobile_NRC.mfd\Charges_Mobile_NRC.mfd.x
ml was not found.

I can't find a way to strip the .mfd from the variable for the AltovaXML section

Problem 2:
MapForce can take from 5 seconds to 3-4 minutes to create the xml files. How can I make the above code check and wait until the xml file is created without setting a fixed time delay for all files (I don't see the need to wait something like 10 minutes if the xml file is there in 10 seconds).

Currently it takes about 8-10 hours to run though all of the mdf files and create xml from them, so validating along the way is the ideal solution instead of having to wait 8-10 hours to see if it validates ok.

I know there's a lot to read, but you people like a challenge don't you.

Thanks in advance.Code: [Select]
In XP, substitution of FOR variable references has been improved

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only <------------------------------------------------
%~xI - expands %I to a file extension only
%~SI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file


in other words if %%a is a filename plus dot plus extension, %%~na is just the filename, dot and extension removed.

So try this...

change this line

%AltovaXML% /VALIDATE %XML%\%%A\%%A.xml

to this

%AltovaXML% /VALIDATE %XML%\%%A\%%~nA.xml

It worked in a trial batch I just ran.

Quote

Problem 2:
MapForce can take from 5 seconds to 3-4 minutes to create the xml files. How can I make the above code check and wait until the xml file is created without setting a fixed time delay for all files (I don't see the need to wait something like 10 minutes if the xml file is there in 10 seconds).

to see if any particular file is in use by another program, you can use handle.exe, part of the XP Reskit, free from Microsoft at

http://www.microsoft.com/technet/sysinternals/SystemInformation/Handle.mspx

Download it and put in somewhere on your PATH

eg to see if afilename.zzz is in use

handle | findstr /i "afilename.zzz"> nul && echo is in use

So you could do this

:wait
handle | findstr /i "%XML%\%%A\%%~A.xml" && goto wait

%AltovaXML% /VALIDATE %XML%\%%A\%%~A.xml

A lot depends if MapForce creates the xml file STRAIGHT away, and releases it when it has finished, or if it just writes it out at the end of its processing...


6174.

Solve : Run two programs under DOS?

Answer»

How to run two program at the same time under dos.
Let say i have device A and device B,
i'm USING utility under dos to fire them, two different utility.
Is that posible, I can fire both of them at same time?in a batch file

Code: [Select]START "" "program 1.exe"
start "" "program 2.exe"


ok...thanks

6175.

Solve : If no Data Found in Drive Rename a Certain Folder with a Time-Stamp-Date?

Answer»

Is there a way in "XP's DOS-CMD-BATCH" to check a specific removable storage drive for data in it, and if it doesn't find anything or detect the drive as being active have it then proceed to RENAME a specified folder with a time-stamp-date...

I found this site for time-stamping a folder in MS-DOS:
http://talk.bmc.com/blogs/blog-gentle/anne-gentle/dos-timestamp-tips



This is my "BATCH SCRIPT APP" I'm making..
-------------------------------------------------------------------------

:UP


tasklist | find /i "R-copy-1.exe" && goto SKIP-1
start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-1.exe E: C:\0\E\1 /XX /mir /r:0"
Check E: for data, if no data found then goto TIME-STAMP
:TIME-STAMP
set hh=%time:~0,2%
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set yymmdd_hhmmss=%date:~12,2%%date:~4,2%%date:~7,2%_%hh%%time:~3,2%%time:~6,2%
REN C:\0\E\1 %yymmdd_hhmmss%
:SKIP-1



tasklist | find /i "R-copy-2.exe" && goto SKIP-2
start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-2.exe F: C:\0\F\1 /XX /mir /r:0"
Check F: for data, if no data found then goto TIME-STAMP
:TIME-STAMP
set hh=%time:~0,2%
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set yymmdd_hhmmss=%date:~12,2%%date:~4,2%%date:~7,2%_%hh%%time:~3,2%%time:~6,2%
REN C:\0\F\1 %yymmdd_hhmmss%
:SKIP-2



tasklist | find /i "R-copy-3.exe" && goto SKIP-3
start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-3.exe G: C:\0\G\1 /XX /mir /r:0"
Check G: for data, if no data found then goto TIME-STAMP
:TIME-STAMP
set hh=%time:~0,2%
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set yymmdd_hhmmss=%date:~12,2%%date:~4,2%%date:~7,2%_%hh%%time:~3,2%%time:~6,2%
REN C:\0\G\1 %yymmdd_hhmmss%
:SKIP-3


cls
GOTO UP

------------------------------------------------------------------

BASICALLY it runs in a constant infinite loop checking for Removable Storage Devices that are plugged into my PC.
then once it detects a "RSD" it procedes to copy its entire contents onto my HDD in a specified folder
using the assistance of the ROBOCOPY.exe FILE--> http://www.ss64.com/nt/robocopy.html

so after the "RS-Device" is unplugged from my PC, I want my "BATCH SCRIPT APP" to check that drive it just copied the files from, to see if the "RS-Device" is still plugged in, and if its not plugged in then it can proceed to rename the folder with the copied files with a time-stamp-date..

IS this possible at all to do what im asking here..??
or am I SOL...

6176.

Solve : Batch file help.. rename file Windows 2003 Server?

Answer»

Hello Group!

I'm trying to CREATE a batch file that will rename a file extension...

The FILENAME is al012007.dat.tmp5

I would like to rename it to al012007.dat

I've tried:
rename *.tmp5 *.dat, but that makes the file al012007.dat.dat

I've ALSO tried:
rename *.tmp5 *
but nothing happens at all. The above command does work when I try it on Windows XP, but not Window 2003 server.

Thanks for any suggestions...
BryanDo you just want to rename 1 file, or all files that are .dat.tmp5?

For 1 file, just use
Code: [Select]ren al012007.dat.tmp5 al012007.dat... but you probably already knew that.

To rename *.dat.tmp5 you can use
Code: [Select]@echo off
for %%a in (*.dat.tmp5) do echo ren "%%a" "%%~NA"

6177.

Solve : Opening specific webpage??

Answer»

Well, I've tried out the LINK that CBMatt PUT up, and it OPENS the email, but is there anyway for it to send (and furthurmore, to attach files)?My favorite tool for SENDING email over command LINE is Blat
http://www.blat.net/

6178.

Solve : Prevent to delete file.?

Answer»

Hi Everybody!!

Is there a way to set the file properties/ATTRIBUTE or anything else so it will be locked by window or it can't be deleted.

Thanks,
Jayattrib "filename" +R will make it read-only but Windows Explorer will still be able to delete it.

In XP Windows Explorer, as Administrator, right-click the file and choose "properties" and then the "security" tab and deny all permissions. Now nobody can do anything with it until you alter the permissions.

Code: [Select]I:\test\delfile&GT;dir
Volume in drive I is Various
Volume Serial Number is 4040-A645

Directory of I:\test\delfile

09/05/2007 17:31 <DIR> ..
09/05/2007 17:31 <DIR> .
09/05/2007 17:31 14 hello.txt
1 File(s) 14 bytes
2 Dir(s) 32,720,904,192 bytes free

I:\test\delfile>attrib +R hello.txt

I:\test\delfile>del hello.txt
I:\test\delfile\hello.txt
ACCESS is denied.

I:\test\delfile>

Code: [Select]I:\test\delfile>attrib /?
Displays or changes file attributes.

ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [drive:][path][filename]
[/S [/D]]

+ Sets an attribute.
- Clears an attribute.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
[drive:][path][filename]
Specifies a file or files for attrib to process.
/S Processes matching files in the current FOLDER
and all SUBFOLDERS.
/D Processes folders as well.


I:\test\delfile>


If you are running an NTFS partition, you can set the Access Control (like choosing the security tab) by using the subinacl command. This command is part of the Windows Resorce Kit, or you can download from Microsoft at http://www.microsoft.com/downloads/details.aspx?FamilyId=E8BA3E56-D8FE-4A91-93CF-ED6985E3927B&displaylang=en

If you don't need permissions this strong, then the attrib command is perfect as suggested by contrex.

Post back if you need an example of subinacl.

6179.

Solve : delete index.dat?

Answer»

Hi Everybody!!

There is many of the third party software available through goole search but I would like KNOW, can i delete index.dat (storage of visited URL in binary) manually by dos.

THANKS,
JayYou can use the del command.
Code: [Select]del "C:\path\to\file\index.dat"Quote from: Carbon Dudeoxide on May 07, 2007, 02:39:26 AM

You can use the del command.

No, It's not work for index.dat

Thanks,
JayWhat about with the /f switch?

Code: [Select]del "C:\path\to\file\index.dat" /fIf we will try to delete this one, we always get MESSAGE bcz its all time get accessing by window/Explorer.

The process cannot ACCESS the file because it is being used by another process.

RD even not work if it in folder.

Thanks,
Jaywhere is this file? It could be a core file for a program.Without using third party software, how about making a batch file with the code
Code: [Select]del C:\Documents and Settings\%username%\Cookies\index.dat
del C:\Documents and Settings\%username%\Local Settings\History\History.IE5\index.dat
del C:\Documents and Settings\%username%\Local Settings\History\History.IE5\MSHistXXXXXXXXXXX\index.dat
del C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\Content.IE5\index.dat
del C:\Documents and Settings\%username%\UserData\index.datand make this batch file run on startup?
This will work for WINDOWS 2000 and XP, I'm fairly sure that's all the locations of index.dat files. If I missed any, add them in.

Edit: Carbon, index.dat is your history. It is always in use by Windows Explorer and other programs. It can only be deleted on startup.Quote from: Carbon Dudeoxide on May 07, 2007, 03:33:25 AM
where is this file? It could be a core file for a program.

C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\Content.IE5 \index.dat
Quote from: Calum on May 07, 2007, 03:36:23 AM

Code: [Select]del C:\Documents and Settings\%username%\Cookies\index.dat
del C:\Documents and Settings\%username%\Local Settings\History\History.IE5\index.dat
del C:\Documents and Settings\%username%\Local Settings\History\History.IE5\MSHistXXXXXXXXXXX\index.dat
del C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\Content.IE5\index.dat
del C:\Documents and Settings\%username%\UserData\index.dat

It's not work with start up . Not deleted.
Unable to delete even in safe mode.I wasn't sure if it'd work, that was the best I could do.
Why not just use something like CCleaner?A batch file can delete index.dat on startup, but it will always be recreated by windows. You have to check the content of the file to see if it was actually deleted. In most instances, a newly created file will be 32K. Anything larger probably has content. It can be opened in Notepad, which is a rather crude display, but is adequate to view the contents to see if anything is actually there. You cannot totally eliminate index.dat.Quote from: 2k_dummy on May 07, 2007, 06:07:26 AM
A batch file can delete index.dat on startup, but it will always be recreated by windows. You have to check the content of the file to see if it was actually deleted. In most instances, a newly created file will be 32K. Anything larger probably has content. It can be opened in Notepad, which is a rather crude display, but is adequate to view the contents to see if anything is actually there. You cannot totally eliminate index.dat.
I did try, size is same after trying to delete through startup.It is a system file that cannot be deleted as referred to by 2KD....

What is it you are trying to accomplish ? ?Hi, There is a way to delete this file by creating new user profile, I am wondering if any way from dos.

Like this file, could i set properties so it can't be deleted.

Thanks,
JayQuote from: patio on May 07, 2007, 03:31:58 PM
It is a system file that cannot be deleted as referred to by 2KD....

What is it you are trying to accomplish ? ?
6180.

Solve : Run a .bat from VBA?

Answer»

Hi there,

I am trying to run a very simple batch file from VBA.
Here is the cotents of the batch file:

dir c:\ > try.txt

When I run the batch file by itself, the text file is created.

Then I want to launch it from VBA using the following command:

Shell("C:\Documents and Settings\Administrateur\try.bat", vbNormalFocus)

A MS-DOS window opens but the text file is not created.

Could you please help me with this simple task?

Thanks in advance,

Benny.
How about this?

(Also - are you looking in the right folder for the text file?)

Code: [Select] Dim ret As Integer
ret = Shell "C:\Documents and Settings\Administrateur\try.bat"

If you want to wait for your batch to complete before continuing, make sure it includes and END or EXIT and use this:

Code: [Select] Dim ret As Integer
ret = CALL Shell "C:\Documents and Settings\Administrateur\try.bat"

Hi,

Thx for your prompt reply,
unfortunatly, it's STILL not working.
when I run the batch file alone, the text file is created in C:\Documents and Settings\Administrateur folder, I expect to get it in the same folder when I run from vba.
The command "Call" is not recognized by my VBA (running with Excel).

Any suggestions? Thanks a LOT for your help.
This seems to be a way of running a batch on workbook open. MAYBE you could adapt it...

Implement this code in Workbook_Open. The /c closes the DOS prompt when finished.

Code: [Select]
Private Sub Workbook_Open()

Call Shell(Environ$("COMSPEC") & " /c C:\Path.bat", vbNormalFocus)

End Sub

or this...

Code: [Select]Put THIS code in the ThisWorkBook:

Sub TEST()

Shell32Bit "C:\test.bat", "WAIT"

End Sub

see here

http://www.google.co.uk/search?source=ig&hl=en&q=run+.bat+from+vba+excel&meta=
Oki the first method is working!
Thanks lot for your help!

6181.

Solve : IF command help...?

Answer»

Quote from: contrex on May 09, 2007, 10:28:25 AM

I mean, I agree that his post was titled "IF command help...", but when you read the actual question, he wanted to know how to use the CHOICE command.
...

The ORIGINAL poster asked for some help - of that we are sure.
You are reading into it. I'm just reading what was written. I don't know what was in his head, nor do I know his level of expertise. He may have meant one thing, and said another.... it happens. No big deal.

Either way, it really doesn't matter to the original poster. What MATTERS is that he got some useful help.

Then you made comments that were not on TARGET, so I replied.

There is no POINT in going on about it.


6182.

Solve : Doubt in Run As command?

Answer»

Hi all,

I want to run the “Run As” command in DOS in a manner where I give password too in a single command line along with user id and domain. Please let me know if this is possible and provide me the syntax too.

Thanks & Regards,
SANKAR.
Runas only works in NT based OS. Not MS-DOS. You cannot pass password on command line as you describe. Consider SU.exe in NT Resource Kit.

http://www.dynawell.com/support/ResKit/winnt.asp




Runas Allows a user to run specific tools and programs with different permissions than the user's current logon provides

Syntax

runas [{/profile|/noprofile}] [/env] [/netonly] [/smartcard] [/showtrustlevels] [/trustlevel] /user:UserAccountName program

Parameters

/profile : Loads the user's profile. /profile is the default.

/no profile : Specifies that the user's profile is not to be loaded. This allows the application to load more quickly, but it can also cause a malfunction in some applications.

/env : Specifies that the current network environment be used instead of the user's local environment.

/netonly : Indicates that the user information specified is for remote access only.

/smartcard : Indicates whether the credentials are to be supplied from a smartcard.

/showtrustlevels : Lists the /trustlevel options.

/trustlevel : Specifies the level of authorization at which the application is to run. Use /showtrustlevels to SEE the trust levels available.

/user:UserAccountName : Specifies the name of the user account under which to run the program. The user account format should be [emailprotected] or Domain\User.

program : Specifies the program or command to run using the account specified in /user.

/? : Displays help at the command prompt.

Examples

To start an instance of the command prompt as an administrator on the local computer, type:

runas /user:localmachinename\administrator cmd

When prompted, type the administrator password.

To start an instance of the Computer Management snap-in using a domain administrator account called companydomain\domainadmin, type:

runas /user:companydomain\domainadmin "mmc %windir%\system32\compmgmt.msc"

When prompted, type the account password.

To start an instance of Notepad using a domain administrator account called user in a domain called domain.microsoft.com, type:

runas /user:[emailprotected] "notepad my_file.txt"

When prompted, type the account password.

To start an instance of a command prompt window, saved MMC console, Control Panel item, or program that will administer a server in another forest, type:

runas /netonly /user:domain\username "command"

domain\username must be a user with sufficient permissions to administer the server. When prompted, type the account password.

------------------------------------------------------------------------------

Runas REPLACEMENT

RUNAS in Windows 2000 is nice, but not very script friendly. Unlike SU from the NT Resource Kit, you can't pass a password. Here is an alternative.


You can use the following script to execute a command via RUNAS. You might find this helpful for yourself, or run it from a batch file (although the password will be in clear text). Another alternative is to hardcode the command, username and password in the script, then use the Script Encoder (download from http://msdn.microsoft.com/scripting) to encode it. You run the script the same way, the file will just have a different extension: cscript vbrunas.vbe. Then if you have repeatable admin tasks you or your users, just execute the script.

Code: [Select]'Start of Script
'VBRUNAS.VBS
'v1.2 March 2001
'Jeffery Hicks
'[emailprotected] http://www.quilogy.com
'USAGE: cscript|wscript VBRUNAS.VBS Username Password Command
'DESC: A RUNAS replacement to take password at a command prompt.
'NOTES: This is meant to be used for local access. If you want to run a command
'across the network as another user, you must add the /NETONLY switch to the RUNAS
'command.

' *********************************************************************************
' * THIS PROGRAM IS OFFERED AS IS AND MAY BE FREELY MODIFIED OR ALTERED AS *
' * NECESSARY TO MEET YOUR NEEDS. THE AUTHOR MAKES NO GUARANTEES OR WARRANTIES, *
' * EXPRESS, IMPLIED OR OF ANY OTHER KIND TO THIS CODE OR ANY USER MODIFICATIONS. *
' * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A SECURED LAB *
' * ENVIRONMENT. USE AT YOUR OWN RISK. *
' *********************************************************************************

On Error Resume Next
dim WshShell,oArgs,FSO

set oArgs=wscript.Arguments

if InStr(oArgs(0),"?")<>0 then
wscript.echo VBCRLF & "? HELP ?" & VBCRLF
Usage
end if

if oArgs.Count <3 then
wscript.echo VBCRLF & "! Usage Error !" & VBCRLF
Usage
end if

sUser=oArgs(0)
sPass=oArgs(1)&VBCRLF
sCmd=oArgs(2)

set WshShell = CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
WinPath = WshEnv("SystemRoot")&"\System32\runas.exe"
set FSO = CreateObject("Scripting.FileSystemObject")

if FSO.FileExists(winpath) then
'wscript.echo winpath & " " & "verified"
else
wscript.echo "!! ERROR !!" & VBCRLF & "Can't find or verify " & winpath &"." & VBCRLF & "You must be running Windows 2000 for this script to work."
set WshShell=Nothing
set WshEnv=Nothing
set oArgs=Nothing
set FSO=Nothing
wscript.quit
end if

rc=WshShell.Run("runas /user:" & sUser & " " & CHR(34) & sCmd & CHR(34), 2, FALSE)
Wscript.Sleep 30 'need to give time for window to open.
WshShell.AppActivate(WinPath) 'make sure we grab the right window to send password to
WshShell.SendKeys sPass 'send the password to the waiting window.

set WshShell=Nothing
set oArgs=Nothing
set WshEnv=Nothing
set FSO=Nothing

wscript.quit

'************************
'* Usage Subroutine *
'************************
Sub Usage()
On Error Resume Next
msg="Usage: cscript|wscript vbrunas.vbs Username Password Command" & VBCRLF & VBCRLF & "You should use the full path where necessary and put long file names or commands" & VBCRLF & "with parameters in quotes" & VBCRLF & VBCRLF &"For example:" & VBCRLF &" cscript vbrunas.vbs quilogy\jhicks luckydog e:\scripts\admin.vbs" & VBCRLF & VBCRLF &" cscript vbrunas.vbs quilogy\jhicks luckydog " & CHR(34) &"e:\program files\scripts\admin.vbs 1stParameter 2ndParameter" & CHR(34)& VBCRLF & VBCRLF & VBCLRF & "cscript vbrunas.vbs /?|-? will display this message."

wscript.echo msg

wscript.quit

end sub
'End of Script
Contrex gave a good answer, but to simplify, (assuming you are running under Windows 2000 / XP) the syntax would be something like:
Code: [Select]runas /user:[emailprotected] program.exeIf you need to include the password, try to echo and pipe it to the command like:
Code: [Select]echo password|runas /user:[emailprotected] program.exe

6183.

Solve : Command Prompt?

Answer»

I am new to command prompt but the F.A.Q.'s do not seem to answer my question
When command prompt OPENS it displays as

C:\Documents and Settings\Danny Gurganus Jr>

I need to type in C:MSC\EXAMPLES\cube>mvc cube.mv

I can't type this in because the whole documents and settings and my NAME and the > sign are there. How can I start from a blank line or from C: ?

Thank you.I am using windows xpType "cd C:\"
If that doesn't work type "%SystemRoot%\system32\cmd.exe" in the Explorer where C: is writtenCD = CHANGE disk
%SystemRoot%\system32\cmd.exe is the PATH of the command promptIf you always want to start in C: than you can change the properties of the command prompt from "%HOMEDRIVE%%HOMEPATH%" to C:
sorry that I'm written this in pieces but the sever is working properly and I can't post big postsYou can alsow: Start > RUN > and type "Command C:"
but than you have to exit using the "EXIT" command.Quote from: Jonas Wauters on May 08, 2007, 02:22:55 PM

CD = Change disk
%SystemRoot%\system32\cmd.exe is the path of the command prompt

No, CD = change directory

to change disk, just type the drive letter and a colon eg D:

C:\Documents and Settings\Danny Gurganus Jr> is the prompt. You don't type it.

Methinks you should study some more.
About Change directory your wright but the path were the prompt start in is changeable I use this myself sow...
I do agree that I don't know much about PC but the things I do know are true.
accept for the misunderstanding of Directory and disk but that doesn't make any difference when you work white it.
If your current directory isn't important to you, then you can just change your prompt. At your "C:\Documents and Settings\Danny Gurganus Jr>" prompt, type the follwoing:
Code: [Select]set prompt=$n:... so your screen will look like:
Code: [Select]C:\Documents and Settings\Danny Gurganus Jr>set prompt=$n:That will give you a prompt of just the drive letter (like you asked in your original post).
6184.

Solve : Run a Dos program in XP?

Answer»

I need to run an old Dos CAD program in XP
on a Intel core 2 (1.876GHz) computer
I have tried Dosbox but no success

Please helpTo get meaningful HELP, it is essential that you provide some basic information such as the CAD program name and version. Otherwise we're just guessing. (That doesn't put some people off on here, so beware!)

The Programm Iam refering to is
Genes1s Ver 5, South African developed
It has been Upgraded to a Windows vsersion that work well
I have written many lines of MACROS for the dos version
and this can not be CONVERTED to run on the Windows version

When trying to start the dos version
I get MetaWINDOW Initgrafix error
This version Runs well on Windows 98 on
older slower computers

Hope this helphave you tried asking Genes1s Concepts at [emailprotected] or [emailprotected].za ?
I Tried Genes1s, No luck, Thanks .That initgrafix error sounds like a display problem, maybe to do with old VGA colour display incompatibility. It may be your display hardware or driver giving problems.

You can try copying the .exe to the DESKTOP and then after re-boot right click the shortcut and tell it to run in MSDos compatibility mode...

I'm not on an XP machine right now to test but this feature should still be available...

6185.

Solve : Need help to automatically create folders based on existing folder names?

Answer»

Hi there.

I am attempting to use a batch file to automatically create incremented folders in a subdirectory based on the last folder name in the subfolder.

eg.
I have a folder called C:\Data and it has subfolders called v01, v02, v03, v04 etc
What I want to do look in C:\Data and create a subfolder that is +1 from the previously created folder.

Any help would be GREATLY appreciated.Something like this may work on your MACHINE:

Code: [Select]@echo off
for /l %%x in (1,1,9) do (
if not exist c:\data\nul (md c:\data\v0%%x & goto :eof)
)
for /l %%x in (10,1,10000) do (
if not exist c:\data\nul (md c:\data\v%%x & goto :eof)
)

The range of the code is 1 to 10,000. Feel free to CHANGE it.


Fantastic, thanks for that Sidewinder.

Now would you know how to incorporate the newly created folder into a SET variable so that I can then use this new folder to COPY my files into.

Currently I manually change the variable that I have each time I create a new folder. I am using -

SET Dump=C:\Data\v01 :: I then change this to v02, v03, v04 etc, you get the picture.

Once again thanks for the help.Code: [Select]@echo off
for /l %%x in (1,1,9) do (
if not exist c:\data\v0%%x\nul (
set Dump=c:\data\v0%%x
md c:\data\v0%%x
goto next
)
)
for /l %%x in (10,1,10000) do (
if not exist c:\data\v%%x\nul (
set Dump=c:\data\v%%x
md c:\data\v%%x
goto next
)
)
:next

The internal label should make it easier to incorporate the snippet into your own code.

Perfect. Does exactly what I wanted it to do.

Thanks again

6186.

Solve : Trying to create zip file for a location that is provided by a user.?

Answer»

Hello.

This is not a homework assignment, I'm just really rusty about any scripting or coding at the moment. Been a while since I've done any of it.

I'm trying to create a ZIP file based on a VARIABLE location that is PROVIDED by a user.

I've got most of it, but not sure of the syntax on how to create the files... the format for the files I wold be using are:

"Site_Name"_backupcontrolfile.zip "Site_Name"_backupcontrolfile.bak
I'm passing the variable through with a set /p site_name through to the Oracle and getting the files created, but now I'm just trying to get the files to zip.

Any suggestions?
FOUND it!

%variable%_backupcontrolfile.zip

6187.

Solve : Open a program @ night?

Answer»

Hi there,

Haven't been here in a while, been (to) busy...
ANYHOW, I've a problem with a script that I made. My OS is windows xp home.

@echo off
color 40
title BITTORRENT night downloader
>>c:/windows/torrent.bat ECHO @echo off
>>c:/windows/torrent.bat ECHO cd C:\Program Files\BitTorrent
>>c:/windows/torrent.bat ECHO "bittorrent.exe"
>>c:/windows/torrent.bat ECHO pause
:afsluiten
if exist c:/WINDOWS/afluitenpc.bat goto end
>>c:/windows/afsluitenpc.bat ECHO @echo off
>>c:/windows/afsluitenpc.bat ECHO shutdown -s
>>c:/windows/afsluitenpc.bat ECHO exit
:end
AT 00:28 c:/WINDOWS/torrent.bat
AT 05:02 c:/WINDOWS/afsluitenpc.bat
pause
exit

The problem is, (it's for downloading torrents a night), according to windows the file torrent.bat is OPENED from 00:28 till 05:02 but that file doesn't open my torrentprogramm (bittorrent.exe). However, if I open it in the windows folder, it does open the program.

Why does windows schedular doesn't open my program that should open bittorrent?
Quote

@echo off
color 40
title BitTorrent night downloader
>>c:/windows/torrent.bat ECHO @echo off
>>c:/windows/torrent.bat ECHO cd C:\Program Files\BitTorrent
>>c:/windows/torrent.bat ECHO "bittorrent.exe"
>>c:/windows/torrent.bat ECHO pause
:afsluiten
if exist c:/WINDOWS/afluitenpc.bat goto end
>>c:/windows/afsluitenpc.bat ECHO @echo off
>>c:/windows/afsluitenpc.bat ECHO shutdown -s
>>c:/windows/afsluitenpc.bat ECHO exit
:end
AT 00:28 c:/WINDOWS/torrent.bat
AT 05:02 c:/WINDOWS/afsluitenpc.bat
pause
exit

Try changing the highlighted line to: cd /d C:\Program Files\BitTorrent

Changed still don't work

If I go to scheduled task when the task should run I see under the status tab: the program could not be opened, however I'm 100% it existsWhat about QUOTES around the program path & name

cd "C:\Program Files\BitTorrent"
6188.

Solve : run program.?

Answer»

Hi everybody!!

Could i FORCE to all LOCAL NETWORK connected PC to run certain PROGRAM @ certain time simultaneously.

Thanks,
JAY

6189.

Solve : stopping loops?

Answer»

does anyone know how to stop a goto LOOP,
im trying to right a program that will run a loop that runs from 1 to 100 by user entered variable, i know how to make the variable, i just dont know how to make a loop run so many times, then stop, so if some ONE could help me out that would be greatHi goodnatureddog,

The following code will loop 10 times, and has been tested on Windows XP [Version 5.1.2600] cmd.exe :-

Code: [Select]@echo off
set COUNTER=1

:startloop
echo Counting from %COUNTER% to 10 ...
echo (Doing something...)

if %COUNTER%==10 goto stoploop
set /A COUNTER=%COUNTER%+1
goto startloop

:stoploop
echo Finished!

The following code will prompt how many times to loop :-

Code: [Select]@echo off
set COUNTER=1

set /P STOPPER=Loop how many times?

:startloop
echo Counting from %COUNTER% to %STOPPER% ...
echo (Doing something...)

if %COUNTER%==%STOPPER% goto stoploop
set /A COUNTER=%COUNTER%+1
goto startloop

:stoploop
echo Finished!

Please NOTE the prompt is NOT validated. If user INPUTS an invalid integer (or zero or negative) then the code will loop forever.

Hope that helps?

Regards,
James

Better solution to loop 10 times, tested on Windows XP [Version 5.1.2600] cmd.exe :-

Code: [Select]@echo off

for /L %%C IN (1,1,10) DO (
echo Counting from %%C to 10 ...
echo [Doing something...]
)

echo Finished!

Better solution to prompt how many times to loop :-

Code: [Select]@echo off

set /P STOPPER=Loop how many times?

for /L %%C IN (1,1,%STOPPER%) DO (
echo Counting from %%C to %STOPPER% ...
echo [Doing something...]
)

echo Finished!

Hope that helps?
James
ok now i just have two more questions,
one- what does the /a switch do and
two- i need to say if the user entered variable is GREATER the 100, to reask the amount
other wise, my loop worked
thxCode: [Select]@echo off
set COUNT=0
:redo
cls
set /p MAX=How many numbers?
if %MAX% GTR 100 goto redo
cls

Add this part. If MAX is larger than 100, it clears the screen and asks for the number again.answering the question, "what does the /a switch do?", it tells the SET command that we are doing (a)rithmetic, not dealing with text strings.


Quote

@echo off
set /a SUM=5+2
echo %sum%
pause

Here is an example of the /a switch. It calculates '5+2' and echo's the answer.
6190.

Solve : Making multiple directories from a wordlist .txt file??

Answer»

Is it possible to make multiple DIRECTORIES for each word from an alphabetical list stored in a txt file?

EXAMPLE: Take the first page of words from a dictionary and create a directory for each
word down the list.

Another poster TOLD me about using the for loop but I admit I don't really understand about that.



effectively you can use the FOR CMD,
for that i think i can help you,

it must be like that:

Code: [Select]FOR /F %%i IN list_of_word.txt DO mkdir %%i

but to create it by extracting the first word of file i don't know!
sorry !!In order to use only selected parts of a (delimited) line of text, use /F with the "tokens" and "delims" parameters -

for /F "tokens=3 delims=," %%i in (myfile.txt) do @echo %%i

echoes the third item in a comma delimited list.Code: [Select]for /F "tokens=*" %%z in (YourListHere.txt) do @mkdir %%z


Thanks guys, I got it WORKING from your help.

6191.

Solve : drive c has no label volume serial number 1d36-11eb....HELP!!!!?

Answer»

when i turn pc on it GOES to DOS screen and says:drive c has no label volume serial number 1d36-11eb. I dont KNOW how to remedy this. Any help is greatly appreciated.No remedy neccessarily needed...most drives operate fine without a volume label.
the things is , is I still cannot get windows to start. goes to COMMAND prompt... you know..black screen that shows c:\>


Quote from: 3deizzie on May 03, 2007, 07:55:27 PM

when i turn pc on it goes to DOS screen and says:drive c has no label volume serial number 1d36-11eb. I dont know how to remedy this. Any help is greatly appreciated.

Try this: 'c:' or what ever volume you know is there. then try running 'win'. Example: 'c:' 'win' or 'd:' and then 'windows'(if you have your installation on d:)
if your volume doesnt have a name, it's no deal, but if it's got no drive letter, it can get worse. try renaming the volume(if that doesnt change anything on or with the partition)

if this doesnt work, you might wanna check if a volume containing windows is installed in your system at all Problem solved elsewhere. Poster made duplicate posts in DOS and Windows sections. Poster omitted to state that computer is a freshly acquired used computer. DEALER or previous owner has removed Windows, as is the normal correct legal procedure.
AHAAA ! !

Thanx.It is nice to have all of the relevant information up front.
6192.

Solve : MS-DOS V3.3 or less?

Answer»

Dear FRIENDS,

Does any body know where to FIND the MS-DOS v3.3 files to DOWNLOAD? I need Command.com, MSDOS.SYS, IO.SYS files which are together LESS than 64KBytes!

Thanks in advance.
Partovihttp://www.google.co.uk/search?source=ig&hl=en&q=download+ms-dos+3.3&meta=Quote from: as_partovi on MAY 05, 2007, 02:04:30 AM

Dear friends,

Does any body know where to find the MS-DOS v3.3 files to download? I need Command.com, MSDOS.SYS, IO.SYS files which are together less than 64KBytes!

Thanks in advance.
Partovi

Check out:
http://oldfiles.org.uk/powerload/bootdisk.htm

Is it there?

6193.

Solve : save output from cmd.exe?

Answer»

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

-------------------------------------------
VScANnER [Demo] - Virus Removing Utility v
"Can Detect <42000> Virus
-------------------------------------------

Volume in drive C is example
Volume Serial Number is 25B4-DEE0


Start Scanning....

ERROR: The process "wscript.exe" not found.

[VB WORM v1 By YaHaa - High RISK]
---------------------------------
Could Not Find C:\autoupdate.dll.vbs
Could Not Find C:\autoupdate.dll
Could Not Find C:\setupSNK.exe
Could Not Find C:\autorun.fcb
Could Not Find C:\wsetting.wfc
Could Not Find C:\CF31180B.wfc
Could Not Find C:\wsetting.txt
Could Not Find C:\mesaggeb.txt

ERROR: The process "PET32.exe" not found.




how to save this output to C:\output.txt?



I don't know where on your SYSTEM is the Vscanner program. However, I'll guess... You must edit to make it correct...

(1)
In command window, type

"Path to Vscanner\vscanner.exe" > c:\output.txt

Possibly

"C:\program files\vscanner\vscanner.exe" > c:\output.txt


(2) If that does not work

after program has run:-

1. Start Notepad
2. In comand window click icon in top left corner of window
3. Choose Edit, MARK from menu that appears
4. In command window, move mouse cursor to start of text to be saved
5. Click left mouse button and drag to highlight all text to be saved
6. Press Enter
7. In Notepad, choose Edit, Paste from menus.
8. save FILE as desired filename.

(You must have done something similar to post the program output here)
yes. its work ,tq

erm... how to write the command to

save the output text to 1 folder but different filename .txt? (i dont want it replace the output text file)
If you don't want to replace the orignal file, but just add the text to it, use >> instead of > (but this only works if the file exists).Quote from: Dark Blade on May 05, 2007, 02:12:47 AM

If you don't want to replace the orignal file, but just add the text to it, use >> instead of > (but this only works if the file exists).

On my system >> works whether or not the file exists beforehand.

Quote from: insertusername on May 05, 2007, 02:01:14 AM
yes. its work ,tq

erm... how to write the command to

save the output text to 1 folder but different filename .txt? (i dont want it replace the output text file)


I just used output.txt as an example. You can type anything you like as a filename.
6194.

Solve : small batch program's I find and make enjoy from DeltaSpider?

Answer»

I GUESS I will keep it as is with XCOPY. From what I understood a regular copy does not allow the copying of SUBFOLDER especialy if they are empty. I do need to structure a way in which I can have the files backed up on Tuesday go to a folder called Tuesday and so on. What would be the best lay out for this?Depending on your regional settings, you can use the value of the date command:

Code: [Select]@echo off
for /f "tokens=1,2" %%x in ('date /t') do (
set dow=%%x
)
if %dow%=Mon set folder=c:\Monday
if %dow%=Tue set folder=c:\Tuesday
.
.
.

Try running the date /t command at the command PROMPT. You may not even have the day of week showing in the output which will make this all the more difficult.

Good luck. This is the output I use as the default for all machines: Thu 04/26/2007

@echo off
for /f "tokens=1,2" %%x in ('date /t') do (
set dow=%%x
)
if %dow%=Mon set folder=c:\Monday
if %dow%=Tue set folder=c:\Tuesday

I would assume that in the two 'if' lines I have to specify the direct path to the folders I have created? Will all these commands work on XP pro?Sidewindes,

I PLACED the code that you provided and got a '=Mon was unexpected at this time' message. What are the areas I must modify other than the folder paths? Is there something I missed?

6195.

Solve : running programs at start-up?

Answer»

I know how to run programs at start up using Command Prompt, but is it possible to make a program that asks the USER if they want to OPEN that program?If you have Win 95/98/ME you have choice.exe ALREADY. If not, download it from one of a zillion places and put it on your PATH somewhere.

look here for some clues...

http://www.google.com/search?source=ig&hl=en&q=download+CHOICE.EXE&meta=

Example CODE showing how to optionally launch Internet Explorer from a batch file, quitting the batch file without waiting for IE to FINISH...

Code: [Select]@echo off
cls
choice /N "Do you want to run Internet Explorer (Y/N) ?"
if errorlevel 2 goto no
if errorlevel 1 goto yes
:yes
start "" "C:\Program Files\Internet Explorer\IEXPLORE.EXE"
:no
exit



Quote from: contrex on April 27, 2007, 12:25:55 AM

If you have Win 95/98/ME you have choice.exe already. If not, download it from one of a zillion places and put it on your PATH somewhere.

look here for some clues...

http://www.google.com/search?source=ig&hl=en&q=download+CHOICE.EXE&meta=
...


And here:

http://hp.vector.co.jp/authors/VA007219/dkclonesup/choice.html


Thanks, it worked.
6196.

Solve : Printing a document using a batch file?

Answer»

I need help!!! How can I create a batch file that opens up a document in excel and prints the document to specific printer? Batch code does not generally do Windows. Using the print command on a Excel workbook/worksheet will produce gruesome results.

A batch file could open an Excel workbook but printing it would only be possible with something like AutoIt, where you could design a macro to mimic your mouse as you go about printing the document.

Generally when dealing with Windows applications, you're better off utilizing a Windows script language.


This type of Excel/batch interaction is often very USEFUL. The
general technique for working with such MSOffice FILES is:

1) Create a dummy .XLS file that simply contains an
auto-open VBA macro that IMPORTS your actual Excel file,
prints it, and quits. Suppose the dummy .XLS file is:
C:\SOMEFOLDER\PrintMyFile.XLS

2) Use a batch file with the command:
start /w C:\SOMEFOLDER\PrintMyFile.XLS
which will start up the dummy file and the VBA macro
will do the work.

This process is preferable to simply putting the
auto-open macro in the main data file. If you did that
it would execute every TIME you opened the file. Since
you'll never open the dummy .XLS file directly yourself
you won't run into this problem by working in the way I
suggest.

This technique is easily adapted to far more complex
MSOffice/batch interaction.

6197.

Solve : Running old dos datebase under windows?

Answer»

Hi
I use a datebase called FMS80 (written in 1980) It consists of about 35 programs inluding Definition editors, REPORT writer and has its own language. It all runs fine under WINDOWS exept for the following.
Under dos I use my sort program to sort AFILE.dat, the sorted output file is AFILE.dat. Under windows the output file is AFILE.0X. Can anyone tell me how to stop windows CHANGING my file names?
Any help greatly appreciated.
Regards
Acer1 DOUBLE POST

Please see responses to the other thread. Only one is needed. The forum is not THAT big. Thanks.

6198.

Solve : Hi. Need help processing files in a folder/directory?

Answer»

If I try to use for %%f in (*.txt) do(...), it doesnt seems to process all the text files in the folder, rather it repeats the same file to do the processing.

for e.g if I have 2 text files(One.txt, Two.txt) in a folder, it repeats 2 times since it received 2 text entries, but the funniest part is it ALWAYS look for either One or Two. Even I tried to rename the first file it is processing, but the program doesnt go into 2 text file. instead it stopped the whole process.

Any idea how to get rid of this problem?

Alternatly I've an idea but not sure how to code it:

Simply create a text file by re-directing the output of dir /s command to a text file:
then read the text file and process the entry one by one.

Any one can help how to read a text file line by line until EOF.

Thanks a lot for any help

Cheers/RajaI USED these PIECE of code and found bug with For loop:

for %%f in (*.txt) do (
REM get the filemname
SET var=
set var=%%f

REM echo.%var%

REM so the rename
ren %var% xxx

REM I wanted to check which file is modified, hence I paused before I proceed to next text file
pause

move xxx archived/%var%

rem reset var before go to next file
rem set var=
)

I've tested with One.txt and Two.txt, the processing is unpredictable, either it takes only One.txt or Two.txt. Scary man.

Thanks for your assistance.Code: [Select]@echo off
REM example of for loop in batch file

REM write 4 lines to a file
echo line 1 > readme.txt
echo line 2 >> readme.txt
echo line 3 >> readme.txt
echo line 4 >> readme.txt

REM read them back in a loop
for /F "delims==" %%a in (readme.txt) do (
echo %%a
)

You need to put FOR /F. It indicates to FOR that whatever is between the parentheses is the source
of a series of lines of data to be read and processed.

without the "/F", what is between the parentheses is interpreted as a
series of ITEMS.

Code: [Select]for "delims==" %%a in (Apples Pears Oranges) do (
echo %%a
)

Output...

Apples
Pears
Oranges

single-quotes within the parentheses indicates that the data lines are
sourced from the output of a command. Without the single-quotes, FOR /F
tries to read a (text-)file named (whatever is within the parentheses)

To use wild cards like *.txt use double quotes.

Sometimes I use the output of

dir /b *.txt


My example:

Code: [Select]@echo off
REM example of for loop in batch file


REM write 4 lines to a file
echo line 1 > readme.txt
echo line 2 >> readme.txt
echo line 3 >> readme.txt
echo line 4 >> readme.txt


REM read them back in a loop


REM FOR EACH ITEM FOUND BY dir /b....
for /F "delims==" %%a in ('dir /b *.txt') do (

REM OR THIS LINE DOES SAME THING
REM note double quotes
REM for /F "delims==" %%a in ("*.txt") do (


REM echo file NAME
echo %%a

REM show file CONTENTS
type %%a

)




See

FOR /?

from the prompt for more info.


Hope this helps.

I suspect that as you are iterating around all files and you are changing the files, it will get confused (ie changing the order it encounters the files)
.
Your idea of putting the filelist into a text file is a good one as it will isolate you from the effect of these changes

GrahamHi Folks.

Thanks for helping me:

Here is the piece of code that is working(to benefit to others who require such a piece of code)

REM=============================================
@echo off
REM example of for loop in batch file

REM write all *.txt into readme(in sorting order by date)
dir *.txt /W/B/OD > readme

REM read them back in a loop
for /F "delims==" %%a in (readme) do (

echo %%a
rename %%a xxx.txt
pause
REM You can call other batch to process the file then rename back to original file
rename xxx.txt %%a
)
README ================================

6199.

Solve : Delete a folder under several users profiles.?

Answer»

Hey all.

I'm in over my head here, i dont know how to do veriablaes just yet in scripts, never really had to use them MUCH untill my current job... Anyways I'm looking for a way to delete a directory that appears under several users profiles.

The directory and path structure stays the same just the user log in name will vary, and i also dont know what the user names will be on each computer i have to run this on, but being that thats is the VARIABLE that probaly WONT matter all that much.

Ex: C:\documents and setting\casey131\DeleteMe
C:\documents and setting\casey242\DeleteMe
C:\documents and setting\casey353\DeleteMe

I wont ask you to write the script for me (all though i wont stop you from doing it either) I just need a good push in the right direction or a good example to get me going.

Thanks in advance for your assistence.
Casey242Casey, 2ND from the bottom...the "FOR" statement.

Let me know if it helps...

http://www.servergig.com/dos/Thats thats what i'm PLAYING with now.
After playing with it for a while this does not give me any errors but does not delete the folders either.

Code: [Select]CLS
FOR %%f IN ("C:\Documents and Settings\*") DO rmdir /q /s "%%f"\delme
pause
EXIT
The out put i get is the same as the command line it just drops one of the %'s
Here is the out put
Code: [Select]C:\Documents and Settings\$n0aedclb\Desktop>FOR %f IN ("C:\Documents and Setting
s\*") DO rmdir /q /s "%f"\delme
I have tried putting the full path for the DO rmdir /q /s c:\Documents and Settings\%%f\delme but that does not work either.

Thanks,
Casey242


Hi,

Try this:

=========
@echo off
cls

cd "C:\Documents and Settings\"
for /d %%a in (*) do (
echo Deleting Deleteme folder in "%%a"
rmdir /s /q "%%a\Deleteme"
echo.
)
=========

I hope that works!

6200.

Solve : batch to compare and rename same file?

Answer»

Hi,
I would know how to compare files of 2 directories
ex: myBatFile 24
rem @echo off
if EXIST \psipi\rde\%1\ goto suite
if NOT EXIST \psipi\rde\%1\ goto notthere
:notthere
md \psipi\rde\%1\
goto suite

:suite
copy C:\temp\*.pdf \psipi\rde\pdf\%1\*.pdf

REM HERE I WOLD HAVE A BACH TO TELL ME IF in the \pdf directory, the *.pdf FILE is the same as WHITCH in the \temp directory.

If yes, I would rename the \pdf\*.pdf in *_1.pdf with a LOOP in *_1.pdf, *_2.pdf, *_3.pdf ...
(example: there is already a file : 070430.pdf. I wold copy the c:\temp\070430.pdf in the same directory. So the new file will be COPIED with this name : 070430_1.cou)

del c:\temp\*.pdf
goto fin
:eof


:eof
exit

Is there an easy solution to do that.

Thanks a lot and best regards