Make a variable of text

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

I have 3 problems,

Problem 1:-
I have a text file called "path.txt" (without dabble quotes). that contains following,

Executable Path__________________________________Process ID

C:\Windows\system32\taskhost.exe 1924
C:\Program Files\PowerISO\PWRISOVM.EXE 1112
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe 2064
C:\Program Files\Microsoft Office\Office12\GrooveMonitor.exe 2100
C:\Program Files\Synaptics\SynTP\SynTPEnh.exe 2160
C:\Program Files\Acer Bio Protection\PdtWzd.exe 2184
C:\Program Files\BSNL 3G Data Card\BSNL 3G\Resource\MCtlSuc.exe 2272
C:\Program Files\Common Files\Java\Java Update\jusched.exe 2284
C:\Windows\system32\svchost.exe 2300
C:\Program Files\uTorrent\uTorrent.exe 2336
C:\Program Files\Common Files\Nero\Nero BackItUp 4\NBCore.exe 2352
C:\Program Files\WIDCOMM\Bluetooth Software\BTTray.exe 2400
C:\Program Files\Synaptics\SynTP\SynTPHelper.exe 2656
C:\Windows\system32\SearchIndexer.exe 2796
C:\Windows\System32\svchost.exe 2372
C:\Windows\System32\cmd.exe 2012
C:\Windows\system32\conhost.exe 1856

Considerations:-
(The line order and number of lines is changeable and I don't know how much line it have actually. These lines can contains multiple spaces, dots(.) commas(,), any digits
(0to9), any brakes etc.)


I want to make a variable of a left side string of a line from the given path.txt content example..............

Example of "left side string" from the path.txt content example given above:-

"C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe" (without dabble quotes)
or "C:\Windows\System32\cmd.exe" (without dabble quotes)


but, the variable should not carry the complete line
e.g. "C:\Windows\system32\taskhost.exe 1924 " (without dabble quotes)

or, only "C:\Windows\System32\" (without dabble quotes)

Currently i am using the following Code :-


@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:reload
cls
cd "!temp!"

set "FIND=%windir%\system32\find.exe"
set "wmic=%windir%\System32\Wbem\wmic.exe"
set "Explore=%windir%\explorer.exe"

TASKLIST
!wmic! process get ProcessID,ExecutablePath >"path.txt"

echo:
echo:
set /p ProsID="Type a PID: "

if not defined ProsID (
echo:PID is not defined...
echo:Press any key to goto reload...
pause>nul
goto :clr_var
) else (
goto :E_1
)

:E_1
if !ProsID! lss 10 (
echo:Can not Explorer Critical Process.......
echo:Press Any Key to goto Reload...
pause>nul
goto :clr_var
) else (
goto :E_2
)

:E_2
if !ProsID! gtr 10000 (
echo:Can not Explorer Critical Process.......
echo:Press Any Key to goto Reload...
pause>nul
goto :clr_var
) else (
goto :E_3
)

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

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

if not defined exepath (
echo:No Task Running with/ this PID..
echo:Press any key to goto reload...
PAUSE>NUL
goto :clr_var
) else (
start !explore! /select,"!exepath!.exe"
goto :clr_var
)

:clr_var
set "ProsID="
set "%%a="
set "S="
set "%%i="
set "exepath="
goto :reload

:END

_______________(it is not the actual code, the above code is just only for problem explanation)

it is working good but it have a problem, the problem is the "tokens=1 delims=." in the second for /f command under the ":E_3" (without dabble quotes) level.

If a "left side string" contains .(dot) before the ".exe" (without dabble quotes) string e.g. "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe" (without dabble quotes) then the "exepath" (without dabble quotes) variable is skipping the ".0\Acrobat\acrotray.exe" (without dabble quotes) from the "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe" (without dabble quotes) string

that means in the above case, "exepath" (without dabble quotes) variable is representing the value "C:\Program Files\Adobe\Acrobat 9" (without dabble quotes) instead of "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe" (without dabble quotes)

but i want that the "exepath" (without dabble quotes) variable to represent the full "left side string" (without dabble quotes) e.g. "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe" (without dabble quotes) not "C:\Program Files\Adobe\Acrobat 9" (without dabble quotes) or other.

What to do?

Problem 2:-
I want to open the run dialog box from batch file.

Currently i am using the following Code as a bat file :-

@echo off
start /min cmd /c explorer "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\run.lnk"

but, i do not want to use it any more, because, the "run.lnk" (without double quotes) shortcut location is changeable.

is there any explorer.exe syntax to open the "run dialog box" (without double quotes) or any other way to open the "run dialog box" (without double quotes) which I can use in batch file?

Problem 3:-
How to determine that user is giving only a numerical value instead of alphabetical value or alphanumerical value as a input of user prompt.

e.g.
set /p ans="Give a numerical value :"

as for the example, how to determine that the variable "ans" (without double quotes) is representing only a numerical value e.g. "6546778" (without double quotes) or "908757009878" (without double quotes) instead of alphabetical value e.g "khjfh fjbkhu hjbhg" (without double quotes) or alphanumerical value e.g "kjg896ghjg jt87 68tyii." (without double quotes)

and also the variable "ans" (without double quotes) should not carry any spaces.


___________________________(Sorry for my bad English, English is not my mother language)


Can any one help me?

Please help me.


See More: Make a variable of text

Report •


#1
December 19, 2010 at 04:54:15
Your English is OK but this is too long a post.

If you have a file with the three lines below, what parts do you want in variables?

