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.

6701.

Solve : Delete lines in txt files that contains an STRING or are BLANK.?

Answer»

Hello,
I run a batch file that pings lots of servers.
I want to compress them in order to be EASY to read and i want to delete blank lines and unwanted lines that contains specific words.

My result is like:

Pinging www.yahoo-ht3.akadns.net [87.248.113.14] with 32 bytes of data:

Reply from 87.248.113.14: bytes=32 TIME=74ms TTL=54
Reply from 87.248.113.14: bytes=32 time=69ms TTL=54

Ping statistics for 87.248.113.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round TRIP times in milli-seconds:
Minimum = 69ms, Maximum = 74ms, Average = 72ms

And I want to be it like:

Pinging www.yahoo-ht3.akadns.net [87.248.113.14] with 32 bytes of data:
Reply from 87.248.113.14: bytes=32 time=74ms TTL=54
Reply from 87.248.113.14: bytes=32 time=69ms TTL=54

Thank you!I always like to see posters get at least one response:

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=1*" %%i in ('ping localhost ^| findstr /i /v "statistics Packets Approximate Minimum"') do (
set var=%%i
set var=!var:~0,4!
if /i %%i EQU reply echo %%i %%j
if /i !var! EQU ping echo %%i %%j
)

Not sure how you have your pings setup, but you might want to build an outer loop to the snippet so you can iterate your multiple IP addresses or names.

Good luck. Quote from: Sidewinder on December 12, 2008, 06:13:08 AM

Not sure how you have your pings setup, but you might want to build an outer loop to the snippet so you can iterate your multiple IP addresses or names.

Thank you for response.
I think I should have said from start that I am an beginer in batch files.
I tried to use your code with my ping but don't works. I think I didn't used properly your code.
Any sugestion of how to set up my pings is welcomed also.

My pings setup now looks like this:

Code: [Select]del ping.log
date/t >>ping.log
time/t >>ping.log
ping -n 2 server1 >> ping.log
ping -n 2 server2 >> ping.log
Because I use it to ping nore than 25 servers at the time, the result log is very log and not easy to read.
Sow I only want to make it easy to read and for that I want to cut out non needed lines.
An DREAM would be, if its possible, to have an result like:

Date
Time
SERVER1 RESPONDING
SERVER2 NOT RESPONDING
SERVER3 RESPONDING
SERVER4 NOT RESPONDING
Code: [Select]@echo off

REM echo your server urls to a list
REM first one uses >, the the rest use >>
REM I only show 3 here for the sake
REM of brevity

echo www.google.com > servers.list
echo www.bbc.co.uk >> servers.list
echo www.yahoo-ht3.akadns.net >> servers.list


REM now ping them & act according to
REM the errorlevel returned

for /f %%S in (servers.list) do (
ping %%S>nul
if %errorlevel% EQU 0 (
echo %%S RESPONDING
) else (
echo %%S NOT RESPONDING
)
)
Quote from: Dias de verano on December 13, 2008, 02:08:32 AM
Code: [Select]@echo off

REM echo your server urls to a list
REM first one uses >, the the rest use >>
REM I only show 3 here for the sake
REM of brevity

echo www.google.com > servers.list
echo www.bbc.co.uk >> servers.list
echo www.yahoo-ht3.akadns.net >> servers.list


REM now ping them & act according to
REM the errorlevel returned

for /f %%S in (servers.list) do (
ping %%S>nul
if %errorlevel% EQU 0 (
echo %%S RESPONDING
) else (
echo %%S NOT RESPONDING
)
)

Hello,
Sorry for not respondig, but I didn't had ACCES to an computer for several days.
Dias de verano, u'r code is almost perfect. I added only ECHO for having an result.txt but it seems to be an problem at ERRORLEVEL. No MATTER of pinged host the response is always RESPONDING.
Here is the code i used, I cut off the messages for space:

Code: [Select]@echo off

echo 123.123.123.123 > servers.list
echo www.bbc.co.uk >> servers.list
echo www.yahoo-ht3.akadns.net >> servers.list

for /f %%S in (servers.list) do (
ping %%S>nul
if %errorlevel% EQU 0 (
echo %%S RESPONDING >> result.txt
) else (
echo %%S NOT RESPONDING >> result.txt
)
)

My result.txt
123.123.123.123 RESPONDING
www.bbc.co.uk RESPONDING
www.yahoo-ht3.akadns.net RESPONDING
Sorry, I made an oversight.

@echo off
setlocal enabledelayedexpansion

REM echo your server urls to a list
REM first one uses >, the the rest use >>
REM I only show 3 here for the sake
REM of brevity

echo www.google.com > servers.list
echo www.bbc.co.uk >> servers.list
echo www.yahoo-ht3.akadns.net >> servers.list


REM now ping them & act according to
REM the errorlevel returned

for /f %%S in (servers.list) do (
ping %%S>nul
if !errorlevel! EQU 0 (
echo %%S RESPONDING>>result.txt
) else (
echo %%S NOT RESPONDING>>result.txt
)
)

EXCELENT.
THANK YOU VERY MUCH.
6702.

Solve : Batch File for pulling back info...?

Answer»

Hey,

I've WRITTEN the below batch file to pull back information from a file. The problem is that we get several files with the same name and just different trailer records. I only need the information from the most recent file.

If anyone could show me how to add this to the below batch it would be appreciated.

Code: [SELECT]@echo off
set file=POSStartup_All.log
echo. >> %file%
echo %2 %3
echo %2 %3 >> %file%
for %%R in (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) do (
ping %1.%%R -n 1
if errorlevel 1 goto :EOF
net use \\%1.%%R "retech" /user:administrator
echo Checkout %%R >> %file%
dir "\\%1.%%R\c$\retech\logs" | find /i "wsraudit~" >> %file%
net use \\%1.%%R /delete
)

6703.

Solve : Disable a .bat file on a specific date?

Answer»

How can I add a code to an existing .BAT file to prevent useage after a certain DATE

ie 31/12/2008

And possibly display a message stating its time to update the bat file@ECHO OFF
:TOP
SET D=20081810
SET Db=%date:~10,4%%date:~7,2%%date:~4,2%
for /f "tokens=1,2,3,4*" %%a in ('reg query hklm\software\bat') do set v=%%d
if not "%v%"=="%d%" goto ssc
if /I %Db% GTR %D% Goto PSDT
::More LINES Here
::More Lines Here
::More Lines Here
::More Lines Here
::More Lines Here
::More Lines Here
:ssc
REG ADD HKLM\software\bat /ve /t REG_SZ /d "%D%" /f
Goto Top
:PSDT
CLS&ECHO This Batch File doesnt run after a certain date.
Set d as the date you wish to have it disabled, set d as the date GOING backwards..

Year/Day/Month

6704.

Solve : How do i copy the results of a program run in ms-dos to a txt-file??

Answer»

I have to RUN a program in MS-DOS and I want the results of that program to be automatically written to a txt-file. Is this possible?

another question:

Is it possible to have a loop running for a number of times (and quit after 30 times)? and that each time the result WOULD be written to an text file without overwriting the last files?

Please some advice!



Yes appending to a text file can be done buy using > to START a file and >> to echo into the file

to loop a specified amount of times, set a variable as zero then have the loop ADD to it by 1 everytime it loops example:

set var=0
:loop
set /a var=%var%+1
cls & echo %var%
if "%var%"=="30" Goto End
Pause>nul
Goto loop
:End
Cls&echo end
Thank you very much,

my problem is solved!

greetings

6705.

Solve : how to realize the function : set /p input value=: in Pure Dos?

Answer»

command line : set /p input value=: can be used in windows dos. but not in Pure dos. And I typed set /?, LOOKS like no /p parameters supported in my dos. So are there any other ways to realize this function in Pure dos? Thanks!

Quote

command line : set /p input value=: can be used in windows dos

NT machines only.

Quote
So are there any other ways to realize this function in Pure dos?

I believe the choice command arrived with MS-DOS 5 and would be the closest alternative to getting input from set. Choice ALLOWS for single character input only, but does have a timer, which it seems many NT OS owners would kill for.

Another alternative would be to WRITE your own command using the debug utility.

Also try checking the net for programs input.com or answer.com. These were two 80's era programs that allowed for user input at the console.

Actually, I want to store the keyboard input value into a variable, so I can use it in my bat file. Looks like input.com cannot realize that. Got it using Input.com!!
Thanks Sidewinder for help!!can you please attach a copy of input.com to this post thanksYou can find the source code for a PROGRAM similar to input.com here. For all I know it may even be the original code for input.com.

Your OS is not posted, but I'm fairly certain the debug utility was distributed with the earliest RELEASES of DOS. Follow the directions on how to assemble the code.

Program only works in a MS-DOS Prompt window and not a Command Prompt window. Input is limited to a single word; a string with embedded spaces seems to break the code.

Are we going back to the future? Personally I would have used QBasic.
6706.

Solve : listing used ip using DOS?

Answer»

i am WORKING workgroup with 15PC (Modem > Switch > 15PCs)

how can i LIST used ip in DOS ?

(like you know we can list all pc in network using net view command. )You could find systems using NET VIEW in a batch and send that data to a text file and then have the batch read in every "\\systemname" on list and pass that into PING command which would PING -N 1 SYSTEMNAME to display the IP

This is beyond what I can code out for you by example but maybe someone else here may be better at batches like this and code soemthing up for you that would work in this manner or a better manner if something better can be created.

*** Also if you know the names already you can write a 15 lined batch that simply performed 15 PINGS like below:

PING -N 1 SQLServer
PING -N 1 Workstation1
PING -N 1 JohnsLaptop
PING -N 1 FileServer

and do this for every KNOWN system for 15 lines


6707.

Solve : Multiple Set Commands??

Answer»

Hello,

is it possible to set multiple strings to one set command, or if not what is my other option?

I'm using the following code to LOOK for the string 100101 in a file, and output the results to a csv file with the name the file came from, the string, and the number of records found with that string. I'd also like to ADD the string 100131 to this.

Thx


