Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all,

I'm very new at this and really don't know much so any help would be greatly appreciated.

What I would like to do :

. retrieve an IP from a file using user input
. launch UltraVNC with that IP to simplify connections

What I have :

. the file is a semicolon separated .txt file with the following data :

. Client name; : its the number of the client, always five numbers
. Subnet mask; : two possible, either ending with 224 or 192
. LAN IP Address : self explanatory

. I got here :

@echo off

mode con: lines=2 cols=40

title Direct connect

:start

color 0A

cls

set var=

set /p var= Enter name:

???? "C:\Users\XXX\XXXX\XXXX" XXXX.txt
????
IF 224 add 17 to IP
IF 192 add 38 to IP
????
OUTPUT
????
start "C:\Program Files\UltraVNC" vncviewer.exe -connect -4greycolors host OUTPUT -Password xxxxxxxxx

. So, that's not much. I would like from the input search the file (that would be 'Client name'), if the mask ends with 224 to add 17 to the IP, 38 if 192 and then direct that IP to the VNC connection.

There it is, if what I ask is possible I hope that someone will have the kindness and patience to explain how to do this and finally evolve.

___________________________________________________________________________________
Hello Sergey,

Thank you so very much for your help!

I got here :

Set Var=
SET /P var= name:
FINDSTR %var% C:\IP_LAN.txt
pause

And in fact I have the output desired :

10001;225.225.225.192;192.192.192.1

Where :

Name : 10001
Sub net mask :225.225.225.192
IP LAN : 192.192.192.1

Now again I'm stomped and I would like to retieve this info and turn it into variables to then use the IF THEN command and pipe it to a connection program as the IP to connect to. I've found some info on the FOR /F command but I don't understand it completely.

Your help would be greatly appreciated.
Posted
Updated 24-May-15 20:24pm
v3
Comments
Sergey Alexandrovich Kryukov 21-May-15 9:48am    
Bad idea. Such things are awkward in batch files and are very inconvenient to the users. It's much better to put all input in a command line. In batch, the command-line parameters are %1, %2, etc.
—SA

1 solution

What you need is done using the SET command:
SET /P variable=[promptString]


But please see my comment to the question: it could be much better to use all input in command-line parameters.

For more help on batch, do the following:

Visit this site loop what it suggests for you: http://www.robvanderwoude.com[^].

In particular, look at this page: http://www.robvanderwoude.com/allhelp.php[^].

If gives you the utility to generate complete batch help from your system. Use it to generate help and read it; you will find more detailed information on how to use each batch construct or command. It may surprise you: in newer systems, there are functions and calls (in contrast to go to, with return) and a lot more.

—SA
 
Share this answer
 
v2
Comments
DarthVagrant 25-May-15 4:12am    
Hello Sergey,

Thank you so very much for your help!

I got here :

Set Var=
SET /P var= name:
FINDSTR %var% C:\IP_LAN.txt
pause

And in fact I have the output desired :

10001;225.225.225.192;192.192.192.1

Where :

Name : 10001
Sub net mask :225.225.225.192
IP LAN : 192.192.192.1

Now again I'm stomped and I would like to retieve this info and turn it into variables to then use the IF THEN command and pipe it to a connection program as the IP to connect to. I've found some info on the FOR /F command but I don't understand it completely.

Your help would be greatly appreciated.
Sergey Alexandrovich Kryukov 25-May-15 9:48am    
Ask the user 3 questions:

set /P name= Name:
set /P mask= Mask:
set /P ip= IP Address:

Then your output will can be obtained as
set oneLine=%name%;%mask%;%ip%

...

But better don't waste time on all that. Make the user supply all the data in one command line. This is more convenient for the user, because the user can always repeat wrong line. Parse command line and use it to get data. Or combine it with interactive questions to the user if not all data is supplied. Repeat the question until the user gives satisfactory answer, and so on.

Also, think if you are not wasting time on batch language. It's good to use it, but not if you make it hard (no debugging, no nothing). For example, interactive data input takes GUI. And so on...

Now, I answered your question in full. Will you accept it formally?

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900