C:\Windows\system32\taskhost.exe 1924
C:\Program Files\PowerISO\PWRISOVM.exe 1112
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe 2064


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
December 19, 2010 at 07:52:44
I'll try and answer problems 2 and 3. (It would have been better if you had created different posts for them, but never mind.)

2.
rundll32.exe shell32.dll,#61

3.
That's an interesting problem. You want to make sure that a variable contains only the digits 0 to 9, and nothing else. (Or maybe you allow spaces and tabs?) You can probably write a loop that checks each character, but that can be too much coding. I've tried thinking of a simple solution, and came up with this:

set /a nans=ans
if !nans! == !ans! (echo OK) else (echo Invalid input.)

However, there are caveats. No spaces allowed, and the input number must not start with a 0. Can anyone think of a better solution?


Report •

#3
December 19, 2010 at 14:47:58
Thanks a lot M2 and klint for your replies.


"If you have a file with the three lines below, what parts do you want in variables?

C:\Windows\system32\taskhost.exe 1924
C:\Program Files\PowerISO\PWRISOVM.exe 1112
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe 2064"</i>


M2,

For the first line "C:\Windows\system32\taskhost.exe"
(without double quotes)

For the second line "C:\Program Files\PowerISO\PWRISOVM.exe"
(without double quotes)

For the third line "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe"
(without double quotes)

i want in variables.

klint,
BULLS-EYE
your both suggestions are working fine,


"(Or maybe you allow spaces and tabs?)"

No, i am not allowing any spaces and tabs also.

"However, there are caveats. No spaces allowed, and the input number must not start
with a 0. Can anyone think of a better solution?"


If I use only a 0 as a input value, your code is recognizing it as a numerical value.


I think, it is possible to make the code beater through reprocessing the output of your code with one or more for /f commands to determine that if the input of your code is
starting with a 0 or contains spaces. (if i am not wrong)


Again, Thanks a lot M2 and klint for your replies.


Report •

Related Solutions

#4
December 20, 2010 at 03:24:18
My apologies:- M2, I was just missed to ask for sorry to you for my vary long post,

Sorry M2 for my vary long post.

Black_Blood


Report •

#5
December 20, 2010 at 04:03:47
This will set consecutively numbered var V1, V2, ... as long as each line contains JUST ONE instance of .exe on each line.

================================================
@echo off & setLocal EnableDELAYedeXpansion

set N=
for /f "tokens=1 delims=." %%a in (myfile) do (
set /a N+=1
set V!N!=%%a.exe
)
set V


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
December 20, 2010 at 12:17:08
Thank you M2 for your reply,


This will set 1consecutively numbered var V, V2, ... as long as each line contains JUST
ONE instance of .exe on each line.

I do not understand you clearly, but if i am not wrong you have tried to say that variable par instance of dot(.) for each line.

If so, then i have to tell you that, i don't know how much dots(.) each line contains. The number of dots(.) that each line contains is changeable also.

but if you can calculate that, how much \ are a particular line have then i can try to solve it and your previous reply for a separate post of mine may can be used there.


Your previous reply for a separate post of mine was as bellow,

@echo off > newfile & setLocal enableDELAYedeXpansion

set /p P=PID?

for /f "tokens=* delims= " %%a in ('find "!P!" ^< PIDlist') do (
set S=%%a
)

for /f "tokens=1 delims=." %%i in ("!S!") do (
echo.%%i.exe
) >> newfile


And that can be found on the bellow link

"The Link"


Thank you again for your reply M2.


Report •

#7
December 20, 2010 at 12:35:28
Post a few of your lines which have no dot or many dots.


=====================================
Life is too important to be taken seriously.

M2


Report •

#8
December 20, 2010 at 15:37:15
Thank you M2 for your reply,

each line must have to contain a single dot(.) as for the ".exe" (without dabble quotes) in every line.

Some example of those lines that contains more then one dots(.) is as bellow

C:\Program Files\Adobe\Acrobat 9.0\Acrobat\acrotray.exe
C:\Program Files\Common Files\Adobe\ARM\1.0\AdobeARM.exe
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe
C:\Program Files\Adobe\Acrobat 9.0\Acrobat\plug_ins3d\prc\A3DReviewer.exe
C:\Program Files\abcd\XXX.1.5.9\xyz.QQQQ.exm\abcd.exe
C:\Program Files\AAA.xm.hq\cz_rex\csk ev cq.rex\AAA.exe

and the example of those lines that contains only a single dot(.) is as bellow

C:\Windows\System32\audiodg.exe
C:\Program Files\BSNL 3G Data Card\BSNL 3G\BSNL 3G.exe
C:\Program Files\BSNL 3G Data Card\BSNL 3G\Resource\MCtlSuc.exe
C:\Program Files\Mozilla Firefox\firefox.exe
C:\Program Files\Common Files\Java\Java Update\jusched.exe
C:\Program Files\Acer Bio Protection\CompPtcVUI.exe


Thank you again M2 for your reply,


Report •

#9
December 20, 2010 at 16:20:45
Don't they have a PID at the end of the line[s]?


=====================================
Life is too important to be taken seriously.

M2


Report •

#10
December 21, 2010 at 05:13:15
Thank you M2, for your reply.


"Don't they have a PID at the end of the line[s]?"


yah, obviously the have.

Each line have a PID value after the ".exe" (without dabble quotes)

e.g. .exe then one or more spaces
and then the PID Value


To be clear, i want my variable to represent a partial string of a line.

The partial string for a particular line is from the beginning of a line to the .exe of the line


Thank you again for your reply M2


Report •


Ask Question