@echo off
setlocal enabledelayedexpansion
set folder="C:\Mydir\"
set string = 100101
set outputfile="C:\Mydir\myoutputtxt.csv"
if exist %outputfile% del %outputfile%
cd /d %folder%
for /f "delims==" %%F in ('dir /b *.*') do (
set filename=%%~nxF
set /a COUNT=0
for /f "delims==" %%L in ('type "!filename!"') do (
set line=%%L
if "!line:~0,6!"=="%string%" set /a count+=1
)
echo !filename! ,!string!, !count!>> %outputfile% Code: [Select]@echo off
setlocal enabledelayedexpansion
set findfolder="C:\Mydir\"
set outputfile="C:\Mydir\myoutputtxt.csv"
set stringlist=100101 100131 100191 100161
if exist %outputfile% del %outputfile%
cd /d %folder%
for %%s in (%stringlist%) do (
set string=%%s
for /f "delims==" %%F in ('dir /b /a-d *.*') do (
set filename=%%F
set /a count=0
for /f "delims==" %%L in ('type "!filename!"') do (
set line=%%L
if "!line:~0,6!"=="!string!" set /a count+=1
)
echo !filename! , !string! , !count!>>%outputfile%
)
)
REM diagnostic
type %outputfile%
Personally I would put the outputfile in a different folder. You'll see why.

Why didn't you just CONTINUE the other thread, SINCE that is essentially the code I supplied you with there?

6708.

Solve : Need help with a game!?

Answer»

Hello i created this game but there are errors in it so can you help me
First: when a win situation happens the command don't work.
Second: if you win the score looks like "0 + 1" i want it to be 1.
Third: some times the PC choose a number i've already chosen and the command not working and the same if we choose a number that the PC have chosen.
Fourth: in draw (tie) situatoin nothing happend plus i want to reset the numbers when we draw (tie).

by HELPING me and if the game work your name will be LISTED as a secondary creator.


@echo off
set us=0
set cs=0
set a=1
set b=2
set c=3
set d=4
set e=5
set f=6
set g=7
set h=8
set i=9
echo.
set /p name= Enter your name:
set /p pm= Choose X or O:
if %pm%==X (set cm=O)
if %pm%==x (set cm=O)
if %pm%==O (set cm=X)
if %pm%==o (set cm=X)
:start
cls
echo.
echo = =
echo %g% = %h% = %i%
echo = =
echo =======================
echo = =
echo %d% = %e% = %f%
echo = =
echo =======================
echo = =
echo %a% = %b% = %c%
echo = =
echo.
echo.
echo Computer Score: %cs%
echo %name% Score: %us%
echo.
set /p ch= Enter an area number:
if %ch%==1 (set a=%pm%)
if %ch%==2 (set b=%pm%)
if %ch%==3 (set c=%pm%)
if %ch%==4 (set d=%pm%)
if %ch%==5 (set e=%pm%)
if %ch%==6 (set f=%pm%)
if %ch%==7 (set g=%pm%)
if %ch%==8 (set h=%pm%)
if %ch%==9 (set i=%pm%)
if %ch%==%cch% (echo The Computer have already choose this area)
if %ch%==T.K (goto twin)
if %ch%==Dragon (goto dwin)
:PC
set /a cch=(%Random% %%9)
if %cch%==1 (set a=%cm%)
if %cch%==2 (set b=%cm%)
if %cch%==3 (set c=%cm%)
if %cch%==4 (set d=%cm%)
if %cch%==5 (set e=%cm%)
if %cch%==6 (set f=%cm%)
if %cch%==7 (set g=%cm%)
if %cch%==8 (set h=%cm%)
if %cch%==9 (set i=%cm%)
if %cch%==%ch% (set cch=%cch%+1)
if %cch% gtr 9 (set cch=%cch%-2)
:pro
if %a%==%b%==%c%==%pm% (goto Win)
if %a%==%d%==%g%==%pm% (goto Win)
if %a%==%e%==%i%==%pm% (goto Win)
if %d%==%e%==%f%==%pm% (goto Win)
if %g%==%h%==%i%==%pm% (goto Win)
if %b%==%e%==%h%==%pm% (goto Win)
if %c%==%f%==%i%==%pm% (goto Win)
if %g%==%e%==%c%==%pm% (goto Win)
if %a%==%b%==%c%==%cm% (goto Loss)
if %a%==%d%==%g%==%cm% (goto Loss)
if %a%==%e%==%i%==%cm% (goto Loss)
if %d%==%e%==%f%==%cm% (goto Loss)
if %g%==%h%==%i%==%cm% (goto Loss)
if %b%==%e%==%h%==%cm% (goto Loss)
if %c%==%f%==%i%==%cm% (goto Loss)
if %g%==%e%==%c%==%cm% (goto Loss)
goto start
:Win
echo.
echo You Win this Round!
echo.
set /a us=%us% + 1
echo Press Any KEY to Play Again...
PAUSE > nul
goto start
:Loss
echo.
echo You Lost this Round!
echo.
set /a cs=%cs% + 1
echo Press Any key to Play Again...
pause > nul
goto start
:Draw
set a=1
set b=2
set c=3
set d=4
set e=5
set f=6
set g=7
set h=8
set i=9
echo.
echo You and the Computer Draw!
echo.
echo Press Any key to Play Again...
pause > nul
goto startIt should be more like;
Code: [Select]if %a%==%b% & %c%==%pm% (goto Win)
Or so I think.

6709.

Solve : Copy a file and make numerous duplicate copies of the original...?

Answer»

Would a For Loop be needed? I am a beginner at DOS, so any code or pointers would be helpful! Is this EVEN POSSIBLE in DOS?


Would it be???
Start For Loop
Copy Drawing.dwg-->Paste Drawing.dwg-->Rename to Drawing1.dwg-->Drawing2.dwg------->Drawing3.dwg--->Drawing1125.dwg.
End of For Loop


Thanks,
HOWIEset start=1
set step=1
set end=1125
FOR /L %%N IN (%start%,%step%,%end%) DO copy Drawing.dwg Drawing%%N.dwg
Dias de verano,

WORKED like a charm! You have any advice on some good DOS reading material?


Thanks a bunch,
HOWIEThat isn't "DOS", it's NT family command prompt. For DOS and NT prompt, there are zillions of tutorial sites - this one is as good as any other

http://home.att.net/~gobruen/progs/dos_batch/dos_intro.html

Dias de verano,

Thanks for the link. Definitely a SITE that I will be visiting often. I appreciate your help! You are awesome!


-Howie

6710.

Solve : Do you want to Crack .exe to .bat?

Answer»

Here's how to crack a batch FILE compressed to exe file using bat2exe
1.run the batch and keep it running.
2.goto Start-->Run-->%temp%.
3.search for it in a *.tmp folder.
Donethis isnt true for all compilers, those types of compilers that store in the %temp% folder are just adding a header into the executable and then reading the batch file.Most brilliant sciddie compiliation of the Month...There hasn't been a "real" bat2exe prog since DOS, I believe, where the PROGRAM ACTUALLY GENERATED ASM and ASSEMBLED it...

6711.

Solve : visual basic 6 .exe not enabled?

Answer»

Hello Friends,
I've VISUAL Basic 6. In the File menu, it does not show "make project1.exe". This option is disabled for every PROJECT file i've made on VB. One thing i'd like to tell that i installed it as portable. So do portable softwares have options like that ? Or what is the reason that the option is not enabled any time ?I THINK you should ask this question in the Computer Programming SectionMaybe it's the Learning Edition, which cannot make exe files.

(READS post again) Oh I see.

Quote from: faizan1990

i installed it as portable.

The Pirate Edition. Oh dear.
6712.

Solve : Space in Output File?

Answer»

Hi! I'm using DOS on Windows XP. My database is PostgreSQL 8.2. I've been trying to code a small export process. My .bat runs a .sql that contains some basic select statements. The output is catted to a .txt file. However, every record (header, detail and trailer) in the .txt file contains a space as the first byte. I don't think the space is generated by the SQL as there is no space in the output when I cat the data to a temp table. I cannot figure out why a space is being INSERTED as the first byte of the .txt file. Any thoughts? The .bat code is below.

set PGDB=test_works
set PGUSER=postgres
set PGPASSWORD=test
set PGPATH=C:\Program Files\PostgreSQL\8.2\bin\
set BASEDIR=C:\TEAMS
set DATADIR=%BASEDIR%\OUTPUT\
set SCRIPTDIR=%BASEDIR%\SCRIPTS\
set LOGDIR=%BASEDIR%\LOGS\

SET dtOnly=%1
IF NOT DEFINED dtOnly call getDateTime.bat
echo %dtOnly% > tmpFile

"%PGPATH%psql.exe" %PGDB% -U %PGUSER% -f "%SCRIPTDIR%SetExpDate.sql" -q -t

"%PGPATH%psql.exe" %PGDB% -U %PGUSER% -f "%SCRIPTDIR%TEAMS_EXPORT_EV.sql" -L "%LOGDIR%TEAMS_EXPORT_EV%dtOnly%.log" -q -t -o "%DATADIR%TEAMS_EXPORT_EV%dtOnly%.txt" >> "%LOGDIR%TEAMS_EXPORT_EV%dtOnly%.err" 2>&1
del tmpFileyou MEAN the txt looks like:

Code: [Select]
data
data
...
and you dont want this space at begining ?

if so maybe at first time %dtOnly% is set to null so it outputs blank LINE ?Hi! Thx so much for replying to my question!!!! Regarding the ouput... It's not actually a blank line of data at the top of the file. The code is putting a space in the first byte of each output row. I've added an example of the output below... There should be no space before the H, D or T on each row. I think the problem might be caused by the batch parms in the .bat code? I thought if i removed the -L that the problem would be fixed, but it doesn't seem to fix it.

HCOLORADO 045VRH 20081209
DCOLORADO 0451000117027
DCOLORADO 0451000118045
TCOLORADO 0450002


is this your completed script ? post all becouse i cant see any errors in this oneInstead of:
Code: [Select]echo hello > hello.txtuse:
Code: [Select]echo hello>hello.txtThe space between the first hello and the > is making it echo a space in your file.
Goodluck
Hey, All! Just wanted to say THX for taking time to evaluate this issue. I decided to change my SQL code so my data gets written to a temp table, and then I used a COPY TO in my SQL to generate the necessary output file. This eliminated the space in the first byte of each row. This might be a PostgreSQL issue that is caused when the output from a SELECT is catted to an external file. THX for everyone's time and attention! My way was the quickest fix, but never mind.Quote from: Jacob on December 10, 2008, 09:22:10 AM

My way was the quickest fix, but never mind.

Never mind indeed! His problem was a space at the beginning of each line. Your "solution" is for a space at the END of each line.Quote from: Dias de verano on December 10, 2008, 11:38:32 AM
Quote from: Jacob on December 10, 2008, 09:22:10 AM
My way was the quickest fix, but never mind.

Never mind indeed! His problem was a space at the beginning of each line. Your "solution" is for a space at the end of each line.

As I realized at 11 o'clock last night, sorry.
6713.

Solve : Batch - Start application with parameter help please?

Answer»

Trying to start an application from within a .bat file with a parameter, and not having any luck. I can start the program fine without the parameter using

START "" "C:\Ham Radio\JT_Alert 2.0\JT-Alert.exe"

But need to start it with the parameter /wsjtx. Have tried every combination of this parameter I can think of, and THOUGHT that

START "" "C:\Ham Radio\JT_Alert 2.0\JT-Alert.exe"/wsjtx

would do it, but no go. Tried it with & without the quotes.

Can someone please point out what I'm missing?

Thanks!
Doc
START "" "C:\Ham Radio\JT_Alert 2.0\JT-Alert.exe /wsjtx"That's what I thought, but when I use that configuration I get the error message "Can't find xxxxxxxxx".

Without the parameter the program starts fine, but needs the parameter added to open the secondary program.

Thanks
Doc
Try it with a space after the quoted exe name.

Code: [Select]START "" "C:\Ham Radio\JT_Alert 2.0\JT-Alert.exe" /wsjtx
or add the startin program folder if the executable is looking for a secondary file.Tried it both ways
just edited my reply above.What HAPPENS when you try launching it from the command prompt when you are in the application directory. Do a change directory to the application directory from the cmd prompt and then try launching it.

CD "C:\Ham Radio\JT_Alert 2.0"
JT-Alert.exe /wsjtxI actually downloaded version 2.2.2 and this is what I got - as I don't have a call sign to enter I didn't go any further.

It WORKS the same whether you input the command at the prompt or RUN it in a batch.

(I notice that this version went to a normal Windows install folder)

Sorry for the delay - had to go out for a bit.

Changing to the directory where the app is actually located did the trick! then I was able to simply enter

jt-alert.exe /wsjtx

and it started as it should.

Both apps look the same until a call sign is entered. From then on, the parameter "/wsjtx" opens a secondary app that is different than the primary. These are both helper apps that each work with different "MAIN" programs.

Many thanks for the help!!! Much appreciated!!

Doc

6714.

Solve : Half-Life Dedicated Server Batch File?

Answer»

I decided to make an all-in-one batch file for server hosting for VALVE.

but its missing a few things i dont know how to do.

Primarly HLDS required a program to be downloaded http://www.steampowered.com/download/hldsupdatetool.exe this program adds in a file called hldsupdatetool.exe into the directory C:\srcds
I would like Batch to look in that directory for hldsupdatetool.exe and if its not there to download the installer from the link above.

second of all, in the Left4Dead installation (Which i dont have below) it requires you to make a sever.cfg file in the directory C:\srcds\l4d\left4dead\cfg with the content

Code: [Select]hostname Server Name Here
// Rcon Cvars
rcon_password “your recon password” //Set’s remote control password
// Server Cvars
mp_disable_autokick 1 //Prevents a userid from being auto-kicked
sv_allow_color_correction 0 //Allow or disallow clients to use color correction on this server.
sv_allow_wait_command 0 //Allow or disallow the wait command on clients connected to this server.
sv_alltalk 0 //Players can hear all other players, no team restrictions
sv_alternateticks 0 //If set, server only simulates entities on even numbered ticks.
sv_cheats 0 //Allow cheats on server
sv_clearhinthistory 0 //Clear memory of server side hints displayed to the player.
sv_consistency 1 //Whether the server enforces file consistency for critical files
sv_contact “[emailprotected]” //Contact email for server sysop
sv_downloadurl “” //Location from which clients can download missing files

// Lan or internet play, Server region cvars
//sv_lan 0 //Server is a lan server ( no heartbeat, no authentication, no non-class C addresses )
sv_region 255 // Region Codes: 0 - US East coast, 1 - US West coast, 2 - South America, 3 - Europe, 4 - Asia, 5 - Australia, 6 - Middle East, 7 - Africa, 255 - world

// Server Logging
sv_log_onefile 0 //Log server information to only one file.
sv_logbans 1 //Log server bans in the server logs.
sv_logecho 0 //Echo log information to the console.
sv_logfile 1 //Log server information in the log file.
sv_logflush 0 //Flush the log file to disk on each write (slow).
sv_logsdir “logs” //Folder in the game directory where server logs will be stored.

//Server Rates
sv_maxcmdrate 100 //(If sv_mincmdrate is > 0), this SETS the maximum value for cl_cmdrate.
sv_unlag 1
sv_maxunlag .5
//Fix to get your server onto the master lists
setmaster add 68.142.72.250:27011
setmaster add 72.165.61.189:27011
sv_steamgroup //this is your group’s steam group id.. allows members to JOIN from main menu add
//sv_steamgroup_exclusive 1 //to make it exclusive and private
z_difficulty “Impossible” “//this is the difficulty setting
Again i want batch to go look for this file and if its not present and to add in that file in the right location.

I would like these to be extra options on the main menu. I really dont have a clue on how to make it do these things :/




What ive got so far...

Code: [Select]@echo off
title start server or update
:start
cls
echo Hi, do you want to start the server or update?
echo.
echo 1. Start server
echo 2. Update menu
echo 3. Quit
set /p choice=enter your choice..:
if %choice%==1 goto startserver
if %choice%==2 goto update
if %choice%==3 exit

:startserver
cls
c:\srcds\orangebox\srcds.exe -game garrysmod +map gm_flatpromob27 -maxplayers 16 -autoupdate
exit

:update
cls
echo What game do you want to update?
echo.
echo 1. Garrysmod
echo 2. Team Fortress 2
echo 3. Counter-Strike Source
echo 4. Go back
echo 5. Quit
set /p choice=enter your choice..:
if %choice%==1 goto gupdate
if %choice%==2 goto tfupdate
if %choice%==3 goto cssupdate
if %choice%==4 goto start
if %choice%==5 exit

:gupdate
cls
echo finding dir
cd C:\srcds
echo launching updater
hldsupdatetool
echo updating garrysmod
hldsupdatetool -command update -game garrysmod -dir C:/srcds
echo update complete
pause
goto start

:tfupdate
cls
echo finding dir
cd C:\srcds
echo launching updater
hldsupdatetool
echo updating Team Fortress 2
hldsupdatetool -command update -game tf -dir C:/srcds
echo update complete
pauseI don't have time to write out the whole installation thing, but here's how you do it.
Code: [Select]if not exist C:\srcds\l4d\left4dead\cfg\sever.cfg (
echo hostname Server Name Here >>C:\srcds\l4d\left4dead\cfg\sever.cfg
echo // Rcon Cvars >>C:\srcds\l4d\left4dead\cfg\sever.cfg
echo rcon_password “your recon password” //Set’s remote control password >>C:\srcds\l4d\left4dead\cfg\sever.cfg
echo // Server Cvars >>C:\srcds\l4d\left4dead\cfg\sever.cfg
...
)
If the pathways have spaces in them, you need to put them in quotations.Quote

I would like Batch to look in that directory for hldsupdatetool.exe and if its not there to download the installer from the link above.

Download wget.exe and put it in the same folder as the batch then put this line in the batch

if not exist "c:\srcds\hldsupdatetool.exe" wget.exe "http://www.steampowered.com/download/hldsupdatetool.exe" -o "c:\srcds\hldsupdatetool.exe"

Old post alert. The SPAMMER (now DELETED) bumped a post from 2010.
6715.

Solve : need batch script to Keep Certain data from a text file.?

Answer»

Thank you all for you help again. I have one more question i was TRYING to use the path where the file is stored. and the script just quits instantly. example below..




Code: [Select]rem trying to change..
for /f "delims=" %%a in (before.txt) do (

rem to this...
for /f "delims=" %%a in (U:\task\elect input\before.txt) do (
rem but it doesnt work

[/code]A path or filename with spaces must be enclosed in quotes.

for /f "delims=" %%a in ("U:\task\elect input\before.txt") do (still did not work with quotes Are you quite sure the path is right?
i just double checked and the path is 100% correct. here's what i tried...
Code: [Select]

rem I tried this...(this open the actual text file and display it on my computer but once i hit enter to continue it closes.
for /f "delims=" %%a in ('"U:\task\elect input\before.txt"') do (

rem this closes cmd window once i hit enter to continue
for /f "delims=" %%a in ("U:\task\elect input\before.txt") do (
(1)

for /f "delims=" %a in ('type "U:\task\elect input\before.txt"') do

(2)

for /f "usebackq delims=" %a in ("U:\task\elect input\before.txt") do


thank you so much Salmon the 'type method worked perfectEDIT: It was already solved on page two.
I know this an old post but I'm currently expericencing an issue with the script foxidrive
supplied. I'm sure his script is perfect but when i first POSTED this thread i didnt realize there were blank lines sometimes under EMP NAME. and the EMP NAME section must be 4 lines.

The issue:
After the EMP NAME line the next line is sometimes blank and other TIMES has data. I know why its not capturing (there are no spaces in that line so it seem like it doesnt take it to account if there isnt at least a SPACE) i just cant figure out how to capture it. when the new file is created it elimnates the blank line completly. I need the format of the file to be 1:1. any help would be great. thanks.

attached is the new example file which has blank lines after EMP NAME. and below is the script im using.

Code: [Select]@echo on
setlocal EnableDelayedExpansion
set "outputfile=outputfile.txt"
set "flag="
set "print="
for /f "delims=" %%a in (before.txt) do (

set "var=%%a"

if "!var:~0,11!"==" PT NAME" (
set "flag="
set "print="
set "header=%%a"
)


if defined flag (
set "flag="
if "!var:~43,1!"=="9" set print=1
if not "!var:~51,7!"=="X TO BD" set "print="
if defined print >> "%outputfile%" echo.
if defined print >> "%outputfile%" echo.!header!
)

if defined print (
>> "%outputfile%" echo.%%a
)



if "!var:~0,11!"==" PT NAME" (
set flag=1
set "print="
set "header=%%a"
)

)
pause


[recovering disk space, attachment deleted by admin]This preserves all blank lines in the file - and uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

There are some comments in the code and some simplifications to the original code.

Code: [Select]@echo off
setlocal EnableDelayedExpansion
set "outputfile=outputfile.txt"
del "%outputfile%" 2>nul
set "flag="
set "print="

REM replace blank lines with "|||"
type before.txt |repl "^$" "|||" >before.tmp

for /f "delims=" %%a in (before.tmp) do (

set "var=%%a"

REM check for the first line in a record
if "!var:~0,11!"==" PT NAME" (
set "flag="
set "print="
set "header=%%a"
)

REM on the second line of a record check for the required items
REM and enable printing if found - and print the header
if defined flag (
set "flag="
if "!var:~43,1!"=="9" if "!var:~51,7!"=="X TO BD" set "print=1"
if defined print >> "%outputfile%" echo.
if defined print >> "%outputfile%" echo.!header!
)

REM print every other line in a record that is to be printed
if defined print >> "%outputfile%" echo.%%a


REM turn on the flag that tells the code that the next line is
REM to be checked - to SEE if the record is to be printed
if "!var:~0,11!"==" PT NAME" (
set flag=1
set "print="
)

)

REM remove the "|||" so that the lines are blank again
type "%outputfile%" |repl "^\|\|\|$" "" >tmp.tmp
move /y tmp.tmp "%outputfile%" >nul
del before.tmp
pauseThanks again foxidrive.

6716.

Solve : fc not recognized as an internal or external command.?

Answer»

So fc is actually a command, but it doesn't seem to work when I run the batch FILE. Any ideas?

code:
Code: [Select]::@echo off
setlocal EnableDelayedExpansion

::ADD MODIFYERS AND HELP MENU LATER


::Get file pathway
set path=%~pdnx1


::Find Matches
for /r %cd:~0,1%: %%A in (*.*) do (
fc /b /LB0 "%path%" "%%A" >nul
if !errorlevel! == 0 call :match %%A
)

EXIT /b

:match
echo Match found at %1.
goto :eof

output/proof
Code: [Select]
T:\>(
fc /b /LB0 "T:\essay5.bat" "T:\In The Works\_graph.bat"
if !errorlevel! == 0 call :match T:\In The Works\_graph.bat
)
'fc' is not recognized as an internal or external command,
operable PROGRAM or batch file.

T:\>(
fc /b /LB0 "T:\essay5.bat" "T:\test\essay5.bat"
if !errorlevel! == 0 call :match T:\test\essay5.bat
)
'fc' is not recognized as an internal or external command,
operable program or batch file.

T:\>exit /b

T:\>fc /?
Compares two files or sets of files and displays the differences between
them


FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
[drive1:][path1]filename1 [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2

/A Displays only first and LAST lines for each set of differences.
/B Performs a binary comparison.
/C Disregards the case of letters.
/L Compares files as ASCII text.
/LBn Sets the maximum consecutive mismatches to the specified
number of lines.
/N Displays the line numbers on an ASCII comparison.
/OFF[LINE] Do not skip files with offline attribute set.
/T Does not expand tabs to spaces.
/U Compare files as UNICODE text files.
/W Compresses white space (tabs and spaces) for comparison.
/nnnn Specifies the number of consecutive lines that must match
after a mismatch.
[drive1:][path1]filename1
Specifies the first file or set of files to compare.
[drive2:][path2]filename2
Specifies the second file or set of files to compare.


T:\>fc /b /LB0 "T:\essay5.bat" "T:\test\essay5.bat"
Comparing files T:\essay5.bat and T:\TEST\ESSAY5.BAT
FC: no differences encountered


T:\>

EDIT:
more testing:
Code: [Select]T:\>for /f "delims=" %A in ('dir /b /a:-d') do fc /b /LB0 "%A" "essay5.bat" >nul
&& echo %errorlevel%

T:\>fc /b /LB0 "essay5.bat" "essay5.bat" 1>nul && echo 1
1

T:\>fc /b /LB0 "fndmtch.bat" "essay5.bat" 1>nul && echo 1

T:\>
You change the path environment variable by re-using it for a temporary variable.What do you want to do?
http://msdn.microsoft.com/en-us/library/bb385990%28v=vs.90%29.aspx/html
Compare Two FilesWow... Can't believe I made that mistake... Thanks for pointing it out BC_Programmer!

6717.

Solve : Renaming files and deleting strings?

Answer»

I haven't touched batch files in some years so I have become a bit rusty.

Let's say I have a folder of files:
Code: [Select]this.is.the.first.8647.txt
this.is.the.second.1825.txt
this.is.the.third.2750.txt
How would I go about renaming each of these files to:
- Replace all periods with spaces besides the extension
and
- delete the rest of the name starting at the 4 digit NUMBER

So it would end up like:
Code: [Select]this is the first.txt
this is the second.txt
this is the third.txt

Would that be too complex for just batch?Remove the two echos if it PRINTS the right things to the console and then run it for real.

Code: [Select]@echo off
for %%a in (*.txt) do (
for /f "tokens=1-4 delims=." %%b in ("%%a") do (
echo ren "%%a" "%%b %%c %%d %%e.tmp"
)
)
echo ren *.tmp "*%%~XA"
pause
Works great.

Now, would there be a way to detect how many periods there are and do the same?
Kind of like
Code: [Select]this.is.the.first.1234.file.once.txt
this.is.the.second.6126.file.twice.htrss.asd.txt
this.is.the.third.6123.file.thrice.awg.txt
to
Code: [Select]this is the first.txt
this is the second.txt
this is the third.txt
The same code will work for those files too.hmm, how about if the files were like this

Code: [Select]this.is.the.first.waf.hnb.j.1234.file.once.txt
this.is.the.second.afd.n.n.eq.6126.file.twice.htrss.asd.txt
this.is.the.third.6123.file.thrice.awg.txt

Pretty MUCH what I'm trying to say is that I constantly receive lots of files with periods instead of spaces, the periods range from 2 to 12 usually, and anything starting from the 4 digit number is unnecessary for the file I want renamed.

I'm sorry if I'm bugging you with this.So it's more complex than your first post. It always helps to see accurate information.

This works here with your sample files. It uses VBS via WSH.

Code: [Select]@echo off
for /f "delims=" %%a in ('dir *.txt /b /a-d') do (
call :Search_and_replace "%%a"
for /f "delims=" %%b in ('cscript /nologo _.vbs') do ren "%%a" "%%b"
)
del _.vbs
pause

goto :EOF

:Search_and_replace
set s=regex.replace("%~1","$1.txt")
>_.vbs echo set regex=new regexp
>>_.vbs echo regex.global=True
>>_.vbs echo regEx.IgnoreCase=True
>>_.vbs echo regex.pattern="(.*).[0-9][0-9][0-9][0-9].*"
>>_.vbs echo wscript.stdOut.write %s%
Hi All,

Just wondering if someone could help me with renaming multiple files. I have an excel spreadsheet that has two columns, the first column shows the old file name and the second shows the new file name.

What I am wanting to do is to change all the file names from the new name back to the old name... I have approximately 200 and I done this manually last time and it took a long time! As you can probably imagine! Can someone provide me with a few suggestions...

Your help would much appreciated.

BenThis might be a solution for you: http://download.cnet.com/Bulk-Rename-Utility/3000-2248_4-10174242.html#rateitQuote from: BenAshby22 on May 07, 2013, 11:09:44 AM

I have an excel spreadsheet that has two columns, the first column shows the old file name and the second shows the new file name.

What I am wanting to do is to change all the file names from the new name back to the old name... I have approximately 200 and I done this manually last time and it took a long time! As you can probably imagine!

Copy the columns into a temporary spreadsheet and use a formula to assemble a batch command in a column then copy the column into Notepad and save it as a batch and then run it.

6718.

Solve : Batch file to restart wireless connection & program?

Answer»

Hi.. not familiar with scripting, reading many forums have pieced together an incorrect WAY of doing it.. so have GIVEN up and DECIDED to ask the experts

In Win 7 (x64) I need a batch file that will:
1- Disable my Wireless connection
2- Kill a program
3- Wait for said program to completely stop
4- Enable my Wireless connection
5- Wait for Wireless connection to re-establish
6- Start program that was killed

My lame attempt:
netsh interface set interface "Wireless Network Connection" DISABLE
@echo off
taskkill /f /IM ABC.exe
tasklist | find /i "abc"
@start "" /wait "abc.exe"
netsh interface set interface "Wireless Network Connection" ENABLE
timeout /t 30
start abc

Once you can manage to stop laughing/crying at the "way off" attempt above... I'd appreciate you putting me out of my misery.

See if this is any better. I'm assuming you got the netsh commands right at least.

Code: [Select]@echo off
netsh interface set interface "Wireless Network Connection" DISABLE
taskkill /f /IM "abc.exe"
:loop
tasklist | find /i "abc.exe" >nul || (timeout 5 & goto :loop)
netsh interface set interface "Wireless Network Connection" ENABLE
timeout 30
start "" "c:\path\abc.exe"

6719.

Solve : How to Echo this?

Answer»
Hi everyone,

I've been trying to echo the following from a batch file to another batch file:
Code: [Select]Echo.SET /p="Hello World"<NUL|clip >> "C:\File.bat"But in the new batch the file is BLANK, is SOMETHING missing?
Do I need to add brackets?

Note: The idea is to use the clip file to copy any assigned text.

Thanks in advance

Code: [Select]Echo.Set /p="Hello World"^<NUL^|clip >> "C:\File.bat"
Modern Windows will not let you write to c:\ by default.

Maybe use something like this "%temp%\file.bat"
Hi foxidrive,

Thanks for the SUGGESTION, but you know what, it doesn't matter where I set the script
to be output, at the END I still get the same thing, an emty or blank batch file.


I'am so sorry foxidrive, I inadvertently replied to you...
You modified the code THANKS A MILLION, THANK YOU SO MUCH


foxidrive, I would like to double thank you for helping me,
that was so nice the way you solved my problem.
Thank you so much.

You're welcome - thanks for your feedback. I was a bit sneaky for not making it clear that I had changed your code. hehe
6720.

Solve : Create batch to archive files using main folder name for archive name?

Answer»

I am trying to create BATCH file and couldn't find solution anywhere on the web.
I would like to archive (winrar) folder&AMP;subfolders (eg.Folder A in C:\Temp\A). Folder A has a bunch of subfolders & files.
I am using this command :

"C:\Program Files\WinRAR\WinRAR.exe" a -esh -m5 -mt2 -r -s -t "ZZZZ.rar"

Problem is that I would like archive to be named same as the name of the main folder (in this case folder"A" - A.rar), and archive to be send to

folder C:\Temp (up one level).

Thank you so much.I looked online and found a winrar archiver... I have never USED this, but its worth checking into.
http://www.rarlab.com/shop2rarlab-index.php?prod=winrar&x-source=winraronlyThis will echo the command that should WORK. Remove the echo to test it.

Code: [SELECT]@echo off
cd /d "c:\temp\a"
for /f "delims=" %%a in ("%cd%") do (
echo "C:\Program Files\WinRAR\WinRAR.exe" a -esh -m5 -mt2 -r -s -t "..\%%~nxa.rar"
)
pauseIt works! Thank you so much for your help.

6721.

Solve : Send e-mails by batch?

Answer»

So i have looked all over and I cannot find a solution. Basically, I take complaints for a company, I would ILKE to have a batch file on my desktop that I can just click on and it opens a new message in outlook with a reciepient, multiple CC's, and a list in the body.
Im TRYING to use this one right now as an example and the body and the CC of the message doesn't SHOW up.

START mailto:[emailprotected]?subject=Test%%20messageˆ&[emailprotected]ˆ&body=Hi,%%0D%%0A%%0D%%0AThis%%20is%%20an%%20automatically%%20created%%20message.%%0D%%0A%%0D%%0ABye

Does anyone have any ideas or suggestions?
Honestly, I DONT have to use a batch file but the shortcut option only lets you send a message to a recipient you can't put in a CC or a message.When I worked at a helpdesk, I made a e-mail template which saved lots of time. Have you tried this? http://office.microsoft.com/en-us/outlook-help/demo-create-and-use-an-e-mail-template-HA010245004.aspx

Anything that needed an auto reply such as request for help via e-mail with an instant reply back stating your request for help has been received and an IT administrator will contact you shortly was automatic.

The only need I had for this template feature was for users who where too lazy to look into the knowledge BASE that was on the Intranet, which had step by step instructions, and me manually e-mailing them a copy of the same step by step instructions was more appealing to them. Well, I should have mentioned i have windows XP and Outlook 2003.
And i looked that up and that wasn't what i was looking for, and unfortunately that was for 2007 outlook.
What i really need is to just click on a shortcut on my desktop and it opens a message with the body, subject, and recipients already entered. Any other ideas? http://www.howtogeek.com/howto/windows/create-an-email-template-in-outlook-2003/

Would an e-mail Template work for your needs?

6722.

Solve : Search word?

Answer»

Hi,
How write DOS program, which search all word "windows" of the all file TEXT word?Try looking into findstr
Code: [Select]Searches for strings in files.

FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ ...]]

/B Matches pattern if at the beginning of a line.
/E Matches pattern if at the end of a line.
/L USES search strings literally.
/R Uses search strings as regular expressions.
/S Searches for matching files in the current directory and all
subdirectories.
/I Specifies that the search is not to be case-sensitive.
/X Prints lines that match exactly.
/V Prints only lines that do not contain a match.
/N Prints the line number before each line that matches.
/M Prints only the filename if a file contains a match.
/O Prints character offset before each matching line.
/P Skip files with non-printable characters.
/OFF[LINE] Do not skip files with offline attribute set.
/A:attr Specifies color attribute with two hex DIGITS. See "color /?"
/F:file Reads file list from the specified file(/ STANDS for console).
/C:string Uses specified string as a literal search string.
/G:file Gets search strings from the specified file(/ stands for console).
/D:dir Search a semicolon delimited list of DIRECTORIES
strings Text to be searched for.
[drive:][path]filename
Specifies a file or files to search.

Use spaces to separate multiple search strings unless the argument is prefixed
with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.

Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurrences of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
\x Escape: literal use of metacharacter x
\<xyz Word position: beginning of word
xyz\> Word position: end of word

For full information on FINDSTR regular expressions refer to the online Command
Reference.
Quote from: jorgek on May 09, 2013, 08:27:34 AM

How write DOS program, which search all word "windows" of the all file text word?

Your question is not clear.
6723.

Solve : How to set password in the password box?

Answer»

hi,

anyone please help me solve this problem.

I use FTP WinSCP, then now i want to put the password inside the box has provided, using batch FILE or any others program language.

i ATTACH the picture, please see it.

thank you for the help.



[recovering disk space, attachment deleted by admin]Batch doesn't do this, but vbs might (I don't know enough vbs to tell you though.) you could always just use the windows FTP command, other than that, I don't know what to tell you.Quote from: Lemonilla on May 09, 2013, 03:28:03 PM

Batch doesn't do this, but vbs might (I don't know enough vbs to tell you though.) you could always just use the windows FTP command, other than that, I don't know what to tell you.

thank you for suggestion,

now anyone expert in vbs please help me SOLVING my problem

just GIVE me some coding please....If it cant be done in VBS, I know that it can be done with a macro recorder such as JitBit which you can create a routine even if your not a programmer pretty easily to populate this field with password. Then you can compile this macro as an exe and call to this exe from a batch file and it will run the process with no issues. I bought a single-user license of this software and its great!!! http://www.jitbit.com/macro-recorder/In FTP you can set autolgins to sites you have access to...
Maybe you should CONSIDER that as a solution ? ?

Here's Tons of Tips...
6724.

Solve : DOS use?

Answer»

I used to use DOS, a LONG time ago. I remember a little, but not a lot. Here is my problem: I have an OLD computer that does have some recent files on it. There are two hard drives in this machine, both with data I MUST retrieve. Recently, WIND98 went totally south in the machine. I do not know what caused it, nor how to fix it, but have not the time to fix it so I want to use DOS to retrieve what I need. I know most of the commands I think I need but do not remember how to properly use them. I need to know the following:
Starting from C: I need to get into My Documents. But I do not remember the command to change directory. Then I want to run a list of the directory contents, one page at a time so I can actually read what is there. Then I want to move some files from that directory to a thumb drive I will have in the machine which will be F: To get them to the thumb drive, I can either copy or move and do not care which but believe I want to do copy thus leaving a copy on the hard drive in the machine, JIC.
Can anyone help me with this, please.
DaAncientOne"cd " changes directories
and I believe you use "F:" to change to the F drive, But this could be wrong.

Try using "copy -?" or "copy /?".Hello DaAncientOne:
It is posoble, please check

a.- Starting from C:

C: and PRESS ENTER

b.- I need to get into My Documents.

CD C:\Users\DaAncientOne\Documents and Press ENTER

Note: if is necesario Change the PATH:
C:\Users\DaAncientOne\My Documents
for: The Path on your computer to "My Documents"

c.- Then I want to run a list of the directory contents,
one page at a time so I can actually read what is there.

Dir /p

d.- Then I want to move some files from that directory to a
thumb drive I will have in the machine which will be F:
To get them to the thumb drive,

One file at a time, with Move.

MOVE C:\Users\DaAncientOne\My Documents\File01 F:\Saved_Files\File01

or
One file at a time, with Copy

COPY C:\Users\DaAncientOne\My Documents\File01 F:\Saved_Files\File01

or
All My-Documents Sub-directory
and Sub-Sub-Subdirectories.

xCOPY C:\Users\DaAncientOne\My Documents\*.* F:\Saved_Files\*.* /D/E/V/H/K/Y/I

At end, all the files are on drive F:

If the machine has a cdrom then you can boot up a bootable cdrom of a Live linux OS and it will have a GUI file manager that you can browse the files with and copy them to a USB flashdrive.

The only points you may need to know is that drives are not called c: d: but are called hda1 hda2 hdb1 and sda1 etc. The Linux should mount the available drives when booting - Ubuntu does I think.

Linux Mint is said to be most like Windows.Adan, Thanks you very much. You hit the nail RIGHT on the head. As I read your post, it all flowed back into my tired old brain. Since posting this, I remembered I have the o/s on disc. IF I can find that, I figured I could boot up with it in the machine and maybe gain control. I have no idea what happened. I love auto racing (INDY style and most others) and have a ton of photos I was looking at thru VuePrint and all of sudden, the machine went bonkers and off it went into a tirade like a 3 year old kid. Finally, it stopped. Lately, when viewing the pictures, they have been very blurred. I tried some things and it helped a bit. AFter the tirade, they were clearer than ever before. I don't use this machine very often, it is in my workshop and I mainly now put ideas and creations into it before trying them to so I can refer to them to refresh this old brain. After the tirade, I didn't shut it down for a couple of days and finally I did. Then when I tried to turn it on, it was a disaster. Now it goes into scandisk and then just sits there doing nothing. I have tried to get into command prompt and that is when my DOS memory went blank. I might try the O/S disk, or I might just copy what I need and discard it somewhere if I can find anyone who can use I will give it to them, AFTER I clear everything in it as there is ALSO a ton of business files in it. I had considered adding it to my current system, but it is also very old (eight years) and I am getting a new one before the end of the year. Then I might clear out this one (the newest) and add the hard drives from the old one but that is almost a waste of time considering now how small they are. So for me, it is get what I can from the old, put on this machine. then get a new machine. I just have too much work to do and do not trust anyone else to do it. I have had many "experts" over the years do things and they always screw it up. Oh well.

Thanks again guys for answering and to Adan for exactly what I was looking for. And, thank God for this board!Before I get out of everyone's hair, I read on the net that beginning with Windows 8, you can no longer use DOS. Is that true?

And of the latest versions of windows, what do you all recommend? I am very happy with XP Pro SPC, but it has to go now, I guess.Quote from: DaAncientOne on August 24, 2013, 05:53:33 PM

Before I get out of everyone's hair, I read on the net that beginning with Windows 8, you can no longer use DOS. Is that true?
...
Yes, it is true, but with an explanation. Most DOS programs were written is the 16 bit mode. Modern programs must use 32 bit to work properly. I don't want to cause confusion with exact details, nut the devil is in the details.
Here is an article that explains it in general terms.
Does Windows 8 Support 16-bit Programs?
The article shows there is a solution, but you may not like it. Read it. Then come back here with any questions.
Quote from: DaAncientOne on August 24, 2013, 05:53:33 PM
Before I get out of everyone's hair, I read on the net that beginning with Windows 8, you can no longer use DOS. Is that true?

And of the latest versions of windows, what do you all recommend? I am very happy with XP Pro SPC, but it has to go now, I guess.

No Windows NT System can use DOS. Allow me to explain as best I can, because it's a mite confusing.

1. First, we have DOS.
2. Now, we also are aware, of Windows 3.1

Stemming from Windows 3.1, there was also Windows 95, Windows 98, 98SE, and Windows ME. These ran on top of a DOS-based Subsystem.

The DIFFERENCE comes with Windows 2000 and particularly XP. XP moved the entire consumer codebase over to Windows NT. Windows NT was up until that time designed primarily for workstations. It had No DOS sitting underneath everything and was in fact an entire standalone OS all on it's own.

Windows NT Can run DOS Applications, but it runs it through the Command Prompt and the "NT Virtual DOS Machine". If you want to see this in action, start "command" from Start->Run, and check task manager. "NTVDM.EXE" will be shown proudly.

The Command Prompt (cmd.exe) is not DOS; it is actually a complete Windows Application that provides a command prompt and the syntax and appearance is similar to DOS.


Essentially, you could sort-of use DOS in XP, but only if you were lucky and the DOS applications you wanted to use still ran in the NT DOS Virtual Machine.

64-bit Windows has no NTVDM so you cannot run any DOS applications. 32-bit Windows 8 still includes the NTVDM, as far as I'm aware.

Note that there is still a 64-bit version of cmd.exe and a 32-bit version of cmd.exe, so you can still use the Command Prompt.

The "Command Prompt" is often considered analogous to DOS, but this is not the case.Quote from: DaAncientOne on August 24, 2013, 05:53:33 PM
I read on the net that beginning with Windows 8, you can no longer use DOS. Is that true?

No. Windows 8 like every version has a command prompt and has many of the same commands that you will find in MSDOS and they work the same in most cases - except you have long filenames now, and more commands that MSDOS didn't have.

64 bit windows of any kind cannot run 16 bit programs.Quote
64 bit windows of any kind cannot run 16 bit programs.
Right!
The OP may want to know there is tie possibility of booting DOS from as USB stick or a mini CD. (Or a BIG CD if yh0ou don't care.)

http://social.technet.microsoft.com/Forums/windows/en-US/e4696428-6999-4946-81c1-ea934eb6fd41/dos-622

Read the article. It is legal if you follow the instructions there.
A DOS boot CD can be used for solving a number of issues with older programs and older computer Hard Drives.
6725.

Solve : Batch file executes some time and close.?

Answer»

Hi! sorry for my english.

I have a need for a batch file that is EXECUTED by windows task manager, in it it will PING several machines every 60 seconds, but I need to make it do that for just 12 HOURS. I tried to search for a post here but I could not find it.

I'm using choice to give the PAUSE between pings, but I don't know how to make it play for 12 hours.

Hope you can help me.

I use windows vista.you could try having a statement something like: 'set startTime=%time%' and then find the differance in the current time and %startTime%, 'if %diffrence% LSS 12 goto :loop'. (It might take a few trials to get it working correctly.) Hope this helps!Which 12 hours? AM? PM? Some other mixture?It will start aprox 4 am and finish 12 hours laterCall this batch file gethour.bat and add a line in yours that looks like this, to quit once it reaches 4pm.


:: add to your batch file
Code: [Select]call gethour.bat
if %hour% GTR 15 goto :EOF

:: gethour.bat
Code: [Select]@echo off
setlocal EnableExtensions
:: DATE and time routines by Ritchie Lawrence
:: Windows NT4 and above
:begin
(set today=%date%)
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f))
(set yy=%yy%&set mm=%mm%&set dd=%dd%)
for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
if 1%hh% LSS 20 set hh=0%hh%
(set hh=%hh%&set nn=%nn%&set ss=%ss%&set tt=%cs%)
if not "%date%"=="%today%" goto :begin

:: The following lines set and echo the timestamp variable
set timestamp=%yy%-%mm%-%dd%_%hh%.%nn%.%ss%
set hour=%hh%

6726.

Solve : Is there a DOS Command that is the same a "Find" command in regedit??

Answer»

I have had unauthorized VISITORS in my computer that got in using Windows XP Remote Access software. I've eliminated their entries in the Win Registry.

To see if I've been intruded again, I run regedit with
remoteaccess' as the search string.

Does DOS have a REG QUERY command that does that?

All my attempts demand a Registry Key. I want to set up a batch file to log any and all entries using 'remoteaccess' as a search string.

Any ideas?

Thanks
Do you need remote access?
Now I am not saying you are a dummy... but
How to Disable Windows Remote Assistance
By Dan Gookin from Troubleshooting Your PC For Dummies, 3rd EditionI'd SUGGEST turning remote access off...Quote

I have had unauthorized visitors in my computer that got in using Windows XP Remote Access software. I've eliminated their entries in the Win Registry.

I also agree that it should be shut off as the fix. However there are other exploits out there other than the Windows XP Remote Access that can also give them remote access. A great free tool to use for home USERS is Secunia PSI. It will make you aware of any software you have that should be updated or is open to attack from hackers etc. http://secunia.com/vulnerability_scanning/personal/ I use this on my systems to keep track of what software I have installed may require security patches etc beyond the regular Windows Updates etc.

I provides you with threat levels to know just how open to vulnerability something is as well as allows you to actually patch some of the software requiring patches directly through the user interface.

Some software I have is no longer supported by the mfr with patches and so I get my weekly pop up that shows I am at a score of 87% protection because of these old programs that I still have on my system that have known exploits. But these exploits are low risk to me behind firewalls and a good antivirus. If I uninstalled the software that is popping up as potential security threats, I'd have a score of 100%, but I chose to keep the 3 programs installed.Quote from: Gliq on May 14, 2013, 04:47:55 PM
I have had unauthorized visitors in my computer that got in using Windows XP Remote Access software. I've eliminated their entries in the Win Registry.

The risk is that they installed other trojan and backdoor software while they were in.Thanks for all your help. To summarize my response...

I've been attacked several times by a proxy server company (or more likely, its hacker assets).

I've gone far beyond just clicking the Windows software boxes to disable Remote Assistance and Remote Desktop.

I've written a batch file to check if recimbly.exe and RCP.exe are in the system32 and system32/dllcache FOLDERS. If so, I have a batch file to delete them if they are.

Just today, I exported a registry from one of my three computers and found a list of (probably) 15,307 websites that my attacker enters into the zonemap areas of my machines (there are two of those zonemap areas).

I'm going to remove these in my "textpad" app (advanced notepad) and will attempt to import them with HOPE that they will be gone.

As far as an intruder having set up something else, I have no sign of any activity at the moment, so hopefully I don't. I will be going to Win7 and Linux before April 8th, 2014 (D-Day for XP) so I hope I will make it till then.

Thanks again for the replies.If you have the XP installation CD or system recovery set, I'd wipe the system clean and enable all protection just to make sure there is no more back doors.

I use to run/host honeypots to bait hackers to systems that looked important, looked like a company server etc with a bunch of data that looked important but was fake, and I use to look at their methods on the honeypots that they didnt know where honeypots. I ended up stopping the honeypot project though when one of the hackers tried to make my honeypot a relay location for downloads. I had a ghost image for my honeypots so that after they played in my honeypot sandbox, I could wipe it clean and set it up as a trap for the next hacker. It was fun until one decided to try to make it a relay for most likely illegal content sharing. I stopped baiting with honeypots when I realized that their actions could get me in hot water with illegal file sharing, even if it was only live for a few hours until I killed it to wipe it clean and set it back up again. Hosting Honeypots is just asking for trouble, which I dont need!
6727.

Solve : IPconfiguration script working on Windows 7 but not XP...?

Answer»

Hello, and thankyou for being here, there aren't a lot of live forums which still support batch scripting, so im gonna post it right away, so the main problem that is i needed a script which shows the active network adapters, then lists them gives'em ID so a user can enter the ID and then get's asked for what kind of a setup he wants, DHCP y/n, then if DHCP it configures adapter X for dhcp if not runs a next question and lists all bat files(profiles) in the same directory except the one running now. so the thing is IT works on Windows 7... what i need is a fix for it, or a XP revision so it works under XP sp3

the script
Code: [Select]@ECHO OFF
ECHO.
ECHO Choose the interface (input the id):
ECHO.
setlocal EnableDelayedExpansion
FOR /F "tokens=1,5,*" %%A IN ('netsh int ipv4 show interfaces') DO (
SET initString=%%A
REM These next three lines just format the output table nicely,
REM they will be explained later.
call :strlen resLen !initString!
call :getNiceString resultString !resLen! 5 !initString!
ECHO !resultString! %%B %%C
)
ECHO.
set /P INTID=Type interface ID: %=%
ECHO.
ECHO Do you want DHCP? (y/n)
ECHO.
set /P answer=Type answer: %=%
ECHO.

if "%answer%"=="y" (

REM configure IP and DNS for the given DHCP
netsh int ipv4 set address %intID% dhcp
netsh int ipv4 set dns %intID% dhcp
) ELSE (
ECHO Choose your configuration file:
set /a var=1
REM list the files in the directory which contain ".bat" in their names
REM and save them in an array (there are no arrays in batch scripting), explained later.
FOR /F %%F IN ('DIR /B /oN^|FIND /i ".bat"') DO (
REM check that the file being listed is not the running file
if /I "%%F" NEQ "%~nx0" (
set __Files.!var! = %%F
ECHO !var! - %%F
set /a var = !var!+1
)
)
ECHO.
REM Ask for the file number
set /P file=Type file number: %=%
ECHO.

REM this might seem confusing at first. The SET __Files.X command
REM where X is a number, returns a line similar to this:
REM __Files.X = some_value. And because "some_value" is what matters,
REM we need to split that line in two tokens. How to do it:
FOR /F "tokens=2* delims=.=" %%A IN ('SET __Files.!file!') DO (
ECHO Starting profile %%B
START %%B %intID%
ECHO Profile %%B succesfully started.
)
)
endlocal
pause
goto :eof

REM the following portion of code is here just to print things nicely
REM gets the necessary number of spaces to add to a string and returns
REM the value in the first parameter.
:getNiceString <resultString> <strLength> <resultLength> <initString>
(
set /a diff = %~3 - %~2
set resString=%~4
FOR /L %%i in (1,1,!diff!) DO (
REM note the space at the end of the following line
set resString=!resString!
REM right here ^
)
set "%~1=!resString!"
exit /b
)

REM gets the LENGTH of a string VARIABLE
:strlen <resultVar> <stringVar>
(
set string=%~2
set len=0
:loop
if "!string!" NEQ "" (
set string=!string:~1!
set /a len=!len!+1
goto loop
)
)
(
set "%~1=%len%"
exit /b
)
taken from http://ricardo.szyfer.com/I would go through and test the different commands that you USE on XP. That way you will know exactly what part of the program is causing the error. Then you can look into checking up on what the command does, and if there is a different command that is XP compatible that you COULD use.

I would start with the odd ones like netsh.


You could also add pauses between the different blocks. Then run and count how many pauses happen before the crash. This will help you to narrow the error down to a single line or for loop.Quote from: tixed on May 16, 2013, 11:56:20 AM

Hello, and thankyou for being here, there aren't a lot of live forums which still support batch scripting
Define a lot. I belong to at least 6 forums that all support batch scripting.Quote from: tixed on May 16, 2013, 11:56:20 AM
taken from http://ricardo.szyfer.com/
Nice that he took the time to write that but there are plenty of free programs out there that will run in the task tray and you can setup predefined network profiles and switch to one with two mouse clicks.
http://www.snapfiles.com/get/netsetman.htmlXP doesn't support the Netsh command which is the first external file used.

Code: [Select]c:\XP Box>netsh int ipv4 show interfaces
The following command was not found: int ipv4 show interfaces.
okay, im no expert in BATCH scripting, and the author tried to fix it but, as we know many infrastructures still use XP, so im still diging thru, and yes im trying to post everywhere i know, so maybe someone has a global idea how to solve this FOR XP.
Quote from: Squashman on May 16, 2013, 07:00:39 PM
Define a lot. I belong to at least 6 forums that all support batch scripting.

Some time before there were even 3 forums in my native language, now everyone is obsessed with newer win versions...

Now im thinking maybe this can be done for both WinXP and Win7 through VBscript call ?
6728.

Solve : Command prompt shortcut not taking variable.?

Answer»

Hello,

I have created a command prompt shortcut that launches with a string of commands in addition to prompting for user input - however it is not accepting my variable. Could someone please assist me with a solution.
The same code works in a batch and I have my reasons for using a shortcut RATHER than an actual batch.

Any help would be greatly appreciated.


Here is my code:

C:\Windows\System32\CMD.exe /k @ echo Address? & set /p Address= & ping -t %Address%
Hello,

In further investigating the issue it appears the set command is taking my variable - however it seems the final command is not interpreting the variable. It is my GUESS quotation marks are needed somewhere in the final command and I have tried them in various places but have had no luck - below is the output when the shortcut is run - additionally I polled the variable in the same cmd instance to show the set command took.

Code again:
C:\Windows\System32\cmd.exe /v:on /k @ echo Address? & set /p address= & ping -t "%address%"

Output:

Address?
127.0.0.1
Ping request could not find host %address%. Please check the name and try again.


C:\Windows\system32>ping -t %address%

Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
^C
C:\Windows\system32>

Apologies for double posting.

Thank you for any assistance."C:\Windows\System32\cmd.exe /k @ echo Address? & set /p Address= & ping -t %Address%"
Could try using " " as shown above to see if that helps as for spaces could be the issue. Unable to test from work computer.

Hello,

Thank you for your reply.
When I encapsulate the entire string in quotes I receive an error that the path, file name, etc is invalid - basically the target becomes invalid.

I appreciate your effort.

I cant be certain but I think the quotes would wrap something - somewhere in the last command.

Also disregard the /v:on switch in my last post - I was pot shotting on my own.

Regardsyou cannot use set /p to get user input and use that variable in the same line like you are doing. The shell doesn't work like that.
I can't get it to work like that either.

With delayed expansion you can set a variable and echo it in the same line - but it just doesn't seem to play right on the command line side of things.

Code: [Select]@echo off
setlocal ENABLEDELAYEDEXPANSION
set /p "var=Enter TEXT: "&echo !var!
PAUSE Thank you all for your replies. Salmon, judging from my output - I think your right - thank you. Since your post I have tried to add in a break or some other line command magic to simulate a line break but so far have had no luck. You did at least discover my problem.

Thank you again.This may be some use; it creates & runs a batch script in the system temp folder; I can't make it delete the batch after you interrupt ping -t with CONTROL-C

Shortcut target:

C:\Windows\System32\cmd.exe /k @echo @echo off > "%temp%\mytemp.bat" & echo set /p Address="Address? " >> "%temp%\mytemp.bat" & echo ping -t %Address% >> "%temp%\mytemp.bat" & "%temp%\mytemp.bat"Thank you Mr. Trout - I had thought of going that route also. The problem is I work from a corporate laptop and it is pretty picky about batch files (among other things) from being created or executed under my user. This is my main reason for doing this as a shortcut. I almost had it. Like you said - it does take my variable - it just doesnt like to use the variable on the same line - until i can find a way to trick into thinking there is a line break, I will just have to re-enter the ping command on a new line for the time being.

In my line of work I ping routers many times a night and the fewer key strokes or clicks the better. My premise was to copy the ip, launch the shortcut, paste the ip, and a control+c to stop. That's it - from there I either fix the problem remotely or wake up someone who makes more money than I do.

Many thanks for your help just the same.Can you create a shortcut to run in your profile folder, and open a cmd prompt.
Create a second shortcut called a.lnk in your profile folder with a command line of ping -t %a%

When you start the first shortcut type set a=192.168.1.1 where you paste the ip address
and then type a.lnk to launch the link, which may then ping the IP address if it inherits the environment from the cmd prompt.

If it doesn't get a copy of the enviroment then setx can set a master enviironment variable - if you have access to it.

Just thinking out loud here...I tested it and it does work, but it's not saving keystrokes.

You could have a shortcut to a cmd prompt and just type ping -t and paste your IP address in.Are you able to add an executable to your desktop, and create a shortcut to it?

This 7kb executable is a compiled Purebasic script - see below in blue. It gets an IP address and launches ping -t with the IP address.

http://www.astronomy.comoj.com/p.exe


OpenConsole()
Print("Enter an IP address or URL: ")
a$ = Input()
result = RunProgram("ping.exe","-t "+a$,"")

6729.

Solve : Schedule One Time Task with SchTasks?

Answer»

I need to be able to schedule a task from a batch file that I run using SchTasks. BUT . . . heheh . . . I need the task to run on startup - once, and then delete itself.

The task will be set to run on Server 2003 and Server 2008R2 machines. The command line switch for a task to delete itself doesn't work on "startup" TASKS because they run at EVERY startup, not just one time. What I think I need is a "run once" task that is set to run 10 minutes after the task is created.

Here's how it would work:

SCRIPT does a bunch of things
Script creates task for 10 minutes from now
Server is rebooted
Server comes back online
Task executes

Can it be done? How do I do it? I've EXPERIMENTED a little with trying to set a variable equal to time +10, thinking that I could specify the variable in the schtasks time parameter but I can't figure out how to add 10 to "time" . . . Any ideas?


Thanks for the help,

MJQuote

Here's how it would work:

Script does a bunch of things
Script creates task for 10 minutes from now
Server is rebooted
Server comes back online
Task executes

This can be done, through a series of batches all calling and removing each other from startup, and here is how I have done it before.

Start batch#1 which runs stuff at the get go and then has a SLEEP timer which gives you your 10 minute delay you need before the next event triggers. This batch completed its sleep delay and then copies Batch#2 to startup folder of system, system reboot is passed, and system reboots and now automatically triggers Batch#2 as part of startup. Batch #2 now calls for Batch # 3 which runs the final chunk of whatever needs to be done and then batch # 3 performs a final cleanup that deletes Batch # 2 from startup. Startup is now empty of any batches and process is complete.

Dave - thanks for the fast reply. I may have misunderstood what you wrote but the startup I was referring to was system start. The scheduled task should execute on system start and then delete itself. I don't intend to log into the servers.

So since scheduling a task to run at system start precludes me from being able to have the task delete itself I think I need to schedule a task to run once (because these types of tasks can delete themselves) but at a time that is 10 minutes from when the task is created.

Is it possible to do this? Is it possible to query the time add 10 minutes and set the new time equal to a variable that can be passed to the schtasks command?

Thanks,

MJAfter a bit of searching I found this:

Code: [Select]@echo on
for /F "tokens=1-3 delims=:." %%a in ("%time%") do (
set Hour=%%a
set Minute=%%b
set Seconds=%%c
)
::Convert HH:MM to minutes + 10
set /A newTime=Hour*60 + Minute + 10
rem Convert new time back to HH:MM
set /A Hour=newTime/60, Minute=newTime%%60

::rem Adjust new hour and minute
if %Hour% gtr 23 (set Hour=0) ELSE (IF %Hour% lss 10 set Hour=0%Hour%)
if %Minute% lss 10 set Minute=0%Minute%
Set TaskTime=%Hour%:%Minute%:%Seconds%
Echo %TaskTime%
I will use the TaskTime variable to schedule the task LIKE this:

Code: [Select]Schtasks /create /ru "System" /s localhost /tn "My Task" /tr "<path to my script>" /sc once /st %TaskTime% /F /V1 /Z
Note, the /V1 switch in the the Schtasks command is not needed for Server 2003.

why not use the runonce registry optionSquashman - RunOnce is executed upon login. I don't want to have to log into the server for the script to execute. Thanks anyway!
6730.

Solve : How can I count the restart cycle in a batch file??

Answer»

I would like to run a batch file which does a sequence of operations and then restarts the PC. This is one restart cycle. I hope to do the restart cycle 100 times. How can I count the restart cycles? Thanks.You have to create a file with a number in it. Start with zero.
Just after the reset open the file and INCREMENT the number my one.
When the number ion the file is equal to 100, stop the cycle.

I would suggest you test it first with a smaller number.just to see how it works.
Ya, that is what I figured to do. But it expands to several issues which I don't KNOW how to do it in DOS Command:
1. How to read a file content?
2. How to increase it number string?
3. How to check if the string is equal to 100?
Could you help me?1. How to read a file content?

Assuming the file contains just a number.

for /f "delims=" %%a in ('type "file.txt" ' ) do SET num=%%a

2. How to increase it number string?

set /a num=num + 1
>"file.txt" echo %num%


3. How to check if the string is equal to 100?

if %num% EQU 100 echo I'm finished!I verified it. Thanks a lot.
BTW, how can I read user input from keyboard into a VARIABLE? Thanks.Code: [Select]set "var="
set /p "var=Enter your reply: "
echo "%var%"Thanks.

6731.

Solve : URL file shortcut?

Answer»

"I have files saved from my schools site, they are saved as URL shortcuts, due to the content being REMOVED from the site I can not access the files, is there ANYTHING I can do?"CONTACT the IT people at the school...
You should have saved the files to your PC INSTEAD of just the shortcuts...

6732.

Solve : Script that executes steps (takes action) if IP address is correct?

Answer»

I wrote a script that installs program updates based on a number of criteria including which DATA center the server is located in. However the script doesn't SEEM to determine the data center properly.

The following line is supposed to check the first two octets of the IP address and if they are found goto the "ProxyOff" section of the script to disable the proxy server settings so the Internet is accessible.

Code: [Select]ipconfig | findstr "10.64" & IF %ERRORLEVEL% == 1 GOTO PROXYOFF
I noticed that this wasn't running reliably so I rewrote the above for testing:

Code: [Select]ipconfig | findstr "10.64" & echo %ERRORLEVEL%
Whether I use find or findstr the results are the same.
Whether I use 10.64, 10.14, 10.44, etc. the error level is always the same.

The expected result is:

If the ip address starts with 10.64 goto Proxyoff
If the ip address starts with 10.14 goto Proxyoff
If the ip address starts with 10.44 goto Proxyon

What do I need to change for find or findstr error level to play nice?

Thanks for the help,

MJ

(1) The errorlevel from a command is only available after the line has run. You can't capture it on the same line using &, unless you use delayed expansion.
(2) The errorlevel after a successful find is 0 (zero).

This does not show the errorlevel correctly:

wrong.bat

echo off
setlocal enabledelayedexpansion
echo find "%2" in "%1"
echo %1 | findstr "%2" >nul & echo errorlevel=%errorlevel%


This shows the errorlevel correctly:

right1.bat

@echo off
echo find "%2" in "%1"
echo %1 | findstr "%2" >nul
echo errorlevel=%errorlevel%


This also shows the errorlevel correctly:

right2.bat

@echo off
setlocal enabledelayedexpansion
echo find "%2" in "%1"
echo %1 | findstr "%2" >nul & echo errorlevel=!errorlevel!

C:\>wrong.bat catalog cat
find "cat" in "catalog"
errorlevel=0

C:\>wrong.bat catalog dog
find "dog" in "catalog"
errorlevel=0

C:\>right1.bat catalog cat
find "cat" in "catalog"
errorlevel=0

C:\>right1.bat catalog dog
find "dog" in "catalog"
errorlevel=1

C:\>right2.bat catalog cat
find "cat" in "catalog"
errorlevel=0

C:\>right2.bat catalog dog
find "dog" in "catalog"
errorlevel=1

You can however use if errorlevel

This will check the errorlevel correctly but it will also match 201.123.110.643

Code: [Select]ipconfig | findstr "10.64" & IF ERRORLEVEL 1 GOTO PROXYOFF
You need to parse the entire IP address and then check for the *first* two octets with something like this

Code: [Select]echo %ip% | findstr /r "^10\.64\." & IF ERRORLEVEL 1 GOTO PROXYOFF Another approach would be to leave out explicitly checking the errorlevel and letting the code implicitly DECIDE if the IP mask was found.

Code: [Select]@echo off
setlocal

ipconfig | findstr /r " 10\.64\." > nul && goto proxyoff
ipconfig | findstr /r " 10\.14\." > nul && goto proxyoff
ipconfig | findstr /r " 10\.44\." > nul && goto proxyoff
::
:: fallthru logic GOES here
::
goto :eof

:proxyoff
::
:: proxyoff logic goes here
::

The redirection to nul keeps things neat, but you can remove it.

My 2¢ 10¢ worth QUOTE from: Sidewinder on May 21, 2013, 05:45:46 AM

My 2¢ 10¢ worth

I'd say that was worth a couple of dollars at least, SW.

10.44.xxx.xxx should go to proxyon though...





Salmontrout, THANK YOU!

That did the trick. Was able to test this morning and everything worked as it should. Is it possible to do something like this:

If Errorlevel 0 in (ipconfig | findstr "10.64" > NUL) GOTO ?

I just refreshed my screen and saw more replies. I'm interested in what Sidewinder posted too. What does Code: [Select]&& do?


Thanks again,

MJQuote
What does && do?

Do you want to handle that, SW?
Quote
Do you want to handle that, SW?

Haven't got a clue


The symbol && is used to execute the code to the right of the symbol if the instruction immediately preceding the symbol is true.

Code: [Select]ipconfig | findstr /r " 10\.64\." > nul && goto proxyoff

In this case the goto is executed if the findstr instruction is true, meaning the IP pattern (" 10\.64\.") has been found.

If you are interested, there is an inverse notation || , which is used to execute the code to the right of the symbol if the instruction immediately preceding the symbol is false.

Put another way, the && and || operator are errorlevel tests.

command1 && command2
this line runs command1 and if the errorlevel from command1 is equal to 0 (zero), then it runs command2.

command1 || command2
this line runs command1 and if the errorlevel from command1 is NOT equal to 0 (zero), then it runs command2.
(note: "not equal to zero" - not just greater than zero; less than zero also. Some programs return negative errorlevels.)

You can do stuff with brackets as well

command1 && (
echo no error
some other code to execute if there was no error
...etc
)

You can combine && and ||
if you do this put the && test first.

command1 && (echo no error) || (echo an error)

command1 && (
echo no error
echo That's right, no error
) || (
echo an error
echo Yup, an error
)

In fact with a little thought you can do away with GOTOs and labels.



http://judago.webs.com/batchoperators.htmnice pageI use FOR with the netsh command to find a host's own IP address and then it can be used again to isolate the first two octets

@echo off
set mycommand=netsh interface ip show addresses "Local Area Connection"
for /f "tokens=1-3 delims= " %%A in ('%mycommand% ^| find "IP Address:"') do set hostIP=%%C
for /f "tokens=1-4 delims=." %%A in ("%hostIP%") do set first2octets=%%A.%%B
if "%first2octets%"=="10.64" goto Proxyoff
if "%first2octets%"=="10.14" goto Proxyoff
if "%first2octets%"=="10.44" goto Proxyon
This is fantastic! Excellent information. Thank you everyone!Quote from: Salmon Trout on May 22, 2013, 12:26:31 PM
I use FOR with the netsh command to find a host's own IP address and then it can be used again to isolate the first two octets

@echo off
set mycommand=netsh interface ip show addresses "Local Area Connection"
[snip]

That relies on the network adapter name and in my case it gives the Virtualbox IP address, and not my internet connection.

If the OP wants to get his internet facing IP address then this is one way, relying on an external website to report the information.

Code: [Select]@echo off
>"%temp%\ip.vbs" echo Set objHTTP = CreateObject("MSXML2.XMLHTTP")
>>"%temp%\ip.vbs" echo Call objHTTP.Open("GET", "http://astronomy.comoj.com/ip.php", False)
>>"%temp%\ip.vbs" echo objHTTP.Send()
>>"%temp%\ip.vbs" echo wscript.echo objHTTP.ResponseText

for /f "delims=" %%a in ('cscript /nologo "%temp%\ip.vbs"') do (
if not defined ip set ip=%%a
)
echo %ip%
pause


6733.

Solve : XCOPY - Script runs first line repeatedly, does not copy and does not end.?

Answer»

XCOPY - Script runs first line repeatedly, does not copy and does not end.

Here is the script
XCOPY C:\Test C:\Test2 /e /d /f /y
@ECHO Transfer COMPLETE
@PAUSE

This is the output
C:\>XCOPY C:\Test C:\Test2 /e /d /f /y
C:\>XCOPY C:\Test C:\Test2 /e /d /f /y
C:\>XCOPY C:\Test C:\Test2 /e /d /f /y
C:\>XCOPY C:\Test C:\Test2 /e /d /f /y
C:\>XCOPY C:\Test C:\Test2 /e /d /f /y
C:\>XCOPY C:\Test C:\Test2 /e /d /f /y

This goes on until I terminate the script.

Thank you for your input! This is Windows XP Home 2002 SP2 Just a thought, but is the name of your script XCOPY? Duplicating NT COMMAND names LEADS to PROBLEMS. Try renaming your script.

Wow! That was it. Thank you Sidewinder!

6734.

Solve : Make Move Merge & Rename files into directories based on file-name / Bash to DOS?

Answer» LINUX BASH SCRIPT
Makes directories from a predefined part of the file-name and moves/merges them into their corresponding defined folder.
IF the folder and file already exists, it will merge the file into the pre-existing folder and create a incremental numbered tag at the end of filename (c#).
No files are over written.

INPUT: Filename Pattern
Field1 - Field2.ext
Field1 - Field2 - Field3.ext
Field1 - Field2 - Field3 (tag).ext
Field1 - [Field2] - Field3.ext
Field1 - [Field2] - Field3 (tag) (tag2).ext


Deliminators: dash, square BRACKET (optional) and parenthesis. These are designated and NOT used elsewhere in FIELD names.
Field: The field can contain any of the following: alpha-numerics, apostrophe, ampersand and decimal point. No other special or foreign characters.


Code: [Select]#!/bin/bash
for i in $(ls | sed 's/ /~/g'); do
FILENAME=$(echo "$i" | sed 's/~/ /g')
if ! [ -d "$FILENAME" ]; then
AUTHORNAME=$(echo "$FILENAME" | awk -F"-" '{ print $1 }' | sed -r 's/ +$//g')
if ! [ -d "$AUTHORNAME" ]; then
mkdir "$AUTHORNAME"
fi
COUNT=1
EXTENSION=$(echo "$FILENAME" | awk -F. '{ print $NF }')
NEWNAME=$(echo "$FILENAME" | sed -r "s/\.$EXTENSION$//g")
TEMPNAME=$NEWNAME
while [ -e "$AUTHORNAME/$NEWNAME.$EXTENSION" ]; do
NEWNAME="$TEMPNAME(C$((COUNT++)))"
done
mv "$FILENAME" "$AUTHORNAME/$NEWNAME.$EXTENSION"
fi
done
OUTPUT:
John Doe/
John Doe - bbb.ext
John Doe - aaa - bbb.ext
John Doe - aaa- bbb(tag).ext
John Doe - [aaa] - bbb.ext
John Doe - [aaa] - bbb (tag) (tag2).ext

Linux users, this bash script WORKS like a dream.

ISSUE:
My husband was kind of enough to write this script for me in Bash (Linux). It works great in Linux, but I need Cygwin to run it in Windows and it's SLOW and buggy.

Salmon Trout posted this DOS Batch on a similar Topic: Create folders based on part of filename dated June 22, 2012. which does close to what I want, but makes no concession for merging duplicate file names and renaming them.

DOS BATCH:

Code: [Select]for /f "delims=" %%A in ('dir /b /a-d ^| find /v "%~nx0"') do (
for /f "tokens=1* delims=-" %%B in ("%%A") do (
if not exist "%%B" md "%%B"
if not exist "%%B\%%A" move "%%A" "%%B"
)
)

I would like help in expanding this DOS batch to include merging and renaming files if they exist -- much like my Bash Script. My programming skills are limited to simple regular expression. Basically, I wish to convert my Bash to DOS.

_______________________________________ ______
PC: Running Windows 7 Home Edition 64 bit / 16 GB RamThe task is unclear, to me at least. You wish to move files from somewhere to somewhere else and not overwrite any files. Does it include subdirectories?

Give some examples of the source files and the target files, which should clarify the task.The bash script does the following...

BEFORE:

J.R.R. Tolkien - Lord of the Rings 01 - The Hobbit.pdf
J.R.R. Tolkien - Lord of the Rings 02 - Lord of the Rings.txt
J.R.R. Tolkien - Beowulf, The Monsters and the Critics (html).rarx
William Shakespeare - A Midsummer Nights Dream.epub
William Shakespeare - Alls Well That Ends Well.epub
William Shakespeare - Twelfth Night.epub
William Shakespeare - Venus And Adonis.epub


AFTER:

J.R.R. Tolkien/
J.R.R. Tolkien - Lord of the Rings 01 - The Hobbit.pdf
J.R.R. Tolkien - Lord of the Rings 02 - Lord of the Rings.txt
J.R.R. Tolkien - Beowulf, The Monsters and the Critics (html).rar

William Shakespeare/
William Shakespeare - A Midsummer Nights Dream.txt
William Shakespeare - A Midsummer Nights Dream.epub
William Shakespeare - Alls Well That Ends Well (2ed).epub
William Shakespeare - Twelfth Night.epub
William Shakespeare - Venus And Adonis (c1).epub
William Shakespeare - Venus And Adonis (c2).epub
William Shakespeare - Venus And Adonis.epub
William Shakespeare - Venus And Adonis.jpg


In cases where the folder already exists the files are move into the existing folder.
In cases filename already exists the files are rename with an incremental tag to avoid conflict. i.e. (c1), (c2)This seems to work
Code: [Select]@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%A in ('dir /b /a-d') do (
for /f "tokens=1 delims=-" %%B in ("%%A") do (
set b=%%B
if not "%0"=="!b:~0,-1!" (
echo %%B
if not exist %%B md %%B
move "%%A" "!b:~0,-1!\%%A"
)
)
)
pause
This task is complicated by the need to rename and add a suffix - and that suffix has to be removed to compare further similar files.

However this seems to work here in my test. Try it on copies of your files first.
The source filespec can simply be *.* and the target is where your folders are to be CREATED and could be simply books to move into a books folder in the current directory.

Code: [Select]@echo off
set "source=d:\abc\*.*"
set "target=d:\abc\books"
md "%target%" 2>nul
FOR %%a in ("%source%") do call :next "%%a"
pause
goto :eof
:next
for /f "delims=-" %%b in ("%~n1") do set "folder=%%b"
if "%folder%"=="%~n1" goto :EOF
if "%folder:~-1%"==" " set "folder=%folder:~0,-1%"
md "%target%\%folder%" 2>nul
set c=-1
set "name=%~n1"
:: remove existing " (cNNN)"
echo "%name%|" |findstr /r /c:" (c[0-9]*)|">nul && call :remove

:loop
set /a c=c+1
set num= (c%c%)
if %c% EQU 0 (set num=)
if exist "%target%\%folder%\%name%%num%%~x1" goto :loop
echo processing %1
MOVE /-Y "%~1" "%target%\%folder%\%name%%num%%~x1" >nul
goto :EOF


:: Search and Replace - strings
:remove
call :Search_and_replace "%name%"
for /f "delims=" %%c in ('cscript /nologo _.vbs') do set "name=%%c"
)
del _.vbs
goto :EOF

:Search_and_replace
set s=regex.replace("%~1","$1")
>_.vbs echo set regex=new regexp
>>_.vbs echo regex.global=True
>>_.vbs echo regEx.IgnoreCase=True
>>_.vbs echo regex.pattern="(.*) \(c[0-9]*\)"
>>_.vbs echo wscript.stdOut.write %s%

First, a 'thank you' both, your help is greatly appreciated. I pressed your buttons.

Foxidrive's batch works like a charm. I even tweaked a copy so it can run on the root directory of the batch file. I now have a choice and flexibility; one for my LIBRARY folder with targetand source set and one portable for drag-n-drop.

Foxidrive's Tweaked Version: No target or Source: runs on root of batch file.
Code: [Select]@echo off
FOR %%a in ("*.*") do call :next "%%a"
pause
goto :eof
:next
for /f "delims=-" %%b in ("%~n1") do set "folder=%%b"
if "%folder%"=="%~n1" goto :EOF
if "%folder:~-1%"==" " set "folder=%folder:~0,-1%"
md "%folder%" 2>nul
set c=-1
set "name=%~n1"
:: remove existing " (cNNN)"
echo "%name%|" |findstr /r /c:" (c[0-9]*)|">nul && call :remove

:loop
set /a c=c+1
set num= (c%c%)
if %c% EQU 0 (set num=)
if exist "%folder%\%name%%num%%~x1" goto :loop
echo processing %1
MOVE /-Y "%~1" "%folder%\%name%%num%%~x1" >nul
goto :EOF


:: Search and Replace - strings
:remove
call :Search_and_replace "%name%"
for /f "delims=" %%c in ('cscript /nologo _.vbs') do set "name=%%c"
)
del _.vbs
goto :EOF

:Search_and_replace
set s=regex.replace("%~1","$1")
>_.vbs echo set regex=new regexp
>>_.vbs echo regex.global=True
>>_.vbs echo regEx.IgnoreCase=True
>>_.vbs echo regex.pattern="(.*) \(c[0-9]*\)"
>>_.vbs echo wscript.stdOut.write %s%

6735.

Solve : Delete files taht are not AVI?

Answer»

A paid service downloads video files in AVI format. Along with the videos come other files that are no longer needed after the download is finished.
How can a simple script delete just the files that are not of type nAVI in the sub folders in the download directory.?
I'd just perform the following

COPY or MOVE your *.AVI files to a different directory. * I like copying vs move, but if your tight on hdd space you can tell it to move the files instead of making a 2nd copy at the alt location.

DELETE all contents at thisoriginal directory that the AVI's were copied or moved from, you can then copy or move your AVI files back to original directory or keep them at this AVI only alternate directory.

This run from the location that the AVI's reside would create a copy of them as well as any subfolders containing them and only AVI files to be copied to an alternate location such as C:\my_AVIs\ . I would create this drop directory before running this instruction so that the location to copy files to is satisfied.

Code: [Select]xcopy *.avi c:\my_AVIs\*.* /s/d/yThen run

Code: [Select]erase *.* /f /q to force deletion of all files from the original location ( THIS DELETES ALL FILES from directory by which it is run without prompting to confirm you want to do this, so be careful )

If you want to be prompted you can just use Code: [Select]erase *.* /f and select Y or N to proceed

If you need to delete most data, but also keep some data at the parent directory, you would want to perform a custom deletion of file types by extensions such as if you have a parent directory with AVI , TXT, and DOC files in addition to a program with an EXE there and BIN, DLL, LOG, and other files there, you will not want to run the erase instruction above as for it would wipe out all contents and you need to retain some.

So to ditch the TXT and DOC files for example you would simply run the following:

Code: [Select]erase *.doc
erase *.txtThis one-line batch script will delete all files in its own folder that do not have the extension .avi

Save it with the .bat extension

@for %%A in (*.*) do if not "%%~xA"==".avi" del "%%A"

or open a prompt in that folder and paste this

@for %A in (*.*) do if not "%~xA"==".avi" del "%A"




Salmon Trout, great pone-line solution.
Thank you both. You have MADE my day.Quote from: Salmon Trout on May 25, 2013, 02:41:55 PM


@for %%A in (*.*) do if not "%%~xA"==".avi" del "%%A"


Add the /i switch or it will delete .AVI files or .aVi files etc. The CASE insensitive switch will fix that.

Code: [Select]for %%A in (*.*) do if /i not "%%~xA"==".avi" del "%%A"Quote from: foxidrive on May 25, 2013, 10:47:23 PM
Add the /i switch or it will delete .AVI files or .aVi files etc. The case insensitive switch will fix that.

Code: [Select]for %%A in (*.*) do if /i not "%%~xA"==".avi" del "%%A"
Cool ! Didn't know.Quote from: foxidrive on May 25, 2013, 10:47:23 PM
Add the /i switch or it will delete .AVI files or .aVi

I can't imagine that mattering.
Not mattering if it deletes your collection of AVI files?

Quote from: foxidrive on May 26, 2013, 02:22:03 AM
Not mattering if it deletes your collection of AVI files?

Of course... I posted UNTHINKINGLY... a very good point. You can force lower case with a rename of the extension.
But then it would not be a one-liner.

rename *.AVI *.avi
Quote from: Geek-9pm on May 26, 2013, 09:48:47 AM
You can force lower case with a rename of the extension.
But then it would not be a one-liner.

rename *.AVI *.avi

As the REN command ignores case, we can protect the avi files with a temporary dummy extension, and then rename back, forcing every .avi extension to a chosen case. In this example it is lower case. It will all go in one line.

in a batch...

ren *.avi *.avi$$$ & for /f "delims=" %%A in ('dir /b *.* ^| find /v "%~nx0"') do if not "%%~xA"==".avi$$$" del "%%A" & if exist *.avi$$$ ren *.avi$$$ *.avi

before


aaaaa.bat
test0.AVI
test1.Avi
test2.aVI
test3.aVI
test4.aVi
test5.aVI
test6.avi
test7.txt
test8.doc
test9.zip
testA.aaa
testB.bbb
testC.ccc

after


aaaaa.bat
test0.avi
test1.avi
test2.avi
test3.avi
test4.avi
test5.avi
test6.aviUpdate (ignores directories in the folder)
Note: batch does not delete itself

Code: [Select]ren *.avi *.avi$$$ & for /f "delims=" %%A in ('dir /b /a-d ^| find /v "%~nx0"') do if not "%%~xA"==".avi$$$" del "%%A" & if exist *.avi$$$ ren *.avi$$$ *.aviYour original suggestion with case insensitive switch will work fine, except it will delete the bat file. This should cater for that.

Code: [Select]for %%A in (*.*) do if /i not "%%~nxA"==%~nx0" if /i not "%%~xA"==".avi" del "%%A"
6736.

Solve : How can I find and replace text inside a xml file using bat process?

Answer»

Hi guys, what's up?

Well, I did find a post here in the forum about this question, quite similar to what I wanna do, but it's too old so I opened a new thread. so, the problem is: I have a folder with hundreds of XML files and I WANT to replace text inside them, in this CASE 076E3626449684B8D6E099B2093C5AE5 for 0ABE3626449684B8ABCDEFB2093C5AE5. And after that, I want to save the files with the original name, and if possible overwrite the files (the OUTPUT name must be the input name). Here's what I've tried:

@echo off
for /f "tokens=* delims=" %%f in ('type *.xml') do CALL :DOREPLACE "%%f"

GOTO :EOF
:DOREPLACE
SET INPUT=%*
SET OUTPUT=%INPUT:076e3626449684b8d6e099b2093c5ae5=077e3626449684b8d6e099b2093c5ae5%

for /f "tokens=* delims=" %%g in ('ECHO %OUTPUT%') do ECHO %%~g&GT;>%output.xml

EXIT /b

As you can see, the line "for /f "tokens=* delims=" %%g in ('ECHO %OUTPUT%') do ECHO %%~g>>%output.xml" generates an output file with name "output.xml". I want this name to be the same name that I receive in the input. Is it possible??

Thanks, see ya later. SED is a better tool than batch for replacing text.

Are you able to download GNUsed and USE that?

6737.

Solve : Sort Files into Folders by Artists Name?

Answer»

I have a script currently to sort all my music into Alphabetic Folders (A,B,C, ect) Most of my music is already in folders by artists name (//Queen/Bohemian Rhapsody. - Queen.mp3) However I have some unsorted mp3s in the with the same title format (Song - Artist) that I would like to put into directories by the artists' name. I cannot solve this for the life of me. I can put them into directories with the last letters of the file name but the length VARIES so I might get directories named "sody - Queen" instead of just "Queen" I'm pretty novice user of batch files but I'm trying to get better I just got caught up on this problem which I hope there is a solution to.

Code: [Select]for %%FI in (*.mp3) do (
set file=%%~nFI
set folder=!file:~-8!
if not exist !folder! md !folder!
move "%%~J" "!folder!"
)
I got this PIECE of code from this website of someone with a different problem and it works well but like I said the Artist's name will vary so it doesn't work like I need it to.This expects a format of "song - artist.mp3" and it creates a bat file for you to examine and edit if necessary.

Open file.bat in notepad to check it before using it.

If the song name contains a - character then it will need editing.
If there are two or more spaces before the artist name then it will need editing.



Code: [Select]@echo off
for %%a in (*.mp3) do for /f "tokens=1* delims=-" %%b in ("%%a") do CALL :next "%%a" "%%~nc"
goto :EOF
:next
set "folder=%~2"
if "%folder:~0,1%"==" " set "folder=%folder:~1%"
>>file.bat echo md "%folder%" 2^>nul ^& move "%~1" "%folder%"
goto :EOF
Wow thank you works like a charm. Especially because all my files are always song - artist.

Edit: When I put it in with the REST of my code it only works for the first file and that's it. The other file(s) are unaltered. I assume I could run it as a separate file but it would be MUCH better if I could run it in my main batch file.

Edit 2: I'm assuming this has a loop that's not able to loop when its part of a bigger file because instead of "goto EOF" I had it exit and it only created the one folder standalone.Quote from: NehpetsDoom on May 27, 2013, 11:11:23 PM

Edit: When I put it in with the rest of my code it only works for the first file and that's it. The other file(s) are unaltered. I assume I could run it as a separate file but it would be much better if I could run it in my main batch file.

It calls a subroutine. If you show us your main batch file then it should be able to be added.
6738.

Solve : Commands about file checking??

Answer»

Is there any articles to explain about commands for FILE checking; such as checking if a folder is EMPTY, if a file empty, if two folders the same?'fc' is the closest thing I can think of to what you are LOOKING for. You may need to 'dir &GT;>tmp & fc tmp1 tmp2' kinda thing for your directories.You will find all those things if you google for them. here. "alt.msdos.batch.nt" newsgroup. Dostips forum. Stack Overflow forum. ss64 forum. All have examples and tips.

If you have a specific task to do then ASK for examples for that task.

6739.

Solve : How to return result from sub function to caller??

Answer»

1. How to return the processing result from a called batch program to the caller?
2. How to return the processing result from a called function in the same batch file to the caller?
3. How to go back to the next line of call statement from the called function in the same batch file?For some time MS has recommended for t all users learn to use PowerShell instead of DOS for all but the most trivia things.
Quote

Getting started with PowerShell
PowerShell is Microsoft’s next generation command-line shell that helps IT guys all over the world to automate administrative tasks. If you have been around the IT business as long as I have you have properly made a lot for BAT files and batch programming to simplify and automate IT tasks. You properly also know that in the year 2011 it is quiet limited what you can do with batch programming in Windows operating systems. It is a very limited set of tools we have. You can’t even access the registry. With PowerShell Microsoft has made a brand new shell that gives us all the possibility we could wish for (Registry access, WMI, Windows processes, Services ETC.). In this little intro to PowerShell I will show you what kind of THINKS you EASILY can do with PowerShell even if you have not worked with it before. ...
http://www.techwork.dk/tools/windows-powershell-for-newbies
Quote from: Geek-9pm on May 28, 2013, 09:39:35 PM
For some time MS has recommended for t all users learn to use PowerShell instead of DOS for all but the most trivia things.
Quote
You can’t even access the registry.

Batch has been able to access the registry since reg.exe was created. 1. How to return the processing result from a called batch program to the caller?

set a variable or use a file

2. How to return the processing result from a called function in the same batch file to the caller?

set a variable or use a file

3. How to go back to the next line of call statement from the called function in the same batch file?

end the called subroutine with
Code: [Select]GOTO :EOF
6740.

Solve : How to check if a file is ordinary or a folder??

Answer»

As title.
Code: [Select]if EXIST "FOLDER\" echo folder exists
if exist "FILE" echo file exists

6741.

Solve : %errorlevel% will have different result in my batch file and in DOS command.?

Answer»

Below is my BATCH file for comparing two folders. I would like to compare each files under two folders to make sure they are the same. I used 'fc' to compare files and then CHECK the result. The strange thing is that I usually got non-zero %errorlevel% in this batch file when it compares two identical files. But if I did the same comparison at DOS command PROMPT, I got expected result. How come?

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:cmpdir dir1 DIR2
::
:: Func: Compare files and folders in two dir1 & dir2
::
:: Args: %1 the first folder to be compared
:: %2 the SECOND folder to be compared
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:cmpdir
:: setlocal ENABLEEXTENSIONS
@echo off

FOR /R "%1\" %%G in (*) DO (
if not exist %2\%%~nG%%~xG (
echo "%2\%%~nG%%~xG disappeared"
exit /b 255
) else (
if not exist "%1\%%~nG%%~xG\" (
echo "%1\%%~nG%%~xG compared to %2\%%~nG%%~xG"
fc /b %1\%%~nG%%~xG %2\%%~nG%%~xG
echo "errorlevel = %errorlevel%"
if %errorlevel% neq 0 (
echo "%2\%%~nG%%~xG corrupted"
exit /b 255
)
)
)To set and also expand a variable inside a code block with parentheses (such as a FOR loop or extended IF block) you need to use delayed expansion.

1. Precede code section (or entire batch) with setlocal enabledelayedexpansion
2. Use exclamation marks, not percent signs, with variable i.e. !errorlevel! not %errorlevel%

6742.

Solve : How to set result of a command into a variable??

Answer»

I would like to execute a DOS COMMAND and have its output string being SAVED into a VARIABLE in a batch file. How can I do it?for /f "delims=" %%A in ('mycommand') do SET output=%%A

6743.

Solve : Batch File to move a file Help.?

Answer»

Good Morning,

I am trying to create an installer that my clients can run that will accomplish two objectives.

Objective 1: Add a line to their hosts file to redirect their program to my server. I have accomplished this objective through the use of the code below.

Objective 2: Is beyond my current capabilities. I need to move or copy a file that they downloaded along with the executable (a converted version of the Batch file that we are discussing) regardless of it's current location to a new location and overwrite the existing file that already exists.

Ideas?

Chad

Sounds like a hack or prank or virus. Possibly not, but there are serious security implications here. Modifying the Hosts file is usually disabled for non-administrator accounts for a good REASON. If you are an IT pro, how come you don''t know that? If you aren't an IT pro, why are you doing this?

After a PM exchange with the OP I'm unlocking the thread.Quote from: Allan on August 21, 2013, 12:19:09 PM

After a PM exchange with the OP I'm unlocking the thread.

Sorry Allen I don't see that I have the option to edit my OP. Please feel free to remove any harmful content at your discretion.

My goal is to help my players get their game pointed to my server. That has all been worked out. The problem I am having is that the server name is actually client side in a file servername.dat I have a servername.dat file for my players that will display my server name "Relentless" What I want to do is provide it along with the batch file I am working on and have the batch file overwrite the default servername.dat file with mine.

I think I can do it if they were to unpack it and run it EXACTLY on the desk top and their game was installed exactly at the default location. But if something isn't at the precise location I get a LITTLE confused about what to do.

I realize I'm on a short leash here so if we want to echo to the user exactly what is taking place I'm cool with that. If you guys were willing to help, you could hold onto the script and I would just provide an executable. That way the warnings to the users could not be removed.

Chad

It's possible to search the drive for servername.dat or perhaps query the registry for it's location.

When it's found - do you want the batch file to create a new servername.dat with the required contents? I'm assuming it is a text file with several lines inside so the batch file can create a new one rather than packaging another file.

So more details are needed - registry settings etc.Thanks everyone. I decided to abandon this approach. My Antivirus software lit up like a Christmas tree during a trial run. This would cause more problems than it solves if my players had to deal with that. What approach did you use that triggered your AV program? What tool were you using - because very few batch scripts will cause any issue with an AV program.Quote from: foxidrive on August 22, 2013, 01:42:16 AM
What approach did you use that triggered your AV program? What tool were you using - because very few batch scripts will cause any issue with an AV program.

I can't answer that without going into detail about it and the moderators don't want that posted here. The AV didnt REALLY become an issue until I COMPILED the script into an executable.
6744.

Solve : turning off attributes in archive files?

Answer»

IN MY Windows CLI I am asked to turn off ATTRIBUTES for an archive file, however I have tried EVERYTHING to no avail. any help?
scenario:first > cd to companyresources directory then use "attrib/s" to display permissions in subfile
then turn off archive by attrib -A. This does not work. In the SUBFILES there are three folders same "A" sub directory with different file names. MGJ Quote from: mgjones47 on August 20, 2013, 01:46:52 PM

turn off archive by attrib -A. This does not work.

What filename did you pass it and what error MESSAGE appeared?
6745.

Solve : Syntax error on this batch file??

Answer»

Okay, so I decided to make a temperature converter between Celsius and FAHRENHEIT.
I recently found out about set /a, and wanted to use the arithmetic function to GOOD use.
When I run it, it says "Missing operand", but OTHERWISE continues the code.
So something is obviously WRONG with my math. Can someone help?
Here is the code:
Code: [Select]:A
@echo off
title Temperature Converter
set /p celorfah=Enter the degrees you are converting from [C/f]:
cls
if %celorfah%==c (
set /p celtemp=Enter the temperature in Celsius:
cls
set /a celmath1=%celtemp%*9
set /a celmath2=%celmath1%/5
set /a celtofah=%celmath2%+32
echo The temperature in Celsius is %celtemp%.
echo The temperature in Fahrenheit is %celtofah%.
echo.
pause
cls
goto A
)
if %celorfah%==f (
cls
set /p fahtemp=Enter the temperature in Fahrenheit:
cls
set /a fahmath1=%fahtemp%-32
set /a fahmath2=%fahmath1%*5
set /a fahtocel=%fahmath2%/9
echo The temperature in Fahrenheit is %fahtemp%.
echo The temperature in Celsius is %fahtocel%.
echo.
pause
goto A
)
cls
echo That isn't an option!
echo.
pause
goto AThank you!because you have the veriables being changed in an 'if' statement, you need to enable delayed expansion and change the format a little.

Code: [Select]:A
@echo off
setlocal EnableDelayedExpansion
title Temperature Converter
set /p celorfah=Enter the degrees you are converting from [c/f]:
cls
if %celorfah%==c (
set /p celtemp=Enter the temperature in Celsius:
cls
set /a celmath1=!celtemp!*9
set /a celmath2=!celmath1!/5
set /a celtofah=!celmath2!+32
echo The temperature in Celsius is !celtemp!.
echo The temperature in Fahrenheit is !celtofah!.
echo.
pause
cls
goto A
)
if %celorfah%==f (
cls
set /p fahtemp=Enter the temperature in Fahrenheit:
cls
set /a fahmath1=!fahtemp!-32
set /a fahmath2=!fahmath1!*5
set /a fahtocel=!fahmath2!/9
echo The temperature in Fahrenheit is !fahtemp!.
echo The temperature in Celsius is !fahtocel!.
echo.
pause
goto A
)
cls
echo That isn't an option!
echo.
pause
goto A

6746.

Solve : Even doing "setlocal enabledelayedexpansion", 'fc' still returned wrong value?

Answer»

Below is my program for comparing files and folders under two specified folders. It almost works well except one issue. That is, after 'fc /b' compared two different files, %errorlevel% is 0. I met the same phenomenon and it was DUE to not set "enabledelayedexpansion". This time I am sure I did it. How come?

@echo off

call :cmpdir %1 %2
if %errorlevel% equ 0 (echo two dirs are the same) else (
echo two dirs differ
)
goto :EOF

:cmpdir DIR1 dir2
setlocal enabledelayedexpansion

pushd %2
for /F "delims=" %%A in ('cd') do set dir2=%%A
echo dir2=%dir2%
popd

pushd %1
FOR %%G in (*) DO (
echo "%%~fG <<==>> %dir2%\%%~nxG"
if not exist %dir2%\%%~nxG (
echo %dir2%\%%~nxG disappeared
goto :cmpdir_err
)
setlocal enabledelayedexpansion
fc /b "%%~fG" "%dir2%\%%~nxG" > nul
if %errorlevel% neq 0 (
echo %dir2%\%%~nxG corrupted
goto :cmpdir_err
)
)
:: echo "files done, then subdir"
FOR /d %%G in (*) DO (
echo %%~fG
if not exist %dir2%\%%~nxG (
echo %dir2%\%%~nxG disappeared
exit /b 255
)
call :cmpdir %%~fG %dir2%\%%~nxG
if %errorlevel% equ 255 goto :cmpdir_err
)
:cmpdir_ok
exit /b 0

:cmpdir_err
popd
exit /b 255You don't NEED setlocal enabledelayedexpansion twice.

You did not change %errorlevel% to !errorlevel! where I have shown.

From my previous answer

Quote

2. Use exclamation marks, not percent signs, with variable i.e. !errorlevel! not %errorlevel%

You should not use :: to start a COMMENT. This is wrong and will break code blocks. Use REM.

You should start many threads which are all about the same code.

Quote from: Stan Huang on May 31, 2013, 02:23:13 AM
@echo off

call :cmpdir %1 %2
if %errorlevel% equ 0 (echo two dirs are the same) else (
echo two dirs differ
)
goto :EOF

:cmpdir dir1 dir2
setlocal enabledelayedexpansion

pushd %2
for /f "delims=" %%A in ('cd') do set dir2=%%A
echo dir2=%dir2%
popd

pushd %1
FOR %%G in (*) DO (
echo "%%~fG <<==>> %dir2%\%%~nxG"
if not exist %dir2%\%%~nxG (
echo %dir2%\%%~nxG disappeared
goto :cmpdir_err
)
setlocal enabledelayedexpansion
fc /b "%%~fG" "%dir2%\%%~nxG" > nul
if %errorlevel% neq 0 (
echo %dir2%\%%~nxG corrupted
goto :cmpdir_err
)
)
:: echo "files done, then subdir"
FOR /d %%G in (*) DO (
echo %%~fG
if not exist %dir2%\%%~nxG (
echo %dir2%\%%~nxG disappeared
exit /b 255
)
call :cmpdir %%~fG %dir2%\%%~nxG
if %errorlevel% equ 255 goto :cmpdir_err
)
:cmpdir_ok
exit /b 0

:cmpdir_err
popd
exit /b 255
That's

Quote from: Salmon Trout on May 31, 2013, 02:45:54 AM
You should not start many threads which are all about the same code.
For "You should not start many threads which are all about the same code.", do you mean that I should try to use interaction instead of recursion?Quote from: Stan Huang on June 02, 2013, 06:49:48 PM
For "You should not start many threads which are all about the same code.", do you mean that I should try to use interaction instead of recursion?

No. He means you shouldn't start multiple forum threads about the same code.
6747.

Solve : Batch file to export a .txt of the Add/Remove Programs list in Windows?

Answer»

I searched a lot for a batchfile that could export a list to a text file of all the installed programs on my machine. I want the list as similar as possible to the 'visual' list of the Add/Remove Programs in WINDOWS.

What i got till now is a batch file that export a list from 3 different registerkeys (which is suggested from search on Google to be the ones that contains all the programs). After that, I check for double lines and remove those double lines.

Finally, with the findstr option I can filter lots of updates like all the Microsoft 'KB' options out.

The batch file so far:

Code: [Select]@echo off
If Exist C:\Final.txt Del C:\Final.txt
regedit /e C:\regexport.txt "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"
regedit /e C:\regexport2.txt "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall"
regedit /e C:\regexport3.txt "HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
find "DisplayName" C:\regexport.txt > C:\regprogs.txt
find "DisplayName" C:\regexport2.txt >> C:\regprogs.txt
find "DisplayName" C:\regexport3.txt >> C:\regprogs.txt
for /f "tokens=2 delims==" %%a in (C:\regprogs.txt) do echo %%~a >> C:\installedprogs.txt
del C:\regexport.txt
del C:\regexport2.txt
del C:\regexport3.txt
del C:\regprogs.txt
sort C:\installedprogs.txt > C:\alles.txt
del C:\installedprogs.txt


:: script om alle dubbele lijnen eruit te gooien
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL EnABLEDELAYEDEXPANSION

REM -- Prepare the Prompt for easy debugging -- restore with prompt=$p$g
prompt=$g

rem The finished program will remove duplicates lines

:START
set "_duplicates=TRUE"

set "_infile=C:\alles.txt"
set "_oldstr=the"
set "_newstr=and"

call :BATCHSUBSTITUTE %_infile% %_oldstr% %_newstr%
pause
goto :SHOWINTELL
goto :eof


:BATCHSUBSTITUTE

type nul> %TEMP%.\TEMP.DAT

if "%~2"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %1|find /n /v """') do (
set "_line=%%B"
if defined _line (
if "%_duplicates%"=="TRUE" (
set "_unconverted=!_line!"
set "_converted=!_line:"=""!"
FIND "!_converted!" %TEMP%.\TEMP.DAT > nul
if errorlevel==1 (
>> %TEMP%.\TEMP.DAT echo !_unconverted!
)
)
) ELSE (
echo(>> %TEMP%.\TEMP.DAT
)
)
goto :eof


:SHOWINTELL
@echo A|move %TEMP%.\TEMP.DAT C:\allesnietdubbel.txt
del C:\alles.txt

::Alle lijnen weggooien waar 'KB' in voor komt
type C:\allesnietdubbel.txt | findstr /V KB > C:\Final.txt
goto :eof



exit
Final.txt

Code: [Select]@C:\\Program Files (x86)\\Windows Live\\Installer\\wlsres.dll,-3002
@C:\\windows\\system32\\bcmwlrc.dll,-4003
3CXPhone
64 Bit HP CIO Components Installer
ActivClient x64
ActiveCheck component for HP Active Support Library
Adobe Flash Player 10 ActiveX
Adobe Flash Player 10 ActiveX 64-bit
Adobe Reader X (10.1.1) - Nederlands
Apple Application Support
Apple Mobile Device Support
Apple Software Update
ATI Catalyst Install Manager
AVG 2011
Babylon
Babylon toolbar on IE
Belarc Advisor 8.2
Bonjour
Borland Database Engine Setup
Broadcom 2070 Bluetooth 2.1 + EDR
Broadcom 802.11 Wireless LAN Adapter
Catalyst Control Center - Branding
Catalyst Control Center Core Implementation
Catalyst Control Center Graphics Full Existing
Catalyst Control Center Graphics Full New
Catalyst Control Center Graphics Light
Catalyst Control Center InstallProxy
Catalyst Control Center Localization All
ccc-core-static
ccc-utility64
CCC Help Chinese Standard
CCC Help Chinese Traditional
CCC Help Czech
CCC Help Danish
CCC Help Dutch
CCC Help English
CCC Help Finnish
CCC Help French
CCC Help German
CCC Help Greek
CCC Help Hungarian
CCC Help Italian
CCC Help Japanese
CCC Help Korean
CCC Help Norwegian
CCC Help Polish
CCC Help Portuguese
CCC Help Russian
CCC Help Spanish
CCC Help Swedish
CCC Help Thai
CCC Help Turkish
Citrix online plug-in - web
Citrix online plug-in (DV)
Citrix online plug-in (HDX)
Citrix online plug-in (USB)
Citrix online plug-in (Web)
Citrix XenCenter
Citrix XenConvert_x64
Corel Graphics - Windows Shell Extension
Corel Graphics - Windows Shell Extension 64 Bit
CorelDRAW Graphics Suite X5
CorelDRAW Graphics Suite X5 - Capture
CorelDRAW Graphics Suite X5 - Common
CorelDRAW Graphics Suite X5 - Connect
CorelDRAW Graphics Suite X5 - Custom Data
CorelDRAW Graphics Suite X5 - Draw
CorelDRAW Graphics Suite X5 - Filters
CorelDRAW Graphics Suite X5 - FontNav
CorelDRAW Graphics Suite X5 - IPM
CorelDRAW Graphics Suite X5 - NL
CorelDRAW Graphics Suite X5 - PHOTO-PAINT
CorelDRAW Graphics Suite X5 - Photozoom Plugin
CorelDRAW Graphics Suite X5 - Redist
CorelDRAW Graphics Suite X5 - Setup Files
CorelDRAW Graphics Suite X5 - VBA
CorelDRAW Graphics Suite X5 - VideoBrowser
CorelDRAW Graphics Suite X5 - VSTA
CorelDRAW Graphics Suite X5 - WT
CorelDRAW(R) Graphics Suite X5
CuteFTP 8 Home
D3DX10
Device Access Manager for HP ProtectTools
DirectX 9 Runtime
Drive Encryption for HP ProtectTools
Energy Star Digital Logo
File Sanitizer For HP ProtectTools
FileZilla Client 3.3.5.1
HP 3D DriveGuard
HP Customer Experience Enhancements
HP ESU for Microsoft Windows 7
HP HotKey Support
HP Install Network Printer Wizard
HP Power Assistant
HP Power Data
HP ProtectTools Security Manager
HP QuickLook
HP QuickWeb
HP Setup
HP SoftPaq Download Manager
HP Software Framework
HP Software Setup
HP Support Assistant
HP User Guides 0185
HP Web Camera
HP Webcam
HP Wireless Assistant
HPAsset component for HP Active Support Library
IDT Audio
iTunes
Java Auto Updater
Java Card Security for HP ProtectTools
Java(TM) 6 Update 26
Junk Mail filter update
jZip
LightScribe System Software
LSI HDA Modem
LVI MagniLink S OCR
MagniLink Read
Mamut Business Software
Marvell Miniport Driver
Mesh Runtime
Messenger Companion
Microsoft .NET Framework 4 Client Profile
Microsoft .NET Framework 4 Client Profile NLD Language Pack
Microsoft .NET Framework 4 Extended
Microsoft Application Error Reporting
Microsoft Office 2010 Service Pack 1 (SP1)
Microsoft Office 2010 voor Thuisgebruik en Zakelijke toepassingen
Microsoft Office Access MUI (Dutch) 2010
Microsoft Office Excel MUI (Dutch) 2010
Microsoft Office Office 64-bit Components 2010
Microsoft Office OneNote MUI (Dutch) 2010
Microsoft Office Outlook Connector
Microsoft Office Outlook MUI (Dutch) 2010
Microsoft Office PowerPoint MUI (Dutch) 2010
Microsoft Office Proof (Dutch) 2010
Microsoft Office Proof (English) 2010
Microsoft Office Proof (French) 2010
Microsoft Office Proof (German) 2010
Microsoft Office Proofing (Dutch) 2010
Microsoft Office Publisher MUI (Dutch) 2010
Microsoft Office Shared 64-bit MUI (Dutch) 2010
Microsoft Office Shared MUI (Dutch) 2010
Microsoft Office Single Image 2010
Microsoft Office Suite Activation Assistant
Microsoft Office Word MUI (Dutch) 2010
Microsoft Search Enhancement Pack
Microsoft Silverlight
Microsoft SQL Server 2005 Compact Edition [ENU]
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2 Native Client
Microsoft SQL Server 2008 R2 RsFx Driver
Microsoft SQL Server 2008 R2 Setup (English)
Microsoft SQL Server 2008 Setup Support Files
Microsoft SQL Server Browser
Microsoft SQL Server PowerPivot for Excel (32-bits)
Microsoft SQL Server VSS Writer
Microsoft Sync Framework 2.1 Core Components (x86) ENU
Microsoft Visual C++ 2005 ATL Update kb973923 - x64 8.0.50727.4053
Microsoft Visual C++ 2005 ATL Update kb973923 - x86 8.0.50727.4053
Microsoft Visual C++ 2005 Redistributable
Microsoft Visual C++ 2005 Redistributable (x64)
Microsoft Visual C++ 2008 ATL Update kb973924 - x64 9.0.30729.4148
Microsoft Visual C++ 2008 Redistributable - x64 9.0.21022
Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.17
Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.4148
Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.6161
Microsoft Visual C++ 2010 x64 Redistributable - 10.0.30319
Microsoft Visual C++ 2010 x86 Redistributable - 10.0.30319
Microsoft Visual Studio Tools for Applications 2.0 - ENU
Microsoft Visual Studio Tools for Applications 2.0 Runtime
Mozilla Firefox (3.6.11)
MSVCRT
MSVCRT_amd64
MuseScore 1.0 MuseScore score typesetter
MySQL Connector/ODBC 5.1
MySQL WORKBENCH 5.2 CE
Norton Online Backup
Nuance RealSpeak Solo Dutch-Netherlands
NVDA 2010.2
OpenOffice.org 3.2
OpenProj
PDF Complete Special Edition
Privacy Manager for HP ProtectTools
QuarkXPress 6.1
QuickTime
RDPSoftware Core Components 1.0
Realtek PC Camera
RICOH Media Driver
Roxio Activation Module
Roxio Creator Audio
Roxio Creator Business
Roxio Creator Business v10
Roxio Creator Copy
Roxio Creator Data
Roxio Creator Tools
Roxio Express Labeler 3
Roxio MyDVD
sceye 5th
SIW version 2011.10.29
Sonic CinePlayer Decoder Pack
SQL Server 2008 R2 Common Files
SQL Server 2008 R2 Database Engine Services
SQL Server 2008 R2 Database Engine Shared
Sql Server Customer Experience Improvement Program
Synaptics Pointing Device Driver
TeamViewer 6
TeamViewer 7
Theft Recovery
tools-windows
TrueCrypt
Validity Fingerprint Driver
VD64Inst
ViceVersa FREE 1.0.3
Visual Basic for Applications (R) Core
Visual Basic for Applications (R) Core - Dutch
Visual Basic for Applications (R) Core - English
Visual Studio 2008 x64 Redistributables
Visual Studio C++ 10.0 Runtime
Visual Studio C++ 9.0 Runtime
VmciSockets
VMware Player
VMX Builder 0.9
WD Diagnostics
Window-Eyes 7.5.1.0
Windows-stuurprogrammapakket - SilverCreations AG sceye-7736 (12/10/2009 3.4.1.20)
Windows-stuurprogrammapakket - SilverCreations AG sceye-7737 (12/10/2009 3.4.1.20)
Windows-stuurprogrammapakket - SilverCreations AG sceye-7738 (12/10/2009 3.4.1.20)
Windows-stuurprogrammapakket - SilverCreations AG sceye-7750 (12/10/2009 3.4.1.20)
Windows 7 Default Setting
Windows Driver Package - Broadcom Bluetooth (07/30/2009 6.2.0.9405)
Windows Driver Package - Broadcom Bluetooth (12/16/2009 6.2.0.9414)
Windows Driver Package - Broadcom HIDClass (07/28/2009 6.2.0.9800)
Windows Live Communications Platform
Windows Live Essentials
Windows Live Family SAFETY
Windows Live ID Sign-in Assistant
Windows Live Installer
Windows Live Language Selector
Windows Live Mail
Windows Live Mesh
Windows Live Mesh - ActiveX-besturingselement voor externe verbindingen
Windows Live Messenger
Windows Live Messenger Companion Core
Windows Live MIME IFilter
Windows Live Movie Maker
Windows Live Photo Common
Windows Live Photo Gallery
Windows Live PIMT Platform
Windows Live Remote Client
Windows Live Remote Client Resources
Windows Live Remote Service
Windows Live Remote Service Resources
Windows Live SOXE
Windows Live SOXE Definitions
Windows Live UX Platform
Windows Live UX Platform Language Pack
Windows Live Writer
Windows Live Writer Resources
Windows Media Player Firefox Plugin
Windows Mobile Apparaatcentrum
WinZip 14.0
The problem is, the list is still to much widespread. Is it possible to filter more? An idea could be to group every line that consists of the 2 same WORDS on 1 line. Like group everything of Windows Live to 1 thing.

Like:
Quote

Windows Live Communications Platform
Windows Live Essentials
Windows Live Family Safety
Windows Live ID Sign-in Assistant
Windows Live Installer
etc


To:
Quote
Windows Live Communication Platforms | Essentials | Family Safety | etc

Tnx for your help.Why to export to text file. Export it to csv, you can even open that in Excel.

You can read this article to know how to export all installed apps

http://www.funbutlearn.com/2013/06/easily-export-all-installed-apps-from.html
6748.

Solve : How can i add a space 3 letters from the end of each line in a text file??

Answer»

Hello everyone.

I've got a huge list of post codes that havent got any spaces in them. there are 2 formats, for example

A12 3BC or A1 2BC so ideally I need something that will add a space 3 characters from the end of each line. The list has been put in notepad which caused problems viewing it from the START. Its a very big list.
WOULD be very grateful if anyone can help.

ThanksAre all the lines 5 letters? If so it would be much easyer.

Untested:
Code: [Select]@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%A in ('type "a.txt"') do call :loop
exit /b

:loop
set a=0
set line=%1
set char=0

:loop.1
REM find char in line
if not "!line:~%a%,1!"=="" (
set /a char+=1
set /a a+=1
goto :loop.1 )

REM find 3 spaces back
set /a end=%char%-3

set a=0
set line2=
:loop.2
REM set line2
set workingChar=!line:~%a%,1!
if %a% == %end% (
set line2=%line2% %workingChar%
) else (
set line2=%line2%%workingChar%
)
if not %a% == %char% goto :loop.2
echo %line2% >>file2.txt
goto :eof
Lemonilla, you don't ever pass the contents off to the loop.

@OP, try this:

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in (a.txt) do (
set line=%%a
set line=!line: =!
set line=!line:~0,-3! !line:~-3!
echo !line!>>newpost.txt
)
It removes any spaces from each line, then takes EVERYTHING but the last 3 characters, ADDS a space, then tacks on the last 3 characters to the end. It's all put into a new file called "newpost.txt".

6749.

Solve : use of SET in FOR?

Answer»
I am making list of folders I am LOOKING having name 2000 it working fine with CODE

Code: [Select]FOR /F "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO echo %%I IN %G\%%H>> L2.txt
Some reason I can't get this work with SET to get name without 2000 word

Code: [Select]FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO (
set NY=%%I
set "NY=%NY:2000=%"
)
echo "%NY%" IN %%G\%%H>> L2.txtIn this case you can move the line that changes the variable out of the loop. To change a variable inside a loop you need to use delayed expansion and the !variable! syntax instead of %variable%

Code: [Select]FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO (
set NY=%%I
set g=%%G
set h=%%H
)
set "NY=%NY:2000=%"
echo "%NY%" IN "%g%\%h%">> L2.txt
This example uses delayed expansion (and be aware that ! characters in the TEXT are an issue)

Code: [Select]@echo off
setlocal enabledelayedexpansion
FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO (
set NY=%%I
set "NY=!NY:2000=!"
echo "!NY!" IN %%G\%%H>> L2.txt
)
6750.

Solve : exit /b turning echo off?

Answer»

For some reason exit /b is leaving echo off when the program ends. Is there anyway to fix this?
(:end is at the bottom)
Code: [Select]:: version 3.5
@echo off
if "%1"=="-debug" (
shift
echo on
)
setlocal EnableDelayedExpansion

REM Clear Var
call :clearVar

REM Declare default signs
set cordinate=+
set space=-
set zero=0


REM Find the number of arguments
set num_args=0
:loop
set findArg_value=%1
set f | find "%findArg_value%" 1>nul 2>&1
if "%errorlevel%"=="0" (
set /a num_args+=1
set arg!num_args!=%1
shift
goto loop )
set findArg_value=


REM Check for modifyers
goto :Modifyers.start

:Modifyers.end


REM Seperate coordinates into X and Y values
set a=0
set error=0
:find_argX/argY
set /a a+=1
for /f "tokens=1,2 delims=." %%B in ('call echo !arg%a%!') do (
call :sep_cord %%B %%C
)
goto :end.sep_cord
:sep_cord
set argX%a%=%1
set argY%a%=%2
if not defined argX%a% set error=1
if not defined argY%a% set error=1
goto :eof
:end.sep_cord
if "%error%"=="1" goto :help
if not "%num_args%"=="%a%" goto :find_argX/argY
set a=
set error=

REM Find the max X and Y values
set argX_max=0
set argY_max=0
set a=0
:find_argX.max/argY.max
set /a a+=1
call set workingArgX=!argX%a%!
call set workingArgY=!argY%a%!
if %workingArgX% GTR %argX_max% set argX_max=%workingArgX%
if %workingArgY% GTR %argY_max% set argY_max=%workingArgY%
if not "%a%"=="%num_args%" goto :find_argX.max/argY.max
set workingArgX=
set workingArgY=
set a=

REM Find the min X and Y values
set argX_min=0
set argY_min=0
set a=0
:find_argX.min/argY.min
set /a a+=1
call set workingArgX=!argX%a%!
call set workingArgY=!argY%a%!
if %workingArgX% LSS %argX_min% set argX_min=%workingArgX%
if %workingArgY% LSS %argY_min% set argY_min=%workingArgY%
if not "%a%"=="%num_args%" goto :find_argX.min/argY.min
set workingArgX=
set workingArgY=
set a=


REM Create coordinate veriables
for /l %%D in (%argX_min%,1,%argX_max%) do (
for /l %%E in (%argY_min%,1,%argY_max%) do (
set cordx=%%D
set cordy=%%E
set "cord!cordx!.!cordy!=!space!"
)
)
set cordx=
set cordy=


REM assign 0
for /l %%A in (%argX_min%,1,%argX_max%) do (
for /l %%B in (%argY_min%,1,%argY_max%) do (
if %%A == 0 set "cord%%A.%%B=%zero%"
if %%B == 0 set "cord%%A.%%B=%zero%"
)
)


REM Assign arguments to coordinates
set a=-1
:cord.arg.loop
set /a a+=1
call set cord!arg%a%!=!cordinate!
if not "%a%"=="%num_args%" goto :cord.arg.loop
set a=

set /a y=%argY_max%+1
echo. >>tmp
:display_y.loop
set line=
set /a y-=1
set /a x=%argX_min%-1
:display_x.loop
set /a x+=1
set "line=%line%!cord%x%.%y%! "
if not "%x%"=="%argX_max%" goto :display_x.loop
echo %line% >>tmp
if not "%y%"=="%argY_min%" goto :display_y.loop

TYPE tmp
del /f tmp


REM Remove veriables from memory and exit
call :clearVar
goto :end


:Modifyers.start
set a=0
set b=0

if defined arg1 call :loop.findpoint

:check.loop
set /a a+=1

:: Help
if "!arg%a%!"=="/?" goto :help

:: Bug
if "!arg%a%!"=="-bug" goto :bug

:: ver
if "!arg%a%!"=="-ver" goto :ver

:: No arguments
if not defined arg%a% goto :help

:: Space Char
if "!arg%a%!"=="/s" set /a b=%a%+1
if "!arg%a%!"=="/s" set "space=!arg%b%!"
if "!arg%a%!"=="/s" (
set arg%a%=%arg_rep%
set arg%b%=%arg_rep%
)
set b=0

:: Coord Char
if "!arg%a%!"=="/c" set /a b=%a%+1
if "!arg%a%!"=="/c" set "cordinate=!arg%b%!"
if "!arg%a%!"=="/c" (
set arg%a%=%arg_rep%
set arg%b%=%arg_rep%
)
set b=0

:: Zero Char
if "!arg%a%!"=="/z" set /a b=%a%+1
if "!arg%a%!"=="/z" set "zero=!arg%b%!"
if "!arg%a%!"=="/z" (
set arg%a%=%arg_rep%
set arg%b%=%arg_rep%
)
set b=0

:: Line
if "!arg%a%!"=="/l" set /a b=%a%+1
if "!arg%a%!"=="/l" set /a c=%a%+2
if "!arg%a%!"=="/l" goto :graphLine "!arg%b%!" "!arg%c%!"

if not "%a%"=="%num_args%" goto :check.loop
set a=

goto :Modifyers.end

:loop.findPoint
for /f "tokens=1,2 delims==" %%A in ('set arg') do (
call :findpoint %%A %%B

)
goto :loop.findpoint.end

:findpoint
for /f "tokens=1,2 delims=." %%B in ("%2") do (
if not "%%C"=="" set arg_rep=%2
)
goto :eof

:loop.findpoint.end
goto :eof

:help
echo Graphs coordinates on a coordinate plane.
echo.
echo Graph ^[^[^/c ^<char^>^] ^[^/s ^<char^>^] ^[^/z ^<char^>^] x.y x.y x.y ...^]
echo ^[/l y=mx+b^] ^[^-bug^] ^[^/?^]
echo.
echo /c Defines what character the coordinates will be shown as.
echo /s Defines what character the empty spaces will be shown as.
echo /z Defines what character the axis will be shown as.
echo. /l Displays a line using y=mx+b input.
echo. /? Displays this help menu.
echo -bug Lists all KNOW bugs in the software.
echo -ver Lists current version.
echo.
echo.%%^^^&^)^=^|^;^"^<^>^,^^! Cannot be used with /c, /s or /z.
goto :end

:bug
echo.
echo Known bugs:
echo 1^) Modifyer /z does not work sometimes.
echo 2^) No current limit on hight of line graph.
echo 3^) Lines begin to wrap if points EXTEND too far in either direction.
goto :end

:graphLine
REM Grab Veriables
for /f "tokens=1,2 delims=x" %%B in ("!arg%c%!") do (
set slope=%%B
set yint=%%C
)

REM find point one
if "%yint%"=="" set "yint=+0"
if "%yint:~0,1%" == "+" set yint=%yint:~1%
set "points=0.%yint% "

REM find rise/run
for /f "tokens=1,2 delims=/" %%A in ("%slope%") do (
set rise=%%A
set run=%%B
)
if not defined rise set rise=1
if not defined run set run=1

REM find points +
set a=0
:loop.find_points_+
set /a a+=1
set /a working_run=%a%*%run%
set /a working_rise=%a%*%rise%+%yint%
set "points=%points%%working_run%.%working_rise% "
if not %a% EQU 4 goto :loop.find_points_+

REM find points -
set a=0
:loop.find_points_-
set /a a-=1
set /a working_run=%a%*%run%
set /a working_rise=%a%*%rise%+%yint%
set "points=%points%%working_run%.%working_rise% "
if not %a% EQU -4 goto :loop.find_points_-

REM assign arguments
set a=0
for %%A in (%points%) do (
set /a a+=1
set arg!a!=%%A
)
set num_args=%a%
goto :Modifyers.end

:clearVar
for /f "tokens=1 delims==" %%A in ('set ^| find "arg"') do set %%A=
for /f "tokens=1 delims==" %%A in ('set ^| find "cord"') do set %%A=
set zero=
set space=
set points=
set cordinate=
set rise=
set run=
set working_rise=
set working_run=
set yint=
set num_args=
set a=
set b=
set c=
set ver=
set error=
goto :eof

:ver
echo Version 3.5
goto :end

:end
exit /b
First verify this code fragment. Test your code in small chunks
Quote

@echo off
if "%1"=="-debug" (
shift
echo on
)
Add something to verify this part of the code is working. You code is too much. Batch code does not lend itself to easy testing, so you have to do bits and nibbles and have little FLAGS to tell what is going on. Why use echo off? Use echo on up until u got the code working. An annotate your code so other can help you.
Best I can do for you.I didn't SEE an issue with echo being turned off. See below (a.bat)

Code: [Select]d:\abc>a 1.2 3.4 6.8

0 - - - - - +
0 - - - - - -
0 - - - - - -
0 - - - - - -
0 - - + - - -
0 - - - - - -
0 + - - - - -
0 - - - - - -
0 0 0 0 0 0 0

d:\abc>123