Determines whether or not the system is connected to the Internet.
BOOL InetIsOffline(
DWORD dwFlags,
);
Parameters
dwFlags
Input flags for the function. This must be set to zero.
Return Value
Returns TRUE if the local system in not currently connected to the Internet. Returns FALSE if the local system is connected to the Internet or if no attempt has yet been made to connect to the Internet.
Requirements
Version 4.00 and later of Shell32.dll
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in intshcut.h.
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _hKey As Long) As LongDeclare Function RegOpenKey Lib "advapi32.dll" Alias _"RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
String, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName _
As String, ByVal lpReserved As Long, lpType As Long, _
type
TConsoleForm = class(TForm)
Static: TStaticText;
Memo1: TMemo;
RunButton: TButton;
procedure RunButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ConsoleForm : TConsoleForm;
var currentbuf: pchar;
function ExecConsoleApp(CommandLine: String;
OutputWindow: hWnd): Int64;
implementation
const
homedir = 'c:\windows\'; {Must be set to the Netstat Directory}
commandline = '';{Any Additional Command Line Paramaters}
consoleapp = 'c:\windows\netstat.exe'; {Full Path to app}
{$R *.DFM}
function ExecConsoleApp(CommandLine: String;
OutputWindow: hWnd): Int64;
const
BufSize = $65332;
{for this simple example, the pipe should be able to
hold the entire output of the console app.
Predictably, this call hangs if CommandLine points to a
Win32 GUI app. Tested with Win32 and MS-DOS console apps}
var
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
WriteHandle, ReadHandle: THandle;
ReadBuf: array[0..BufSize] of Char;
BytesRead: Longword;
temp : Longword;
begin
FillChar(StartupInfo,SizeOf(StartupInfo), 0);
FillChar(ReadBuf, SizeOf(ReadBuf), 0);
CreatePipe(ReadHandle, WriteHandle, nil, BufSize);
with StartupInfo do
begin
cb:= SizeOf(StartupInfo);
dwFlags:= STARTF_USESHOWWINDOW or
STARTF_USESTDHANDLES;
hStdOutput:= WriteHandle;
hStdError:= WriteHandle;
wShowWindow:= SW_HIDE;
end;
if not CreateProcess(nil, PChar(CommandLine), nil, nil,
false, DETACHED_PROCESS or NORMAL_PRIORITY_CLASS,
nil, pchar(homedir), StartupInfo, ProcessInfo) then
begin
Result:= -1
end else
begin
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
{if you want to do a running update of the output of
the console app, you would not block here. Instead you
could loop while GetExitCodeProcess returned STILL_ACTIVE
all the while calling ReadFile on the pipe. Overlapped IO
would be nice, but I am not sure it would work on an
anonymous pipe. I have tried polling the pipe (works OK)
but not overlapped IO.}
procedure TConsoleForm.RunButtonClick(Sender: TObject);
var
s: String;
CAExitCode: Integer;
begin
memo1.lines.clear;
s:= consoleapp + ' '+ commandline;
Static.Caption:= 'Executing ' + s;
CAExitCode:= ExecConsoleApp(s, Static.Handle);
if CAExitCode <> 0 then
begin
if CAExitCode = -1 then
MessageDlg(Format('could not execute ''%s''', [s]),
mtError, [mbOK], 0)
else
MessageDlg(Format('%s returned exitcode of %d',
[s, CAExitCode]), mtError, [mbOK], 0)
end;