bat numerical problem

December 23, 2010 at 15:02:31
Specs: Windows Vista Home Premium-32bit / Windows 7 Ultimate 32bit, CPU=intel-core2duo_2.1GHz/RAM=3GB
Hallow every one,

I have two numerical problems with my bat program.


Problem 1

How to generate ascending numerical digits with a bat program ?

(e.g. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15................etc. continuously in ascending order.)


Problem 2

I have a text file named temp.txt with many lines (I don't know how much).


The lines can contains numerical, alphabetical, alphanumerical characters.

I want to check with a bat program that is there have one or more 0(zero)s at the beginning of a line in the temp.txt file and want to make the line a variable (Variable name=My_Var1) and then want to reprocess the line to remove the 0(zero)s from the beginning of that line and then want to assign a another variable (another variable name=My_Var2) to the reprocessed filtered output.


It is not necessary that a line in the temp.txt only have the 0(zero)s at the beginning of a line, one or more 0(zero)s can be found at the any position of a line but a line can not contain only one or more 0(zero)s.

temp.txt content example as follow:-

444.3>Khnj?fj3302""994-9.00.8..
332kjf...mH.m.m,,'^??9900.008.40
0332kjf...mH.m.m,,'^??9900.
100033mmr9
22238899484
00088433222221
022333449598
0000033
100868699
078..9.79??>><{||||00
fjhFGfhNjnfFnjjsj
jfnkZjBKfnkskHk
GGidfnHdnfdhnKJK

Can any one help me ??

Please help me.



See More: bat numerical problem

Report •

#1
December 23, 2010 at 15:19:52
How to generate ascending numerical digits with a bat program ?

FOR /l %%a IN (Start Step End) DO ECHO %%a

"Start" is where you want the sequence to begin, "Step" is the nuber you want the sequence to increase by, and "End" is where the sequence will end.

For example, (1 1 100) would generate all the numbers between 1 and 100. (50 1 100) you generate all the numbers between 50 and 100.

Can I put a question here?


Report •

#2
December 23, 2010 at 18:25:27
Remove leading zeros, not fully tested..

@echo off
setlocal enabledelayedexpansion
cls

for /f "tokens=*" %%1 in (%temp%\trial.txt) do (
    set My_Var1=%%1&set My_Var2=%%1& call :Loop
    echo.
    echo My_Var1=!My_Var1!
    echo My_Var2=!My_Var2!
    echo.

    )


exit /b

:: Remove leading zeros if exist.
:Loop
IF "!My_Var2:~0,1!"=="0" (
  SET My_Var2=!My_Var2:~1!
    GOTO Loop
    )

Did you Google for an answer before asking the question?


Report •

#3
December 23, 2010 at 18:39:57
@Wahine

A deceptive trick to remove leading zeros:

for /f "tokens=* delims=0" %%a in ("thestring") do echo whatever with %%a


Report •

Related Solutions

#4
December 24, 2010 at 00:18:02
Thanks Judago - can you direct me to where the trick is documented please?

Did you Google for an answer before asking the question?


Report •

#5
December 24, 2010 at 01:08:00
I can only find Unofficial documentation.

If you want it to fall under the documentation, it could be done like so:

set var=000010015245
for /f "tokens=1* delims=0" %%a in ("A0%var%") do echo %%b

"A" being a non-delim character or characters. Followed by the a delim character in case there are no leading delims(i.e. no leading zero).


...
tokens=x,y,m-n  - specifies which tokens from each line are to
                  be passed to the for body for each iteration.
                  This will cause additional variable names to
                  be allocated.  The m-n form is a range,
                  specifying the mth through the nth tokens.  If
                  the last character in the tokens= string is an
                  asterisk, then an additional variable is
                  allocated and receives the remaining text on
                  the line after the last token parsed.
...


from for


Report •

#6
December 24, 2010 at 07:47:27
Thank you vary much to all you guys Matt123, Wahine, and Judago for all your replies, and VARY VARY SORY for my delayed reply.

@Matt
it is working good..
but, it have a problem also, that it generates ascending digits in a pre-specified range,

however,it can be a extra control to the code to what it will generate and it will also help me.

but, after my posting i have also made a code to do such, the code is as bellow,

@echo off
set /a numb=0
set /a num=0
:start
cls
echo:%numb%
set /a numb = num+1
set /a num = numb
goto :start

(Any comment, error reporting or enhancement suggestion to the code will be vary much appreciable.)

@Wahine
Vary good trick.

I have tested your code, it is working fine.
you have used extended variables to do it.
It helped me.

@Judago
Your code is vary short and working, i have tested it.
But, then i have to pass my lines one by one to your code.
then it will do the work for me.


Again thanks: Matt123, Wahine, and Judago for your replies.


Report •

#7
December 24, 2010 at 14:02:58
Judago - thanks again. I should have known it would be part of the Rob V'Woude stable.

Black_Blood - thank you for coming back to advise of your success and for your other comments. You will, of course, realize that the code you posted in your reply to Matt contains a closed loop, there is no exit-point in your code.

Did you Google for an answer before asking the question?


Report •

#8
December 24, 2010 at 16:42:35
Some words to Judago,

Judago, Today on the web i have found a site is as bellow,

http://judago.webs.com


Is it your site ??? If the site is yours then the following is for you else it is irrelevant to you and others.

I have been reading what is written in your site, i feel it is great, specially the links named For loop madness, Batch Operators, %variable% !catches! and Tib-bits was just fab.

These was really helped me and increases my knowledge


in your site there was small description about con operator, can you kindly tell me more about con ??

Is that possible to pass a text string to a separate cmd console from a cmd console or from a bat script with con?? How ??


In the "Batch Files" link of your site there was many useful scripts specially the Usbflash.bat script was vary knowledge increasing that how you scanning for attached usb devices and list them.


In the download page, there is many cool utilities you made available for download, and specially the Wcde app. is just great. Wcde rocks.


I have a special kind request to you, Can you make a cmd tool to make highly customizable and controllable GUI which can be called through a batch program to do batch jobs??

If you kindly accept my request it will be vary vary much great.


(PLEASE REPLY)


Report •

#9
December 24, 2010 at 17:37:27
Thank you vary much Wahine for your reply and also thanks for your report about my code.


Black_Blood - thank you for coming back to advise of your success and for
your other comments. You will, of course, realize that the code you posted in your
reply to Matt contains a closed loop, there is no exit-point in your code.


There is no exit point in my posted code because i haven't gave it.

Actually i have developed this code to use in my currently underdeveloping bat program and in that bat program the posted code doesn't need to be exited for as my bat programs requirement.


However, it is possible and very easy to add a exit point to the code, the following is the same code with added exit point.

@echo off
set /a numb=0
set /a num=0
:start
cls
if %numb% equ <any numerical value> goto :End
echo:%numb%
set /a numb = num+1
set /a num = numb
goto :start
:End
echo:Press any key to exit...
pause>nul && goto :eof


NOTE: Replace the "<any numerical value>" (without dabble quotes) in the 6th line of the code with your desired numerical value.


(Any comment, error reporting or enhancement suggestion to the code will be vary much appreciable.)


Report •

#10
December 24, 2010 at 18:08:05
@Black_Blood

http://judago.webs.com


Is it your site ???

Yes it's my site ;) I haven't touched it much lately though(execpt for cmdimate/batimate) :p. I'm glad it has be useful to you, especially wcde(Hint: "wcde /yolk /now" ).


in your site there was small description about con operator, can you kindly tell me more about con ??

Is that possible to pass a text string to a separate cmd console from a cmd console or from a bat script with con?? How ??

Unfortunately con only represents the current console that cmd is running in, it has no effect on other windows. The only way I know to pass text is either at invocation(via start or with a container of some sort(i.e. a file).

con just represents the current console window anything redirected to con will be displayed and cannot be redirected again. Like nul it is used like a file and some programs will even take it as a file argument.

Think of nul like that shy person that never speaks and con as the person that *has* to tell you everything.

@(
    1>&2 echo I'm in the error stream Ha ha!
    >nul echo I'm shy....
    echo I'm average ;p
    >con echo Look at me !!! I'm the only one you see!
) >nul 2>&1

In short anything redirect to con will be displayed in the current console.

I have a special kind request to you, Can you make a cmd tool to make highly customizable and controllable GUI which can be called through a batch program to do batch jobs??

These things take time(weeks or longer), and I'm not sure I have it......

Do you mean a proper GUI or something inside the console(ala cmdimate/batimate/jsals)?


Report •

#11
December 24, 2010 at 22:31:14
Thank you vary much Judago for your reply, also thanks for the extended explanation about Con and nul

So, Con only works for the current console.


The only way I know to pass text is either at invocation(via start or with a
container of some sort(i.e. a file).

Oh, Sorry, I was just forgot the Start command that it can do such but not with a running cmd console, what do you think??

You have also mentioned that it can be done with a container of some sort(i.e. a file) can you please tell me how??


These things take time(weeks or longer),

No problem at all, i can understand that such of a stuff can take time and i will monitor your web site and that web page also my self every day to view your work progress on it (if you take the work in your hand)


Do you mean a proper GUI or something inside the console(ala cmdimate/batimate
/jsals)?


Yes, I have meant a proper GUI and with the following,

Think of a CMD command with lots of switches and required elements.

Actually, I want a process which can be done by a bat file (like a CMD command) and when i execute the bat file the customized (by a user) GUI should open in the place of the command console it self.

Every buttons on the GUI (like radio buttons, check boxes, ok, cancel, etc. or any customized labeled buttons by the user ) should be able to hold a complete bat script or partial script of the bat file (which have executed the GUI or others), what required by the bat script.

It should be able to display process bars, percentage of process done, etc.

The GUI, it's buttons, and process bar's appearance also should be customizable (i.e. with images e.g. .bmp, .png .gif etc.), i mean the background and foreground of the GUI, it's buttons and the process bar it selves.

The window size, window behavior, window default position, buttons size, buttons position, buttons behavior, process bar size, process bar position, process bar behavior, etc. on the GUI should also be widely customizable.

Multiple window should can be work to gather (so, i think probably you should have to give a unique ID No. to each window and probably you should consider a variable to the ID No. but it would be beater if you let a user to set his won unique ID No. to each GUI and Sub-GUI and save that ID No. as a variable.)

And a another thing, the GUI window and its elements (separately or to-gather) should able to be refreshed continuously, periodically, or if needed or when wished by user.

And any other feature(s) that you think it must should have.

It will not be a problem for me that if you develop a new script language which commands will can be executed from a CMD Console or from a bat file to do the stuff but it will be a problem for me if your newly developed script language's commands can not be executed from a CMD console or from a bat file.


The hole system should run under any versions of XP, VISTA, Win7. (if you wish you can add supports for any lower version of windows)

Have I made it properly defined?? Please kindly tell me.

And If you kindly accept my request it will be vary vary much great.

Thanks again for your reply Judago and also for your extended help again



Report •

#12
December 24, 2010 at 23:58:33
Oh, Sorry, I was just forgot the Start command that it can do such but not with a running cmd console, what do you think??

You have also mentioned that it can be done with a container of some sort(i.e. a file) can you please tell me how??

With start you can start a batch script in a new window and pass it parameters, but beyond that it's not practical(or possible AFIK).

If both scripts are written to check a certain file for information either or both could periodically check, read and clear the file, thus allowing very rudimentary communication. It would however be less that elegant.

[The program stuff]

That is very complicated concept and I'm not in the most stable situation at the moment, so I'm going to pass. Sorry.

I just can't commit to the time(probably 100hrs+ work for just me) when I don't know what it is I will be doing next year.


Report •

#13
December 25, 2010 at 05:10:14
Thank you vary much Judago for your reply, and also for the explanations.


With start you can start a batch script in a new window and pass it parameters, but
beyond that it's not practical(or possible AFIK)


Yah, I also think so, but I was asking you for if there any probability have existed.


If both scripts are written to check a certain file for information either or both could
periodically check, read and clear the file, thus allowing very rudimentary
communication. It would however be less that elegant.

So, you mean, a common file (i.e. text file) where a batch program writing data to the file and a another batch program which is reading data from the file so that the second batch program's console can be (continually or when needed) updated.

That is very complicated concept and I'm not in the most stable situation at the
moment, so I'm going to pass. Sorry.

I just can't commit to the time(probably 100hrs+ work for just me) when I don't know
what it is I will be doing next year.


Hey, not a problem man, I can understand.

But, there is a problem i am facing, if you give me any suggestion and/or any solution to it that will be really vary great. look at the following code,

@echo off
setlocal
set num = 0
set /a num = 9001/2
echo:%num%
pause


if I use a calculator to calculate the math it will be resulted as 4500.5 but with the set /a the result that coming up is 4500. why it is ignoring the .5 value?? It happens all the time when I try to do some math like it.

Any suggestion or solution to the problem Judago ??


Again, Thank you vary much Judago for your reply, and also for the explanations.


Report •

#14
December 25, 2010 at 05:33:05
So, you mean, a common file (i.e. text file) where a batch program writing data to the file and a another batch program which is reading data from the file so that the second batch program's console can be (continually or when needed) updated.

Pretty much.

if I use a calculator to calculate the math it will be resulted as 4500.5 but with the set /a the result that coming up is 4500. why it is ignoring the .5 value?? It happens all the time when I try to do some math like it.

Set /a is integer math only, floating point isn't supported. Results are rounded.

There are ways to work around it, but you have to ask what number of decimal places do you want? It's also tricky when it hits the 32 or 64 bit walls.

It's not a catch all but I wrote this some time ago:

http://judago.webs.com/content/Scri...

Even then limitations are present(see the in script help), division always was a problem child......


Report •

#15
December 25, 2010 at 09:41:20
Judago: Results are rounded truncated.
Subtle but distinct difference.

How To Ask Questions The Smart Way


Report •

#16
December 25, 2010 at 14:37:12
Thank you vary much Judago for reply,

Set /a is integer math only, floating point isn't supported. Results are rounded.

There are ways to work around it, but you have to ask what number of decimal places
do you want? It's also tricky when it hits the 32 or 64 bit walls.

It's not a catch all but I wrote this some time ago:

http://judago.webs.com/content/Scri...

Even then limitations are present(see the in script help), division always was a problem
child......

So, Set /a doesn't supports floating point values.

I have been viewing the divide.bat script after your post, but it doesn't works for me, when i tries to execute it a cmd console just flashed up and closed down, i am using Windows 7 is that the problem??


It's also tricky when it hits the 32 or 64 bit walls.

But, is it possible with bat that to check a Windows OS that either it is a 32bit or 64bit which is installed?? How??


And I want to also ask you that, if line number is known for a text line in a certain text file then how to make the line a variable??

Again Thank you vary much Judago for reply,


Report •

#17
December 25, 2010 at 15:48:15
WELCOME Razor2.3


Report •

#18
December 25, 2010 at 18:29:32
Razor2.3: Subtle but distinct difference.
Thanks for correcting me.


Black_Blood:I have been viewing the divide.bat script after your post, but it doesn't works for me, when i tries to execute it a cmd console just flashed up and closed down, i am using Windows 7 is that the problem??

You have to call it with parameters from the command line or another script. There is also the possibility that it won't work on Win7(I doubt it though).....

Can be large and floating point.
                     |
call divide.bat {dividend} [/] {divisor} [variable name] [n decimal places]
                                |
              Must be whole and less than 2097153


************************************
C:\>call divide.bat 9001 / 2
4500.50000000 - Leftover: (this isn't always the mod result)

C:\>call divide.bat 9001 / 2 "" 2
4500.50 - Leftover: (this isn't always the mod result)

C:\>call divide.bat 9001 / 2 testvar 2

C:\>echo %testvar%
4500.50

Windows OS that either it is a 32bit or 64bit which is installed?? How??

MS even have a page:


http://support.microsoft.com/kb/556009

And I want to also ask you that, if line number is known for a text line in a certain text file then how to make the line a variable??

Maybe something like this:

set linenum=2
set filename="test.txt"
for /f "tokens=1* delims=]" %%a in ('find /n /v "" ^< %filename%') do (
    if "%%a"=="[%linenum%" set line=%%b
)

echo %line%
pause


Report •

#19
December 27, 2010 at 01:32:02
Thank you vary much for your reply Judago and vary vary sorry for delayed reply.


So,Your Divide.bat is works like a cmd tool (e.g.icacls.exe, msg.exe, reg.exe etc.), It works fine with your suggested, but with a problem that the variable switch is not working at all, may be for as you said win7. So, i am using for /f to make a variable of the output.

And, the another thing is extra words with result, and trailing 0(zero[s]) like the bellow,

call divide.bat 9001 / 2
4500.50000000 - Leftover: (this isn't always the mod result)


So, I did a coding job to remove extra words and trailing 0(zero[s]) from the output of the divide.bat execution, the code is as bellow,

@echo off

set "divide=26662360899660.481523152768338"
set "divisor=5263"
set "decimal_places=12"

for /f "tokens=1 delims= " %%g in ('div %divide% / %divisor% "" %decimal_places%') do (
   for /f "tokens=1* delims=." %%h in ("%%g") do (
      for /f "tokens=1 delims=0" %%j in ("%%i") do (
      echo:Trimmed Output=%%h.%%j
      pause  
      )
   )
)


I think the above code is not so stable and may can be smaller.

Judago, any suggestion will be great

MS even have a page:

support.microsoft.com/kb/556009

Thanks for the link judago, the code from the MS is working fine.


Maybe something like this:

set linenum=2
set filename="test.txt"
for /f "tokens=1* delims=]" %%a in ('find /n /v "" ^< %filename%') do (
    if "%%a"=="[%linenum%" set line=%%b
)

echo %line%
pause


It is working, but some times not, i.e. i was coding a script for just to test your code but, isn't working but the exact code you have posted is working, i don't know what's going wrong with the tester code.

The tester code is as bellow:


@echo loff
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set linenum=3
set filename="test.txt"
for /f "tokens=1* delims=]" %%a in ('find /n /v "" ^< %filename%') do (
   if "%%a"=="[!linenum!" (
   set line=%%b
   cls
   echo:line=!line!
   echo:a=%%a
   pause
   ::goto :nul
   ) else (
      cls
      echo:Nothing found...!!
      echo:a=%%a
      echo:line=!line!
      pause
      ::goto :nul
   )
)

echo:line=!line!
pause

Can you help me to fix it out??


Judago As for my curiosity it will be really vary great if you answer that how to know the installed OS is either XP, VISTA or Win7 with bat??

Again, Thank you vary much for your reply Judago and vary vary sorry for delayed reply.

It is engulf for a human to live as a human on earth...


Report •

#20
December 27, 2010 at 03:05:50
Here I just modified the original
(it's on the site but isn't listed, the original is still under "batch files"
- just be sure to use this link):

http://judago.webs.com/content/Scri...

Are you sure you only passed the variable name without and
%'s or !'s, because if they are marked the contents
will be set to.

The whole idea with the line num thing was that it iterates
over the entire output of find /n /v until it finds the
line, the else is useless because it would be executed even
if the match will be found eventually.

The "notfound" may seem ambiguous, but %%a will have "[<number" otherwise.

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set linenum=3
set filename="test.txt"


for /f "tokens=1* delims=]" %%a in ('find /n /v "" ^< %filename% ^| findstr /b \[%linenum%\]^|^|echo notfound') do (
    if "%%a"=="notfound" (
        echo couln't find line %linenum% in %filename%
    ) else (
        echo found line %linenum% in %filename%
        echo.%%b
        set line=%%b
    )
)
pause

As for the os versions you can use the ver command and test
against known strings.


Report •

#21
December 27, 2010 at 04:37:57
I just slightly modified the script linked in #20(same link).

A zero dplace could have stripped trailing zero's in the whole number....


Report •

#22
December 27, 2010 at 15:53:15
Thank you vary much Judago for your reply and for your extended expansive help.


Here I just modified the original
(it's on the site but isn't listed, the original is still under "batch files"
- just be sure to use this link):

judago.webs.com/content/Scri...

.............

I just slightly modified the script linked in #20(same link).

A zero dplace could have stripped trailing zero's in the whole number....


Judago now it is working fab. , and do not need extra coding also.

Are you sure you only passed the variable name without and
%'s or !'s, because if they are marked the contents
will be set to.


Yes, I am sure.

The "notfound" may seem ambiguous, but %%a will have "[<number"
otherwise.


I learn. As your codes says your understanding with code syntax is vary good, and about me is, started learning coding with bat about 2 months ago without any reference book, only / ? was there. So your codes is like a learning platform for me. But I do not understand one thing, why you are using double piping (i.e.

| |
) at the front of echo notfound ??

As for the os versions you can use the ver command and test
against known strings.


Isn't it possible with registry like the previous 32bit and 64bit problem or with other?


I have extra problem also, if you can find answer, the problem is as bellow,


I have text file named path.txt, it have so many lines (I don't know how much) in the bellow form,

<Full directory path of a executable file><many spaces><a 1 to 9 digit int.><many spaces>


e.g.

C:\Windows\system32\taskhost.exe                                  448        
C:\Program Files\PowerISO\PWRISOVM.EXE                            2440       
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe           2464       
C:\Program Files\Microsoft Office\Office12\GrooveMonitor.exe      2552       
C:\Program Files\Synaptics\SynTP\SynTPEnh.exe                     2672       
C:\Program Files\Acer Bio Protection\PdtWzd.exe                   2688       
C:\Program Files\BSNL 3G Data Card\BSNL 3G\Resource\MCtlSuc.exe   2708       


Only the int. value is known to me, and i want a variable to represent From beginning of a line to the .exe of a known int. line.


Now I am using the bellow code,

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set ProsID=2464

for /f "tokens=* delims= " %%a in ('find "!ProsID!" ^< !temp!\path.txt') do (
      set S=%%a
   )

   for /f "tokens=1 delims=." %%i in ("!S!") do (
      set "exepath=%%i.exe"
   )
echo:!exepath!
pause

______________________________(ProsID is the variable name of the int. value)

That code is skipping any thing after a first .(dot) found in a line, so if a line contains any .(dot) before the .exe
e.g.

C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe           2464       

it is skipping

"0\Acrobat\acrotray.exe           2464       "
from the example. Otherwise it is working as far as my testing.

What should I do ??


Thanks again Judago for your every attention to me.

It is engulf for a human to live as a human on earth...


Report •

#23
December 27, 2010 at 17:25:52
The "||" means if the previous command returns an errorlevel greater than zero execute the next command. The echo is so that the loop executes(if there is no actual text for /f won't execute the do part.

find /n /v "" ^< %filename% ^| findstr /b \[%linenum%\]^|^|echo notfound

Find appends line numbers in the format of "[<number>]" to the start of line, findstr looks for lines that start with the specified line number. If the line isn't found findstr returns 1, so the echo is executed. "notfound" doesn't contain "]" so it will be in %%a and ensure execution.

Isn't it possible with registry like the previous 32bit and 64bit problem or with other?

There probably is but I don't know it off hand; either way you will end up comparing strings.

Only the int. value is known to me, and i want a variable to represent From beginning of a line to the .exe of a known int. line.

The below seemed to work for me on xp.I just ran over the whole file(i.e your sample) I think you know what to do ;)

for /f "tokens=*" %%a in (test.txt) do (
   for /f "tokens=1" %%b in ("%%~xa") do (
       echo %%~dpna%%b
    )
)


Report •

#24
December 28, 2010 at 21:53:48
Thank you vary much Judago for your reply.


The "||" means if the previous command returns an errorlevel greater than zero........

So, "||" is works like Bit-Wise OR, But why you are placing escape(^) in the middle of the two pipes(i.e. or) (i.e. ^|^|)??


There probably is but I don't know it off hand; either way you will end up
comparing strings.


No problem I will keep trying.


The below seemed to work for me on xp.I just ran over the whole file(i.e your
sample) I think you know what to do ;)


Bulls-Eye: It's Working Smoothly.


I have two extra Questions, If you can find answer it will be realy vary great

#1. How to do opposite of Takeown function in bat with normal files and folder ??

#2. Is that possible with bat or other to play wavsound files in back ground ?? (i.e. No player window Will be displayed)


However, your WCDE is working great. WCDE ZINDABAD...


Again, Thank you vary much Judago for your reply.


It is engulf for a human to live as a human on earth...


Report •

#25
December 28, 2010 at 23:57:35
Every "special character" mainly ><|^&) need to be escaped to be the "in" part of a for loop so it doesn't get executed immediately. Even though the behaviour could be considered a single operator both pipes need to be escaped.


#1
I don't know of a way but I don't deal with permissions often.

#2
You will need another program or tool.

http://judago.webs.com/content/play...

It's just:

play <filename.wav>

I just knocked it up, all of 14 lines ;)

Just be aware that it uses: http://msdn.microsoft.com/en-us/lib...

It has this limitation:

The sound specified by pszSound must fit into available physical memory and be playable by an installed waveform-audio device driver.


Report •

#26
December 29, 2010 at 15:58:20
Thank you vary much Judago for your reply,

You makes me so Pleased with your Response to me.

Every "special character" mainly ><|^&) need to be escaped to be the "in" part
of a for loop so it doesn't get executed immediately. Even though the behaviour could
be considered a single operator both pipes need to be escaped.

I understand.


#1
I don't know of a way but I don't deal with permissions often.


Not a problem !!


#2
You will need another program or tool.


Play.exe is just working fabulously. but, is that possible with other sound (audio) formats?(e.g. mp3, mp2, wma, midi, flac, ac3, ogg etc.)


Judago, is that possible with bat, that refreshing a big console screen output randomly in a short period without badly flashing the console screen view ??

Actually I have a text file which is edited continuously with a bat prog. and a another bat prog. displays the file content in a cmd console screen with the type command, but it causing the console screen badly flashing,

I want the console display output to be outputted on the console screen without get badly flashing.


Again, Thank you vary much Judago for your reply,

It is enough for a human to live as a human on earth...


Report •

#27
December 29, 2010 at 17:40:09
Play.exe is just working fabulously. but, is that possible with other sound (audio) formats?(e.g. mp3, mp2, wma, midi, flac, ac3, ogg etc.)

You will have to find another media player that is scriptable, wav just happens to be available easily.

is that possible with bat, that refreshing a big console screen output randomly in a short period without badly flashing the console screen view ??

It depends, if you *have* to refill the entire buffer or just add a line to the end. The trick is to only output what you need to. Perhaps for /f's "skip=<number>" could help to only output new text.



Report •

#28
December 30, 2010 at 09:39:11
Thank you vary much Judago for your replay,

You will have to find another media player that is scriptable, wav just
happens to be available easily.


OK


It depends, if you *have* to refill the entire buffer or just add a line to the end.
The trick is to only output what you need to. Perhaps for /f's "skip=<number>" could
help to only output new text.


Sorry, I can not understand what you are trying to tell !!

Screen buffer is not a problem for me.


Again, Thank you vary much Judago for your replay,

It is enough for a human to live as a human on earth...


Report •

#29
December 30, 2010 at 17:00:56
What I meant was that if the only way to reduce flicker is to reduce the amount of text being sent to the console.

If your file is simple being constantly appended to then you only need to output the new lines.


Here is a very quick example:

@echo off
(
    echo.@echo off
    echo.set skip=
    echo.set lines=
    echo.
    echo.:loop
    echo.for /f "%%skip%%%%lines%% tokens=*" %%%%a in (disp.txt^) do (
    echo.    set /a lines+=1
    echo.    echo %%%%a
    echo.^)
    echo.set skip=skip=
    echo.wcde /w 2000
    echo.goto loop
) > bat2.bat

> disp.txt echo The first line of disp!
start bat2.bat
for /l %%a in (1 1 1000) do (
    >> disp.txt echo this would be line:%%a
    wcde /w 2000
)


Report •

#30
December 31, 2010 at 14:25:36

HAPPY NEW YEAR


to all...


                                                                                                        


Black_Blood...

                                                   

It is enough for a human to live as a human on earth...

Report •

#31
December 31, 2010 at 16:42:39
Happy New Year Judago


Best wishes for your coming days...


...and, thank you vary vary much for your reply,


What I meant was that if the only way to reduce flicker is to reduce the amount of
text being sent to the console.

I am explaining the problem to you properly...


You know vary well that what gonna be the output of the tasklist command when used without parameters.

And, you can imagine that I am reloading it continuously with a exitable loop to continuously update the running tasks list.


Now, what I want is to only update the changes in the list, not the hole list.

You can understand that, changes can happen in the middle of the list so last line update is not a option for me.

And, I want it to happen smoothly, some thing like Windows Task Manager's Process tab,

(It is not a problem that if i have to use external programs like CMD Tools etc.)


What should I do Judago??

It is enough for a human to live as a human on earth...


Report •

#32
December 31, 2010 at 20:50:48
Happy New Year!


It's not as easy as you would think because you would have to keep tabs on everything and handle a dynamic number of processes and even then there is going to be a flicker when a process ends because you would have to rebuild most of the list so there isn't any gaps, ect.

This still has a little flicker, but I think it may be a little better than type:

@echo off
SetLocal EnableDelayedExpansion
cls

for /f "tokens=1 delims=," %%a in ('wcde /info') do set buffer=%%a
wcde /sc 0

set maxlines=0
set currentlines=0

:update
wcde /p 0 1
for /f "tokens=*" %%a in ('tasklist') do (
    wcde /e "%%a"
    set /a currentlines+=1
    wcde /p 0 +1
)


if !currentlines! lss !maxlines! (
    set /a maxlines-=1
    for /l %%a in (!currentlines! 1 !maxlines!) do (
        wcde /p 0 %%a
        for /l %%a in (1 1 !buffer!) do (
            wcde /e " "
        )
    )
)
set maxlines=%currentlines%
set currentlines=0
wcde /w 2000
goto update


Report •

#33
January 1, 2011 at 15:37:15
Thank you vary much for your replay judago,

I have tested your code, it is working but have a problem also, the console screen is sliding up and down, and i thing it is because, !maxlines! is greater then console screen Window height. Isn't it ??

Is that possible to stop the screen sliding??


A new problem is occurring in your previously posted code, the code was as bellow,


for /f "tokens=*" %%a in (test.txt) do (
   for /f "tokens=1" %%b in ("%%~xa") do (
       echo %%~dpna%%b
    )
)

Only for testing, I have added some code to it which is given bellow,


@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:start
cls
echo:
set /p ProsID="PID: "

for /f "tokens=*" %%a in ('find "!ProsID!" ^< path.txt') do (
   for /f "tokens=1" %%b in ("%%~xa") do (
       set "exepath=%%~dpna%%b"
    )
)
echo:Exepath="!exepath!"
pause
set "%%a="
set "ProsID="
set "%%b"
set "%%~dpna%%b="
set "exepath="
goto :start


And what the path.txt file is exactly contains that is as bellow,

ExecutablePath                                                    ProcessId  
                                                                  0          
                                                                  4          
                                                                  388        
C:\Windows\system32\csrss.exe                                     468        
C:\Windows\system32\wininit.exe                                   512        
C:\Windows\system32\csrss.exe                                     528        
C:\Windows\system32\services.exe                                  576        
C:\Windows\system32\lsass.exe                                     600        
C:\Windows\system32\lsm.exe                                       616        
C:\Windows\system32\winlogon.exe                                  624        
C:\Windows\system32\svchost.exe                                   756        
C:\Windows\system32\svchost.exe                                   828        
C:\Windows\System32\svchost.exe                                   912        
C:\Windows\System32\svchost.exe                                   1004       
C:\Windows\system32\svchost.exe                                   1040       
C:\Windows\system32\svchost.exe                                   1172       
C:\Windows\system32\svchost.exe                                   1292       
C:\Program Files\Acer Bio Protection\CompPtcVUI.exe               1416       
C:\Windows\System32\spoolsv.exe                                   1496       
C:\Windows\system32\svchost.exe                                   1528       
C:\Program Files\LSI SoftModem\agrsmsvc.exe                       1612       
C:\Program Files\WIDCOMM\Bluetooth Software\btwdins.exe           1632       
C:\Program Files\Acer Bio Protection\BASVC.exe                    1732       
C:\Program Files\Common Files\Nero\Nero BackItUp 4\NBService.exe  1764       
C:\Windows\system32\svchost.exe                                   688        
C:\Windows\system32\Dwm.exe                                       1972       
C:\Windows\Explorer.EXE                                           1816       
C:\Windows\system32\taskhost.exe                                  448        
C:\Program Files\PowerISO\PWRISOVM.EXE                            2440       
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe           2464       


above was going well, but the problem is when 0 or 4 is given as the PID value (i.e. right side integer) it returns the "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe" string instead of a null string, but when 388 is given as the PID value it is returning a null string as expected, otherwise it is working good for other PID values in the above list.

What to do ??


judago i have another question that, with the schtasks command how to schedule a admin task for n seconds where the n can be greater then 86400 sec. (i.e. 24 hours) ??

Again, Thank you vary much for your replay judago,

It is enough for a human to live as a human on earth...


Report •

#34
January 1, 2011 at 17:13:25
[Sliding screen]: It is possible but it would require a rewrite of wcde's /e switch(which would break a lot of things). I very quickly put together an executable and it works, but if you scroll past the cursor, display jumps back so the cursor is inside the visible area.

!!Warning!!: I didn't put much effort into this(may have bugs ect)
http://judago.webs.com/content/writ...
(modified script in the zip)

[pid problem]

Try searching for the leading/trailing space.

findstr /r /e /c:" !ProsID!\ *" path.txt

Just think about how many times "4" appears in the file....

[Schedtasks]
I haven't done any scheduling in a long time so I can't really answer.


Report •

#35
January 3, 2011 at 02:31:32
Thank you vary much Judago for your reply, and vary vary sorry for my delayed reply, my internet connection was vary low.

I have to tell you that, you are a great guy and a vary good programmer, your works are just fabulous and I am vary vary great full to you for your every expansive helps and shearing your works with me.

[Sliding screen]: your writeline.exe is working greatly,
it is doing what I was wanting. but it is consuming so much CPU time (i.e. 70% - 85%), is there any way to reduce the CPU consumption ??


[pid problem]: I have solved it with your suggestion.


[Schedtasks]: No problem, I will keep trying to find a solution.


But judago, is that possible to change the console,s font size, font type and font style with a command ??


Judago, how do I use your writeline.exe and wcde.exe together to get a beautiful combination of color control, position control, mouse click facility, with the non-sliding ability of your writeline.exe tool ???

Some thoughts, You can add a extra switch to your wcde.exe tool which will be abble to execute a external command like any other cmd tools (i.e. your writeline.exe , play.exe etc.) and will can be used together with /e , /ee , /c , /cr , /p , /pr and other switches. I thing it will extend the ability of your wcde tool a lot.


Again, thank you vary much Judago for your reply, and vary vary sorry for my delayed reply,

It is enough for a human to live as a human on earth...


Report •

#36
January 3, 2011 at 04:02:39
it is doing what I was wanting. but it is consuming so much CPU time (i.e. 70% - 85%), is there any way to reduce the CPU consumption ??

I'm only getting 0-18% on my machine overall when running, "writeline" isn't exactly a bloated pig(though some optimization could be found). So the only option would be to increase the delay between updates ......


But judago, is that possible to change the console,s font size, font type and font style with a command ??

It is but it it requires vista or later to work properly, since I only have xp I can't test or write it.

Judago, how do I use your writeline.exe and wcde.exe together to get a beautiful combination of color control, position control, mouse click facility, with the non-sliding ability of your writeline.exe tool ???

It's not possible at present, I would have to use a different API function(WriteConsoleOutput I think) the quickly put together "writeline" uses "WriteConsoleOutputCharacter" which is a little easier to use, but doesn't offer any colo[u]r facilities.

Some thoughts, You can add a extra switch to your wcde.exe tool which will be abble to execute a external command like any other cmd tools (i.e. your writeline.exe , play.exe etc.) and will can be used together with /e , /ee , /c , /cr , /p , /pr and other switches. I thing it will extend the ability of your wcde tool a lot.

I was thinking of integrating some of these things, but I'm in a bit of a situation at the moment; I could be moved out and without internet as soon as tomorrow. So I can't commit. If it ever gets done then I will send you a pm.


Report •

#37
January 3, 2011 at 15:26:15
Thank you vary vary much Judago for your reply,


I'm only getting 0-18% on my machine overall when running, "writeline" isn't
exactly a bloated pig(though some optimization could be found). So the only
option would be to increase the delay between updates ......


OK...


It is but it it requires vista or later to work properly, since I only have xp I
can't test or write it.


OK. not a problem...


It's not possible at present, I would have to use a different API
function(WriteConsoleOutput I think) the quickly put together "writeline" uses
"WriteConsoleOutputCharacter" which is a little easier to use, but doesn't offer any
colo[u]r facilities.


Now it is working more fab. but I gonna mis those colo[u]r facilities.


I was thinking of integrating some of these things, but I'm in a bit of a
situation at the moment; I could be moved out and without internet as soon as
tomorrow. So I can't commit. If it ever gets done then I will send you a pm.


if you are in some problem then I want to remember you that, you are a great guy judago, and great guys always wins, I will pray for you and I know you will overcome your problems soon.


Thanks for every thing you have done for me judago.

It is enough for a human to live as a human on earth...


Report •

#38
January 4, 2011 at 03:20:48
Thank you ;)

Ok I found some time and added two switches:

wcde /wav filename.wav
wcde /eline ypos strin gs and {colou,rs}

/wav is obvious but /eline is a bit different (similar to writeline.exe).

/eline writes the whole line, it always starts at x coord 0 and fills the entire line, if the input is larger than x size then it is cut, else spaces are appended. It accepts inline colo[u]r and slash pattens(except \x010 and \x013 - line end characters) like /e[e] .

It can't be used at the same time as /e[e].

Not fully tested, but seems to work.

http://judago.webs.com/downloads.ht...

As for the tasklist script:

    rem writeline !currentlines! "%%a" becomes:
    wcde /eline !currentlines! "%%a"

        rem writeline %%a " " becomes:
        wcde /eline %%a " "



Report •

#39
January 4, 2011 at 16:54:03
Welcome back Judago,

And thank you vary vary much for your reply,

Now your wcde 4.0 is more rocking...and working very good.

Judago, I want to learn C++, can you tell me about some ebooks for beginners freely downloadable form web ?? And what should I learn before start learning C++ ??


Another thing is, what is the difference between IDE and API ?? What should I get for coding in C++ ?? And which IDE or API should I use ??

Again, thank you vary vary much for your reply Judago,

It is enough for a human to live as a human on earth...


Report •

#40
January 4, 2011 at 17:26:45
No problem ;)

I can't suggest any books(or ebooks) as I mostly learnt from web tutorials, the web is full of content you only need to do a search. Anyway this is one of the better online tutorials: http://www.cplusplus.com/doc/tutorial/

IDE == Integrated Development Environment. Basically code editor, compiler and linker combined into one tool.

API == Application Programming Interface. Specifically I was talking about the Windows API. It's hard to navigate but the documentation is there somewhere: http://msdn.microsoft.com/en-us/lib...

It's really your choice as to the IDE/compiler you use, most people seem to use Visual Studio Express(microsoft), I have been using the rather outdated Dev-Cpp.....

There may be better languages to learn these days, c/c++ can be quite frustrating..


Report •

#41
January 4, 2011 at 17:41:58
I have been using the rather outdated Dev-Cpp.....
I was using Dev-Cpp (while manually updating MinGW, so I wasn't terribly out of date) because I wanted a nice portable IDE. Now I use Code::Blocks, and I like it.

As for languages, if you're going to do Windows development, I'd go with C#. As for C# books, Learning C# 3.0 comes recommended. I haven't read it myself, though.

How To Ask Questions The Smart Way


Report •

#42
January 5, 2011 at 16:24:46
Thank you vary much Judago for your reply.

Is the API do not contains any compiler yet ??

The msdn link was broken. it showing an error with error code 404,

                          

There may be better languages to learn these days, c/c++ can be quite
frustrating..


Judago, can you please tell me what those languages are ?? And have you meant that the C++ is difficult to learn or really frustrating ??

                          

Judago, is that possible with wcde /ic that the script would not be paused for a mouse left click, the script will be continued, but when a mouse left click is given then the wcde /ic will capture and process the click ???

                          

To listing running processes executables full directory path, I am using the bellow code:

wmic process get ProcessID,ExecutablePath

and I run it every time in admin. mode, but it is not collecting all processes path, it skipping some processes e.g. audiodg.exe , smss.exe etc. Is there any way to get all processes paths list without skipping any of them ???

                          

Again, Thank you vary vary much for your reply Judago.

It is enough for a human to live as a human on earth...


Report •

#43
January 5, 2011 at 16:47:50
Thank you vary much Razor2.3 for your reply,

I do not understand one thing that why use separate programing language(s) for separate type of OS(s), isn't there any Universal Type programing language which can be used to do programing in any kind of OS(s) ???

It is enough for a human to live as a human on earth...


Report •

#44
January 5, 2011 at 17:21:15
Is the API do not contains any compiler yet ??

Nope, it's just a bunch of system functions.


The msdn link was broken. it showing an error with error code 404,

http://msdn.microsoft.com/en-us/lib...

I accidentally put a dot at the end ...

Judago, can you please tell me what those languages are ?? And have you meant that the C++ is difficult to learn or really frustrating ??

C++ isn't really that bad and isn't a waste of time or anything, you just have to be careful when dealing with memory and pointers.

It depends on what you are doing, Razor suggested C# for windows development, for scripting python isn't too bad. All that I should have said it figure out what you are going to do most and try to pick an appropriate language.



Judago, is that possible with wcde /ic that the script would not be paused for a mouse left click, the script will be continued, but when a mouse left click is given then the wcde /ic will capture and process the click ???

Nope, not really. It waits because it's uses less resources that constantly being looped. If the script were to keep going then I'm not sure how it could pass anything back to the script.....

and I run it every time in admin. mode, but it is not collecting all processes path, it skipping some processes e.g. audiodg.exe , smss.exe etc. Is there any way to get all processes paths list without skipping any of them ???

Does tasklist /v show the paths?


Report •

#45
January 7, 2011 at 08:10:22
Thank you vary vary much Judago for your reply,

and vary vary sorry for my delayed reply.


Nope, it's just a bunch of system functions.

Judago, where the C++ have it's own "Standard" (i.e ANSI) function set, is the API adding some extra functions to the "Standard" C++ or replacing the "Standard C++ functions with it's own set of functions ??


I accidentally put a dot at the end ...

No problem.


C++ isn't really that bad and isn't a waste of time or anything, you just have
to be careful when dealing with memory and pointers.


O, OK.


It depends on what you are doing, Razor suggested C# for windows
development, for scripting python isn't too bad. All that I should have said it figure
out what you are going to do most and try to pick an appropriate language.


Actually Judago, I do not understand one thing (i.e. what I have said before to Razor2.3) that, why use different programing language for different type of OS ?? Isn't there any language for any thing ???


Nope, not really. It waits because it's uses less resources that constantly
being looped. If the script were to keep going then I'm not sure how it could pass
anything back to the script.....


OK, no problem.

Does tasklist /v show the paths?


No, tasklist /v do not shows any path !! I was meant the directory path of a process file where it is loaded from into RAM.


Judago, there is a problem I am facing, if you can help me to solve it, it will be rely vary great,


You know vary well that, what will be the output of tasklist command when used without any switches. Now the problem is, how to make a variable of the PID int. value when the line number of a line is known to me ???


there is a code I was wrote with some help of your previously suggested codes for testing purpose to solve the problem and it is working good but I want a batter and shorter solution for it. The code was as bellow:-


@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

set "line=hhh 55 hhady 27 4 9 smc 45 535 55 543 hh      2784 Services                    1      9,752 K"

set /a numb=1
set /a num=0

:start

set "tnum=!numb!"

for /f "tokens=%tnum% delims= " %%j in ("!line!") do (
   set "j=%%j"
   )

set /a "j_num"="!j!"
if "!j_num!" == "!j!" (
   goto :PID_Test
   ) else (
      goto :tnum_con
   )

:tnum_con
set /a numb = num+1
set /a num = numb
goto :start

:PID_Test
set /a PT_tnum=!tnum!+1
set "PT_tnumb=!PT_tnum!"

for /f "tokens=%PT_tnumb% delims= " %%k in ("!line!") do (
   set "k=%%k"

   )

if "!k!"=="Console" (
   goto :PID_Found
   ) else (
      if "!k!"=="Services" (
      goto :PID_Found
      ) else (
         goto :tnum_con
         )
      )

:PID_Found

echo:PID=!j!

pause


Again, thank you vary vary much Judago for your reply,

It is enough for a human to live as a human on earth...


Report •

#46
January 7, 2011 at 11:29:32
isn't there any Universal Type programing language which can be used to do programing in any kind of OS(s)
Sadly, no. Every platform has different (sometimes fundamental) abstractions, and this trickles down to every language. Higher level languages, like Python, will help you abstract some of the differences away, but not all of them. Often on a "universal" language like C/C++ is so bare bones, you'll need to learn the platform's API to accomplish your task. There are helper libraries out there for C++ (namely boost), but that becomes a third thing to learn.

Granted, knowing C/C++ allows you to move from Win32 to POSIX easier than someone who only knows C#, but nothing holds you to C# once you learn the basics of programming.

[wmic] is not collecting all processes path, it skipping some processes e.g. audiodg.exe , smss.exe
UAC is getting in the way; you need to elevate the script and run it as Administrator. Also, PID 0 and 4 will never has an executable path, because they're not really processes.

How To Ask Questions The Smart Way


Report •

#47
January 7, 2011 at 19:17:21
[The script part]

I don't really recognise the data, so I based the script on what you were doing:

Edit: That is one screwy image name ;) "/fo csv" works well too.

set last=
for %%a in (!line!) do (
    if /i "%%a"=="services" set pid=!last!
    if /i "%%a"=="console" set pid=!last!
    set last=%%a
)


Report •

#48
January 8, 2011 at 02:19:10
Thank you vary vary much judago for your reply,

Actually, I do not understand clearly what you are trying to tell.

and sorry for that,

It is enough for a human to live as a human on earth...


Report •

#49
January 8, 2011 at 02:41:26
I didn't recognise the tasklist output for all the other suff that was in place of the "image name" and that "tasklist /fo csv" will output as csv.

Did the script work?


Report •

#50
January 8, 2011 at 03:41:08
Thank you vary vary much Razor2.3 for your reply,

Razor, if the API have it's own function set so, is the API replaces the standard (i.e. ANSI) C++ function set with it's own function set or only adds some extra functions to Standard (i.e. ANSI) C++ function set ??

UAC is getting in the way; you need to elevate the script and run it as
Administrator. Also, PID 0 and 4 will never has an executable path, because they're
not really processes.


I always run the bellow WMIC code in administrator mode what I have told before,

wmic process get ProcessID,ExecutablePath


But, it is do not collecting all the processes path as I told before also, and yes, processes with PID 0 & 4 is not actual processes, there are virtual processes, so they don't have any path yet.

It is enough for a human to live as a human on earth...


Report •

#51
January 8, 2011 at 05:23:57
is the API replaces the standard (i.e. ANSI) C++ function set with it's own function set or only adds some extra functions to Standard (i.e. ANSI) C++ function set ??
It extends, but in an incompatible way. For instance, if you you're writting a Win32 program in C++, and you want to open up somefile.txt, you can use C's std::fopen(), or you can use C++'s std::ifstream, or you can use Win32's ::CreateFile(). Only one of them fits the style of the rest of the API.

I always run the bellow WMIC code in administrator mode
I suspect you're running as an Administrator, but not elevating the application (it won't prompt you for elevation, it'll just silently fail). The easiest way to test is to disable UAC, and run the command. Compare the output to when UAC is enabled.

they don't have any path yet.
They will never have a path.

How To Ask Questions The Smart Way


Report •

#52
January 9, 2011 at 08:52:55
Thank you vary much Judago for your replay,

and extremely sorry for my delayed replay.

I didn't recognise the tasklist output for all the other suff that was in place of
the "image name" and that "tasklist /fo csv" will output as csv.

csv is great. Actually I forgot that the csv is there. Thanks for remind me.


Did the script work?


Yes, it did it's job vary well.


Judago, A BIG problem is happening with some bat files, that those are running well in non-admin (i.e. normal mode) mode, but not running a bit even in admin mode. (i.e. just popping up and closing down) Why that type of thing is happening ???


And, Judago, is that possible to change the console buffer with mode command ??


Again, thank you vary much Judago for your replay,

It is enough for a human to live as a human on earth...


Report •

#53
January 9, 2011 at 08:59:11
Thank you vary Razor2.3 for your reply,

Only one of them fits the style of the rest of the API.

Razor, is the API have it's one or more style(s) ?? I mean what is that actually ??


but not elevating the application (it won't prompt you for elevation, it'll just
silently fail).


What is elevating a application means ??

EDIT: Did you mean elevating a program's permission ?? Then I want to know that, how to run a program or my bat file with elevated privilege (i.e. permission) to solve the wmic problem.

The easiest way to test is to disable UAC, and run the command. Compare
the output to when UAC is enabled.


I did some testing with my code as your suggestion, but it is still resulting the same as the output when UAC was enabled.


they don't have any path yet.
They will never have a path.

I have also meant the same.


Razor, A new problem is occurring with my bat that, I want to schedule a administrative task for n sec. using the schtasks command, and the n sec. can be greater then 31536000 sec. (i.e. approx. a year) also. Can you please tell me how to do that ???


Again, thank you vary Razor2.3 for your reply,

It is enough for a human to live as a human on earth...


Report •

#54
January 9, 2011 at 18:23:35
Judago, A BIG problem is happening with some bat files, that those are running well in non-admin (i.e. normal mode) mode, but not running a bit even in admin mode. (i.e. just popping up and closing down) Why that type of thing is happening ????

I'm running XP so no fancy UAC for me to mess with; I haven't got a clue.



And, Judago, is that possible to change the console buffer with mode command ??

Yes mode can size the buffer, but if I remember correctly you will have no control over window position and size.


Report •

#55
January 10, 2011 at 15:32:53
Thank you vary much Judago for your reply,

I'm running XP so no fancy UAC for me to mess with; I haven't got a clue.

Not a problem at-all, and I thing I have some possible clues now.


Yes mode can size the buffer, but if I remember correctly you will have no
control over window position and size.


yeah, mode dosen't have any control on window position and size.


Judago, which location of registry system (i.e. folder) would be the best to storing my bat program's settings (i.e. default settings, last selected tab settings etc.) without harming other registry entries ??

Actually, I want to store my bat program's default settings and the setting changes made by it's users into the registry and I want to know which location of the registry system would be the safer most to store my bat program's settings without harming any other registry entries.

(I know, it can be possible with some kind of files (e.g. text file) but files can be deleted or modified accidentally, yes, registry entries also can be deleted or modified accidentally too but it's probability is much lower then a file like .txt I think. That why I choose the registry.)

Can you please tell me about it ??


Aggain, thank you vary much Judago for your reply,

It is enough for a human to live as a human on earth...


Report •

#56
January 10, 2011 at 16:14:32
hkcu\software\companyname

All you have to do is pick a name that nobody else is likely to use......


Report •

#57
January 12, 2011 at 07:38:23
Thank you vary much Judago for your replay,

And vary sory for my delayed reply, actualy my internet connection is causing the problem.

If i am not wrong, in the hkcu c=current , u=user , k=key but the h= what ??

Judago how to rearrange the output of the tasklist (i.e. without any switch) command in alphabetical order.

I have get some success on that with the following code.


findstr /i /b /c:A "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:B "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:C "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:D "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:E "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:F "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:G "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:H "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:I "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:J "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:K "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:L "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:M "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:N "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:O "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:P "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:Q "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:R "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:S "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:T "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:U "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:V "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:W "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:X "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:Y "%temp%\plist_Q.txt">>O_plist.txt
findstr /i /b /c:Z "%temp%\plist_Q.txt">>O_plist.txt

(it is not the complete code but the main processing module)


but, it is only processing the first alphabet of each line.

I want to process each and every alphabet of each line to alphabetically reordering the output and it is quite difficult with that code because the lines which the code is processing not have any fixed length.


Judago, can you give me some thing better then it ??
(If I have to use any other cmd tools, I haven't any problem)

Again, thank you vary much Judago for your replay,

It is enough for a human to live as a human on earth...


Report •

#58
January 12, 2011 at 08:10:48
If i am not wrong, in the hkcu c=current , u=user , k=key but the h= what ??

Hive: http://blogs.msdn.com/b/oldnewthing...

Judago how to rearrange the output of the tasklist (i.e. without any switch) command in alphabetical order.

Tasklist /nh | sort


I know /nh is a switch, but if you really want the header you can output it using echo



Report •

#59
January 12, 2011 at 17:16:48
Razor, A new problem is occurring with my bat that, I want to schedule a administrative task for n sec. using the schtasks command, and the n sec. can be greater then 31536000 sec. (i.e. approx. a year) also. Can you please tell me how to do that ???
I'm not sure what you're asking for. If you want your script to run for over a year, then just let it run. If you want to schedule it for sometime in the future, then set its start date to a year in the future.

Actually, I want to store my bat program's default settings and the setting changes made by it's users into the registry and I want to know which location of the registry system would be the safer most to store my bat program's settings without harming any other registry entries.
Don't do this. The registry destroys the very concept of portability between platforms. A better idea is to have a settings file in the same directory as your script. Plus, if you do it right, it's easier to pull data in and out of the file.

Actually, while we're on the subject, what are you trying to do? I suspect you might be trying to reinvent a wheel here.

How To Ask Questions The Smart Way


Report •

#60
January 14, 2011 at 14:23:00
Thank you vary much Judago for your reply,

And vary vary sorry for my delayed reply,
(My modem is causing some problems till some days, it is not accessing the net properly, so, I am getting vary low speed internet connection.)


So, it is hive And thanks for the web link.


Alphabetically Re-Ordering Problem: the sort is great, and vary good one-liner. (Actually I didn't knew the sort command.)


I know /nh is a switch, but if you really want the header you can output it
using echo

No problem, I have managed to place the header at the needed position with your wcde.exe v4.0 tool instead of using echo because, echo isn't supports any color parameter which I need.


However, there are two problems occurring in my bat. If you can find answer it will be really vary great.


Problem1:

How to add or place or/and delete a text string at/from the right side or at/from the left side of a text string without using FOR /F ?? (The text strings can contains any characters that a bat file can support.)


Problem2:

There is three text strings that I want to append in a file. The strings are as bellow:

nircmd execmd taskkill /f /pid nircmd.exe >nul 2>&1
nircmd setcursorwin 724 9
nircmd sendmouse left click

                          (>nul 2>&1
in the frist string is
vary vary
important.
)


To do that, I was using the following:

@echo off
echo:nircmd execmd taskkill /f /pid nircmd.exe >nul 2>&1 >EXIT.txt
echo:nircmd setcursorwin 724 9 >>EXIT.txt
echo:nircmd sendmouse left click >>EXIT.txt

It was OK for the 2nd & 3rd strings but, with the third string it is resulting only the following:

nircmd execmd taskkill /f /pid nircmd.exe
, it is ignoring the
 >nul 2>&1
string that I do not want it to ignore.

I know it is because of the > sign,

Then I tried as to double quoting the first string, now it is resulting the full string but with the quotes, like as bellow:

"nircmd execmd taskkill /f /pid nircmd.exe >nul 2>&1"


But I do not want the double quotes to be added to the resulting string.


Then I tried to remove the the double quotes from the appended first string using the FOR /F command but isn't works a bit even, I think, FOR /F insn't supports the " character as a delimiter may be because, in the FOR /F, the TOKENS , DELIMS , EOL etc. it selves is placed into double quots.

What to do judago ??


Again, thank you vary much Judago for your reply,

It is enough for a human to live as a human on earth...


Report •

#61
January 14, 2011 at 18:18:02
Problem 1

Inserting/appending text to a string is pretty easy, just set a variable:

set string=middle
set string=insert%string%append

Removing strings gets trickier, to remove from the end you will basically have to use substring, possibly with a goto loop.


set string=sadfdsfdfthe
if "%string:~-3%"=="the" set string=%string:~0,-3%

Without using for you can either use the same as above or the wilcard/string replace(only works at the front of a variable.

set string=dswfsdfdsthesdfdf
set string=%string:*the=%

Some characters need to be escaped, depending on how you actually do things !vars! tend automatically escape.

Problem 2:

echo %% ^| ^< ^> ^& ^^

echo:nircmd execmd taskkill /f /pid nircmd.exe ^>nul 2^>^&1 >EXIT.txt


Report •

#62
January 16, 2011 at 19:53:21
Thank you vary vary much Razor for your reply,

And vary vary sorry also for delayed reply. My modem is creating complications to accessing the net.

I'm not sure what you're asking for. If you want your script to run for over a
year, then just let it run. If you want to schedule it for sometime in the future, then
set its start date to a year in the future.

I was just trying to ask you that, I want to schedule a admin task for a time period
which can be 100 sec. , 1758 sec. 7654 sec. or any sec. between 1 to 31536000
sec. how to do that with schtasks command. And I don't want to pass the
time value to the schtasks tool in hh.mm.ss etc. format, I want to pass
the time value to it in sec.

How to do that ??


Don't do this. The registry destroys the very concept of portability between
platforms. A better idea is to have a settings file in the same directory as your
script. Plus, if you do it right, it's easier to pull data in and out of the file.


Yeah, I agree, and I think, in that case, I should make a setting file and make the file inaccessible to the user with cacls or icacls etc. and when my script have needing to access it then I will make setting file accessible and when the needing will be completed then I will make the file inaccessible to the user and this is the cycle that will be running continuously till my script is closed.

I think, that should make the setting file a bit secure then a normal file, plz tell me what do you think ??

Actually, while we're on the subject, what are you trying to do? I suspect you
might be trying to reinvent a wheel here.


What I want to do is to make a program that can do works like "Windows Task Manager" but in console mode and with some added functionalities also like suspend/resume a process , restart a process etc. etc.

I don't know it is reinventing or not, but the Wheel is not happening because, bat is a script language (Can I call it a programing/scripting language? I don't know.)

However, I have a plane to make Wheel, if it is possible to track strictly the program's console window position and if it is possible to strictly track mouse cursor position and left button click position coordinate with a separate bat file then it is possible to make a bat Wheel.

I suspect you might be trying to reinvent a wheel here.

If I ever get succeed to turn the Wheel Concept a reality with bat in future then it will not be my invention, it will be a Joint Effort, because, many helpful peoples have helped and helping me like YOU , JUDAGO , M2 and so many to continuously do work on it.

And, it is not for the Wheel it self only, it is for the entire app. what I am trying to make.

Again, Thanks you vary much for your replay Razor.


It is enough for a human to live as a human on earth...


Report •

#63
January 19, 2011 at 11:35:40
Thank you vary much Judago for your replay,

And vary vary sorry for my vary delayed replay,

Inserting string was known to me, but I did not knew the removing trick.

After get your post, I found some similar but extended like your trick in the http://ss64.com/nt/syntax-substring.html web page.


With the second problem, your solution is working vary good.

But, after my posting to you, I get some success on it also, with the bellow code:

set "ABCD=>nul 2>&1"
echo:nircmd execmd taskkill /f /pid nircmd.exe !ABCD!>AAAA.txt

However, there is some more problems,


How to know that a bat file which is executed, is that executed with admin privilege or with normal privilege ??


And another problem is, how to know with bat that the logged on user is an admin or not ??


The third problem is, how to run a bat file with SYSTEM Privilege ??

And I also want to know that what is the highest Privilege which can be achieved in a computer ??

Judago one small request to you, can you give the ability to support inline color to your WCDE's eline switch ?? It will be a great enhancement, and will be vary useful to me also.


Again, Thank you vary vary much Judago for your replay.

It is enough for a human to live as a human on earth...


Report •

#64
January 19, 2011 at 15:45:12

How to know that a bat file which is executed, is that executed with admin privilege or with normal privilege ??


And another problem is, how to know with bat that the logged on user is an admin or not ??

Privileges/permissions aren't really my area, but I here OPENFILES works well to test if the script is elevated.


Judago one small request to you, can you give the ability to support inline color to your WCDE's eline switch ?? It will be a great enhancement, and will be vary useful to me also.

/eline has always supported inline colour.

wcde /eline 0 "{+1,+1}H{+1,+1}E{+1,+1}L{+1,+1}L{+1,+1}O{+1,+1}!"



Report •

#65
January 22, 2011 at 13:42:01
And I don't want to pass the
time value to the schtasks tool in hh.mm.ss etc. format, I want to pass
the time value to it in sec.

How to do that ??
You don't. Take your seconds, and convert it to an hh.mm.ss format.

I think, that should make the setting file a bit secure then a normal file, plz tell me what do you think ??
You cannot protect yourself against the user. If the user wishes it, he will get access to your file. You cannot stop him.

What I want to do is to make a program that can do works like "Windows Task Manager" but in console mode and with some added functionalities also like suspend/resume a process , restart a process etc. etc.
There's already tasklist and taskkill, what else are you looking for? The only other ability you mentioned was suspending a process, and you need a language that can interface with the Win32 API to do that.

I don't know it is reinventing or not, but the Wheel is not happening because,
Reinventing the wheel is an idiom. It means you're making something that's already made. Generally, you end up re-making it poorly.

How to know that a bat file which is executed, is that executed with admin privilege or with normal privilege ??
You really can't; there's no interface for scripts to read their security token. The best workaround would be to call a process that does check its permissions. Running fsutil as a user will set the errorlevel to 1.

The third problem is, how to run a bat file with SYSTEM Privilege ??
Start it with the SYSTEM account. PSTools might help there.

How To Ask Questions The Smart Way


Report •

#66
January 24, 2011 at 05:02:41
Thank you vary much Judago for your reply,

And, Vary Vary sorry for my vary delayed reply, the cause was my modem,

Privileges/permissions aren't really my area, but I here OPENFILES works
well to test if the script is elevated.


OK, I can manage. but, do you know any "OPENFILES works" that I can use ??


/eline has always supported inline colour.


Oh, actually, My question was wrong !!! You have told it before that it supports inline colors, but I wanna ask you /eline writes a complete line and starts from 0 X coord, is that possible to make a color full partial line like /e[e] switch but with the /eline's ability ??

I mean, e.g. is that possible to make a color full partial line from 11 or 15 X coordinate to 55 or 67 X coordinate where the end X coordinate value of the console buffer is 350 or 569 ?? It can be a optional sub switch of /eline.


Again thank you vary much Judago for your reply.

It is enough for a human to live as a human on earth...


Report •

#67
January 24, 2011 at 19:46:47
http://ss64.com/nt/openfiles.html


http://judago.webs.com/downloads.ht...

/edirect xpos ypos "to be displayed without a linebreak" "can roll over onto other lines".

I'm tired of messing with wcde, this is the last switch.


Report •

#68
January 28, 2011 at 15:30:21
Thank you Razor for your reply,

And Vary Vary sorry for delayed reply,

You don't. Take your seconds, and convert it to an hh.mm.ss format.


But, how to convert sec. to hh.mm.ss, in my knowledge there is no such things in batch to do floating point calculations and set /a is vary limited and do not supports floating points.

Yeah, I know, it is possible to do floating point calculations with bat, but then you have to teach the comp. that how to do a division, multiplication etc. jobs

Do you know any process or any utility to do this type of jobs easily ???


You cannot protect yourself against the user. If the user wishes it, he will get
access to your file. You cannot stop him.

I think, every people who can run a comp. they also can open a txt file, but if the text file is locked or protected then many peoples don't know how to get access to it. This is the advantage. And there is also some cmd tools to change the owner of a file or folder (e.g. chown.exe by Alexander Frink)

If any body have the know-how that how to get access to a locked or protected file or how to take-over the ownership of a file or folder then he/she can get access to it any time.


There's already tasklist and taskkill, what else are you looking for? The only
other ability you mentioned was suspending a process, and you need a language
that can interface with the Win32 API to do that.


Maybe you are right, but there is some cmd tools which can do this kind of works. e.g. PSSUSPEND.EXE. This cmd tool is a part of PsTools package v2.44 from Mark Russinovich's Sysinternals.


Reinventing the wheel is an idiom. It means you're making something that's
already made. Generally, you end up re-making it poorly.


Oh, I didn't knew it, I thought you are talking about the Cyclic Update of the console without losing other abilities. But what I have told you (with out knowing the proper meaning) that was true.


Now I am telling you, I am just trying to make some thing own, it is not a replacement of windows task manager by any means. It is only my learning process, and that bat project is just only for my practicing purpose.

You really can't; there's no interface for scripts to read their security token.
The best workaround would be to call a process that does check its permissions.
Running fsutil as a user will set the errorlevel to 1.

Actually, Judago's suggestion to use OPENFILES command is working vary good.

But, other similar concept ways also there, e.g. make a file (e.g. txt file) , modify its ACL and make sure that only an administrator can read or access it, then try to read it with a bat file, if that bat file can read it then it is running with administrative privilege or it is elevated else the bat file is not elevated.

I planned it before I get the suggestion about OPENFILES command from Judago, but now i am using OPENFILES because it's easier.


However, I want to know, is the all versions of XP , VISTA & WIN 7 comes with OPENFILES , FSUTIL , WMIC, I mean, is they installed by default ???


Start it with the SYSTEM account. PSTools might help there.

I always log-on to my comp. with admin account but what is system account ??
I mean, how do i log in to SYSTEM ACCOUNT ?? Do you mean to run a bat file using AUTOEXEC.BAT or AUTOEXEC.NT ??

(I am using "WINDOWS 7 ULTIMATE v6.1.7600")


If i am not wrong, vista and win7 doesn't supports AUTOEXEC.BAT to execute things at start up, I think, it is only there for backward compatibilities, am I correct ??

And what about the AUTOEXEC.NT ?? Can you tell me some thing ??


The WMIC problem is still unsolved, can you give me some solution?


Again, thank you Razor for your reply,

It is enough for a human to live as a human on earth...


Report •

#69
January 28, 2011 at 16:23:33
But, how to convert sec. to hh.mm.ss, in my knowledge there is no such things in batch to do floating point calculations and set /a is vary limited and do not supports floating points.
You still have division and modulo. You shouldn't need anything else.

How To Ask Questions The Smart Way


Report •

#70
January 28, 2011 at 16:24:56
Thank you vary much Judago for your reply,

And, again vary vary sorry for my delayed reply,


So, "openfiles" is a cmd command, it is working vary good,


/edirect is really vary good, now, this is the thing I was wanting. It is working vary cool.


However, There is some more problems occurring,

How do I count or test that, how much characters there is in a text line ??

And, how do I make separate variables for each separate characters of a line in start to end and end to start order ??
(i.e. the line can contains any ASCII characters.)

Again, thank you vary much Judago for your reply

It is enough for a human to live as a human on earth...


Report •

#71
January 28, 2011 at 16:52:52
Unfortunately to get the length/each character your going to need to loop through with substrings until the string is empty.

@echo off
SetLocal EnableDelayedExpansion


set string=^&^|^^!sdf5648989sdsds
set length=0

:walk
echo !string:~%length%,1!
set /a length+=1
if not "!string:~%length%!"=="" goto walk

echo %length% characters

pause


Report •

#72
February 12, 2011 at 08:10:37
Thank you very much Razor for your reply.

And vary vary sorry for my delayed reply. My modem problem is not solved.

You still have division and modulo. You shouldn't need anything else.


But where ?? Yeah, Judago's division bat prog. is there but where is the modulo ??

However, I found 2 command line utilities in the net. when my modem was working...


1st is the math.exe from http://www.hyperionics.com by Greg Kochaniak


and the 2nd is conset.exe by Frank P. Westlake (I lost the site address unfortunately)


conset is much extended.


Both are working vary good.


The bellow is working good for me.

schtasks /create /rl highest /f /sc once /st 14:11:00 /sd 02/10/2011 /tn TEST_TASK_1 /tr "cmd /c wcde /b 1000 5000"

But the /z switch is not working there, can you tell me why ??


Razor, for my wmic problem you have said before that the elevation is silently failing, that’s why it is not outputting all the currently running processes paths.

But, how to fix that problem ??


Again, thank you very much Razor for your reply.

It is enough for a human to live as a human on earth...


Report •

#73
February 12, 2011 at 11:50:16
Both are working vary good.
If you say so, but it seems like a lot of work when SET /A has its modulus operator (%, %% in a batch file).

But the /z switch is not working there, can you tell me why ??
No idea; presumably a bug in schtasks.

But, how to fix that problem ??
You specify /rl highest. If it's not working, it's either a bug in your script, or the account you're using doesn't have permissions you require.

How To Ask Questions The Smart Way


Report •

#74
February 17, 2011 at 06:32:41
Thank you very much Judago for your reply.

And vary vary sorry for my very delayed reply. My modem was crashed down.


Judago your code is working very good,


But there is one more problem...


Is there any way to Check a email Address is valid or not with BAT ??

(Valid in the sense have existence or haven't exists.)

Again, thank you very much Judago for your reply.

It is enough for a human to live as a human on earth...


Report •

#75
February 17, 2011 at 06:46:51
Thank you vary much Razor for your reply,

And vary vary sorry for my delayed reply,


but it seems like a lot of work when SET /A has its modulus operator (%, %%
in a batch file).

Oh, I didn't knew, But how to use that I mean the syntax ??


it's either a bug in your script, or the account you're using doesn't have
permissions you require.

I dont know my script have or have not bug[s] or not I will check,

I always login to my comp. as an administrator.

but what is the problem ?? can you tell me some thing more ??

Again, thank you vary much Razor for your reply,

It is enough for a human to live as a human on earth...


Report •

#76
February 17, 2011 at 15:39:59

Is there any way to Check a email Address is valid or not with BAT ??

(Valid in the sense have existence or haven't exists.)

Not that I know of, there used to be online checkers(along the lines of whois), but I think SPAM has killed them off.


rem secs to h:m:s
rem if you want leading zeros it's not hard to add...

set secs=3661

set /a hrs=secs / 3600
set /a secs %%= 3600

set /a mins=secs / 60
set /a secs %%= 60

echo %hrs%:%mins%:%secs%

pause


Report •

#77
April 14, 2011 at 12:07:59
Thank you vary much JUDAGO for your replay,

I M back now, I was in some troubles that why the delay happened to replay, and vary vary sorry for that.

email problem is not solved till now, but the "modulo" problem is solved with your replay.


but, there is a problem with making "global variables" in my bat script.

Bellow is a sample batch script to just only describe my problem,

@echo off
setlocal enableextensions enabledelayedexpansion

set "round_str=%1"

if "!round_str:~0,1!"=="+" (
set "XXX=!round_str:~1!"
set id=1
)

if "!round_str:~0,1!"=="-" (
set "XXX=!round_str:~1!"
set id=2
)

:loop

if "!XXX:~0,1!"=="0" (
set "XXX=!XXX:~1!"
goto :loop
)

if !id! equ 1 set "round_str=+!XXX!"

if !id! equ 2 set "round_str=-!XXX!"

for /f "tokens=1* delims=." %%a in ("!round_str!") do (
set "b4.=%%a"
set "aftr.=%%b"
)

if "!b4.!"=="!round_str!" (
if "%~2"=="" echo:!b4.!
if not "%~2"=="" (
   endlocal
   set %~2=%b4.%
   )
goto :EOF
)

if ".!b4.!"=="!round_str!" (
if "%~2"=="" echo:!b4.!
if not "%~2"=="" (
   endlocal
   set %~2=%b4.%
   )
goto :EOF
)

if not "!b4.!"=="!round_str!" (
if %aftr.:~0,1% lss 5 (
if "%~2"=="" echo:!b4.!
   if not "%~2"=="" (
      endlocal
      set %~2=%b4.%
      )
   goto :EOF
   )
if %aftr.:~0,1% geq 5 (
   set "tmp=!b4.:~-1!"
   set /a tmp+=1
if "%~2"=="" echo:%b4.:~0,-1%!tmp!
   if not "%~2"=="" (
      set "tmpout=%b4.:~0,-1%!tmp!"
      endlocal
      set %~2=%tmpout%
      )
   goto :EOF
   )
)

::The script ends here.


This sample batch script is for round a number, first argument is the number to round and the 2nd argument [optional] is variable name to assign the rounded output with that,

All things were going well but in the 66th line of that script the global variable is not happening. Other global variable assignations are working good.


What is the problem with the 66th line, what is the wrong with it ??

Please help me

Again thanks for your replay judago

It is enough for a human to live as a human on earth...


Report •

#78
April 14, 2011 at 16:04:10
The problem is the variable expansion stuff again, you set tmpout within the if statement you use it:

if "%~2"=="" echo:%b4.:~0,-1%!tmp!
   if not "%~2"=="" (
      set "tmpout=%b4.:~0,-1%!tmp!"
      endlocal
      set %~2=%tmpout%
      )
   goto :EOF
   )
)

Workaround:

if %aftr.:~0,1% geq 5 (
    set "tmp=!b4.:~-1!"
    set /a tmp+=1
    if "%~2"=="" echo:%b4.:~0,-1%!tmp!
    if not "%~2"=="" (
        set "tmpout=%b4.:~0,-1%!tmp!"
        for /f "delims=" %%a in ("!tmpout!") do (
          endlocal
          set %~2=%%a
        )
    )
    goto :EOF
    )
)


Report •

#79
April 16, 2011 at 22:50:15
Thank you vary much JUDAGO for your replay,

With the "for /f" it is working vary good.

And I have a new question !!

Is that possible to pipe something [e.g. string] to a bat file as a argument ??


again, thank you vary much JUDAGO for your replay,

It is enough for a human to live as a human on earth...


Report •

#80
April 16, 2011 at 22:59:00
Is that possible to pipe something [e.g. string] to a bat file as a argument ??

Which is it pipe or argument?


A batch can't open a pipe but it could use find or more in for /f to take from a pipe:

for /f "delims=" %%a in ('more') do echo %%a

Arguments:

%* and %0 - %9

%* - all arguments.
%0 - this script
%1 - %9 - first nine arguments

"Shift" makes the content of %1 become the content of %2, and so on so you can loop through more than nine arguments.


Report •

#81
April 17, 2011 at 04:59:45
Thank you vary much JUDAGO for your replay,

I was testing your piping code, it is working good but I found some thing that it should not do.

1:> If a PAUSE command is issued after or before the code, it is behaving like as
any key is already pressed at the PAUSE prompt.

2:> If a TIMEOUT command is issued after or before the code, it is showing an
error as bellow:
"ERROR: Input redirection is not supported, exiting the process immediately."
But the PING is working as delayer.

3:> [It is the most dangerous] If any piping is not used then the script is just
hanging to infinity !!


How to deal with those problems ??



 

The Second Problem is :-
I have made a bat script to do floating point mathematics witch use VBScript as the math processor. The Script is as bellow:


@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

for /f "tokens=*" %%a in ("WScript.exe") do (
if "%%a"=="" echo:ERROR: "WScript.exe" not found&goto :EOF
)

echo:Option Explicit>VbsCalScr.vbs
echo:Dim CalOut>>VbsCalScr.vbs
echo:Dim FSO>>VbsCalScr.vbs
echo:Dim objStream>>VbsCalScr.vbs
echo:CalOut = %~1>>VbsCalScr.vbs
echo:Const TristateFalse ^= ^0>>VbsCalScr.vbs
echo:Const FILE_NAME = "Math_Result.txt">>VbsCalScr.vbs
echo:Set FSO = Createobject("Scripting.FileSystemObject")>>VbsCalScr.vbs
echo:Set objStream = FSO.CreateTextFile(FILE_NAME, _>>VbsCalScr.vbs
echo:   True, TristateFalse)>>VbsCalScr.vbs
echo:With objStream>>VbsCalScr.vbs
echo:   .WriteLine CalOut>>VbsCalScr.vbs
echo:   .Close>>VbsCalScr.vbs
echo:End With>>VbsCalScr.vbs

echo:CreateObject("Wscript.Shell").Run """" ^& WScript.Arguments(0) ^& """", 0, False>invisible.vbs

wscript.exe "invisible.vbs" "VbsCalScr.vbs"

ping localhost -n 1 >nul 2>&1
ping localhost -n 1 >nul 2>&1
ping localhost -n 1 >nul 2>&1


:back1
if exist "invisible.vbs" (del /f /q "invisible.vbs"||goto :back1)

:back2
if exist "VbsCalScr.vbs" (del /f /q "VbsCalScr.vbs"||goto :back2)

if exist "Math_Result.txt" (
   for /f "tokens=*" %%b in (Math_Result.txt) do (
   if "%~2"=="" echo:%%b
   if not "%~2"=="" (
      endlocal
      set %~2=%%b
      )
   )
) else (
   echo:ERROR: Math Processer was failed to give output
   )

:back3
if exist "Math_Result.txt" (del /f /q "Math_Result.txt"||goto :back3)

goto :EOF

~:Script ends here:~

All things were going well but if you look at it you will find that I have used a unnecessary command "PING" for nothing but add some delay.

Cause of it was, I found that, if I do not add a delay the "WScript" is showing an "error msg" that it could not find the "VbsCalScr.vbs" file witch is the main Math Processor created by the main bat script.

but, when the sufficient delay is added, it works good.

Now, my question is, why is that happening ??

Is that because of the "WScript" was executing the "VbsCalScr.vbs" file before it can be completely created ??

but, the delay is slowing downg the hole script,

Is there any way that I don't have to add the delay ??


Again, thank you vary much JUDAGO for your replay,

It is enough for a human to live as a human on earth...


Report •

#82
April 17, 2011 at 23:44:50
How to deal with those problems ??

For the most part you can't, you could do some condition stuff with arguments but that's about it.

BTW the last one doesn't actually hang it waits for user input, when the user hits ctrl+z and enter it will continue.

Now, my question is, why is that happening ??

Is that because of the "WScript" was executing the "VbsCalScr.vbs" file before it can be completely created ??

but, the delay is slowing downg the hole script,

Is there any way that I don't have to add the delay ??

I'm not sure exactly what the issue is, but your guess makes sense. perhaps you could try "type filename > nul", it may help.


Report •

#83
April 19, 2011 at 06:24:48
Thank you JUDAGO for your replay,

Sorry for the misobservation about hanging.

I'm not sure exactly what the issue is, but your guess makes sense. perhaps
you could try "type filename > nul", it may help.

I have doubt about my guess because, I have not added the delay before the WScript execution, I have added it after the execution of WScript. because bat file is a script so it should first execute the wscript command and then the dellay command[s], So how the delay is supporting the file creation operation to be completed properly.

If some delay of about 10 sec. is added after the redirections to give some time to complete the creation of those files and if you now execute the WScript after that delay you will see that the same thing is happening again. [i.e. no delay after WScript execution is used]

I think, In the case of that script, the delay is working like a pillar bellow the roof (LOL) supporting and giving time to WScript to read and run things properly.

Is that a bug of WScript or WScript is not fully compatible with CMD or it is the CMD is not compatible or cmd have a bug ???

I want to know your opinion and suggestion.






perhaps you could try "type filename > nul", it may help.

I do not understand properly what you've told.

Where to use the "type filename > nul" ??

My guess is, into the for /f , am I right ??

or it is to use in the place of the delay ??

I have tried it as my guesses but it is not working


Can you give me some more help on it ??? I really need it !!

Again, thank you vary much for your replay,

It is enough for a human to live as a human on earth...


Report •

#84
April 19, 2011 at 16:59:49
I don't know a lot of vbs, but perhaps you should just used cscript.exe:

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

for /f "tokens=*" %%a in ("cScript.exe") do (
    if "%%~$path:a"=="" (
        echo:ERROR: "CScript.exe" not found in path
        goto :EOF
    )
)

(
    echo:Option Explicit
    echo:Dim CalOut
    echo:CalOut = %~1
    echo:wscript.echo CalOut
) > VbsCalScr.vbs



for /f "tokens=1,2 delims=)" %%a in (' 2^>^&1 cscript //nologo VbsCalScr.vbs') do (
    if not "%%b"=="" (
        echo:ERROR: Math Processer was failed to give output
    ) else (
        if "%~2"=="" (
            echo:%%a
        ) else (
            endlocal
            set %~2=%%a
        )
    )
)

:back2
if exist "VbsCalScr.vbs" (del /f /q "VbsCalScr.vbs"||goto :back2)


goto :EOF


Report •

#85
May 15, 2011 at 13:34:14
Thank you vary much JUDAGO for your replay,

And vary vary sorry for my vary delayed reply, you know, "problem" and "life" both are similar words

My knowledge in VBScript is also vary preliminary. Just started learning it Aprox. less then a week ago. [i.e. from your last post]

Your script is vary good but I am getting a problem in it,

If input have some parenthesis, then it is showing an error.

[e.g.]
if input is 1063/2 then it is going good but if input is ((((233/3)*2)+3)-1*month(date))/2 then it is giving error that *2)+3)-1*month(date))/2 was unexpected at this time."


I found the bellow was causing the error:

(
    echo:Option Explicit
    echo:Dim CalOut
    echo:CalOut = %~1
    echo:wscript.echo CalOut
) > VbsCalScr.vbs


So, I changed it to that:

echo:Option Explicit>VbsCalScr.vbs
echo:Dim CalOut>>VbsCalScr.vbs
echo:CalOut = %~1>>VbsCalScr.vbs
echo:wscript.echo CalOut>>VbsCalScr.vbs


the bellow code is not working also:

:back2
if exist "VbsCalScr.vbs" (del /f /q "VbsCalScr.vbs"||goto :back2)

Because, I found, in my computer, DEL is outputting "0" as errorlevel even when it is failing to delete some thing,

So, this code should work good:

:back2
set /a cnt+=1
if exist "VbsCalScr.vbs" del /f /q "VbsCalScr.vbs"
if !cnt! leq 5 if exist "VbsCalScr.vbs" goto :back2


Now it is doing it's all jobs vary well.

Vary good and short script but with huge abilities





The problem with my previously posted script is now solved, now it do not need the "delay".

There was a small mistake in the "invisible.vbs".

The optional bWaitOnReturn was FALSE, that why it was not waiting for the completion of the current execution and was going to the next statement to execute.

Replacing the "FALSE" with the "TRUE" will solve the problem.





Q:#1> However: Is that possible to set multiple lines of string in a single variable at a time in bat ?? I mean, can a variable contains multiple lines of strings at a time in bat??

Q:#2> Do you know any thing about how to get the stranded "open file" dialog box in VBScript ??

Again, Thank you vary much for your replay JUDAGO,

It is enough for a human to live as a human on earth...


Report •

#86
May 15, 2011 at 23:44:09
#1: No, a variable can't hold a cr of lf(line end characters).

#2: I don't know the specifics.

Regarding the parans, replace:

    echo:CalOut = %~1

with:

    for /f "delims=" %%a in ("%~1") do echo:CalOut = %%a

You don't need the "invisable" script, that is what cscript is for.


Report •

#87
May 17, 2011 at 14:39:19
Thank you vary much JUDAGO for your replay,

#1: No, a variable can't hold a cr of lf(line end characters).

OK, but I think, REG_MULTY_SZ data type of registry can help !!

Is that possible to expend REG_MULTY_SZ registry value like environment variable with some trick ??




#2: I don't know the specifics.

OK, not a problem, I will be digging... !!




Regarding the parans, replace:

for /f was good !!




Again, thank you vary much for your replay JUDAGO,

It is enough for a human to live as a human on earth...


Report •

#88
May 17, 2011 at 14:55:07
Q:#2> Do you know any thing about how to get the stranded "open file" dialog box in VBScript ??
There used to be a UserAccounts.CommonDialog, but it was removed in Vista. So it goes.

How To Ask Questions The Smart Way


Report •

#89
May 17, 2011 at 16:40:54
Thank you vary much RAZOR for your replay,

There used to be a UserAccounts.CommonDialog, but it was removed in Vista. So it goes.

I know little-bit about UserAccounts.CommonDialog

But, is there any way to do that in VISTA and WIN7 ??

Or, any common way for XP, VISTA and WIN7 ??

(I am a novice in VBScript so PLEASE be explicit)

Again, Thank you vary much for your replay RAZOR,

It is enough for a human to live as a human on earth...


Report •

Ask Question