Hi. I am new to the site and not too clever at Pascal (beginner).
I need to be able to get an IP address, then compare it with one I want to use then if the address is the same run a program if not quit.
This is to get Laptops to run a backup program only on LAN and NOT when using VPN.
I thought something along the lines of
Get IP <coding ???)
If IP = <ip address> then
run program
else
Quit.
Obviously not that easy so can anyone help me please.

Recommended Answers

All 7 Replies

*******UPDATE**********

I have done most of the program but can't get the last bit to work now.
Can anyone tell me how I can get pascal to run an external Program
called from a shortcut (the program has to have a path added to it's startup Target box else it won't run) thus the shortcut.
Anyone please.

There are plenty of utilities that can do this. There's a new one I'm about to try, myself, called "Ping Range." Just go to download.com and look up "ping ip range" and it'll actually show you quite a few different tools.

commented: I agree with Salem +0

*******UPDATE**********

I have done most of the program but can't get the last bit to work now.
Can anyone tell me how I can get pascal to run an external Program
called from a shortcut (the program has to have a path added to it's startup Target box else it won't run) thus the shortcut.
Anyone please.

I can't use external programs as they ask user for input. the whole thing needs to run without user input.
I have tried one calling the other but always get the "too many parameters specified error". Begining to get cheesed off with Pascal especially as I am not a programmer by vocation.
Can anyone get my program to work as is.
thanks.

If i'm not mistaken one of the parameters to ShellExecute() is the startup path of the process. If this is the only reason for having a shortcut could you not just set the Startup Path with ShellExecute()? I'm not trying to argue or convince you to use another way... I can't find any documentation on executing a shortcut.

Unless you are talking about parameters to the application..?

If i'm not mistaken one of the parameters to ShellExecute() is the startup path of the process. If this is the only reason for having a shortcut could you not just set the Startup Path with ShellExecute()? I'm not trying to argue or convince you to use another way... I can't find any documentation on executing a shortcut.

Unless you are talking about parameters to the application..?

Thanks for the reply.
The shortcut needs to be given a path so the program knows what to backup. ie: C:\solautolapbak.exe "D:\My Documents"
I have tried the following command
Exec (shell, 'C:\solautolapbak.exe');
and
Exec (shell, 'C:\solautolapbak.exe 'D:\My Documents' ');

neither work. the first because it states no path was listed
the second just drops into the directory the file is in at a dos prompt and does nothing. The program HAS to have the path at the end and run from a shortcut with this listed.
we can't put the path in the main program as sometimes this changes due to the PC's build (may not have D: or may be My Docs etc).
Sorry for the headache on this, I feel like I'm banging my head against a wall too :-) this is the only part I can't get working.
thanks.

Here's a sample from a code I use for opening and executing other programs from within dephi. This executes a file and gives it a 2nd file as a parameter.

params

procedure execute_file(file_to_execute:string;file_to_transfer:string);
var
str_to_execute:string;
begin
 if fileexists( file_to_execute )=false then exit;
 if fileexists( file_to_transfer )=false then exit;
 str_to_execute:=ExtractShortPathName(file_to_execute)+' ';
 str_to_execute:=str_to_execute+ExtractShortPathName(file_to_transfer);
 WinExec(pchar(str_to_execute),SW_SHOWDEFAULT);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 execute_file('c:\runme.bat','c:\dummy.txt');
end;

Filenames with spaces in them can be problematic, that's why I use ExtractShortPathName. Be warned that it doesn't work it the file doesn't exists ( for example it's a target file that the program is supposed to write).

Here's a sample from a code I use for opening and executing other programs from within dephi. This executes a file and gives it a 2nd file as a parameter.

params

procedure execute_file(file_to_execute:string;file_to_transfer:string);
var
str_to_execute:string;
begin
 if fileexists( file_to_execute )=false then exit;
 if fileexists( file_to_transfer )=false then exit;
 str_to_execute:=ExtractShortPathName(file_to_execute)+' ';
 str_to_execute:=str_to_execute+ExtractShortPathName(file_to_transfer);
 WinExec(pchar(str_to_execute),SW_SHOWDEFAULT);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 execute_file('c:\runme.bat','c:\dummy.txt');
end;

Filenames with spaces in them can be problematic, that's why I use ExtractShortPathName. Be warned that it doesn't work it the file doesn't exists ( for example it's a target file that the program is supposed to write).

Looks like I may have it working. works on my machine but it needs testing for a few days on a laptop just to be sure before deploying.

Thanks for all those that replied.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.