Reinventing the wheel
April 24, 2024, 08:56:34 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Members Tags Login Register  
Pages: 1 ... 3 4 [5] 6 7 ... 10
 41 
 on: May 16, 2009, 05:35:53 AM 
Started by bushtor - Last post by rionroc
Ops!

Sorry for my answer, I thought your asking for any of as.


Anyway! Good luck!

Cheers!

 42 
 on: May 15, 2009, 10:46:51 PM 
Started by bushtor - Last post by rionroc
I understand that this is the one you are basing.
http://www.yeahware.com/download/enable.zip

>>With the code from the link above I assume that it might be possible to modify it with other parameters to also get a list of dialup connections. Is this true or will dialup enumeration require a totally different approach?
for me, NO!, you could select and disable the device of dialup, such as the modem device. (but you must know first the name of the modem device)


>>Would it be possible to limit the query seeking for specific types of adapters, like wireless and bluetooth one and ignore loopback adapters and 1394 oners by changing parameters in the code above..?   YES


>>Would it also be possible to check if a network cable is plugged in or not with this code...?   is NOT with that code or link.

 43 
 on: May 15, 2009, 09:50:13 PM 
Started by rionroc - Last post by rionroc
Thank you Sir

Actually the code runs fine,  InfoTip can get the path and filename.

function TInfoTip.Load(pszFileName: POleStr; dwMode: Integer): HResult;
begin
WideCharToStrVar(pszFileName, fName);
Result := S_OK;
end;

function TInfoTip.GetInfoTip(dwFlags: DWORD; var ppwszTip: PWideChar): HResult;
begin
ppwszTip := StringToOleStr('The infotip3 for: ' + #13 + fName);
Result := S_OK;
end;

//fName RETURNS the path and the filename.

For my question1:
What I'm asking for the infoTip display [if mousedown] was press and not the mouseover, that if is possible.   But if that is impossible,   how about displaying the infoTip on a Delphi form.
------------------------------------------------------------------------------
//end question1



//begin question2
------------------------------------------------------------------------------
>>does not contain the path, only the filename?
That is about my other post that I deleted(the question2), and I hope you have the copy.   The function selectedfilename only gets the filename anywhere inside desktop windows explorer,  but does not include the path.

This is the output of the project I made:
http://www.mediafire.com/?nufzry0o4nj

Please see it Sir,  to understand this issue
Sorry for the mix questions.

 44 
 on: May 15, 2009, 06:20:22 PM 
Started by rionroc - Last post by ciuly
lets continue our PM conversation here:

so what you say is that in
function TInfoTip.Load(pszFileName: POleStr; dwMode: Integer): HResult;
the parameter pszFileName does not contain the path, only the filename?

also you have a bug. in
function TInfoTip.GetCurFile(out pszFileName: POleStr): HResult; export;
you need to change the parameters amongs them. it must be
WideCharToStrVar(finfo, pszFileName);

 45 
 on: May 15, 2009, 06:15:48 PM 
Started by rionroc - Last post by ciuly
First of all, I don't particularly like the "zombie" attribute.
Second, the idea of this forum from the begining was for user feedback on various topics and for me to be able to publish information fast (currently, the rest of the site is rather static html). There are already quite a few delphi related sites and some delphi-dedicated sites, so there really isn't the need to make yet another one.
And last, there will be changes to the structure of the site, but not in the following few months since I really need to make money, before investing time in something that only consumes money Wink
Basically, changes to the structure of the site are ratehr low on the list of me priorities

thanks for your input though.

 46 
 on: May 15, 2009, 03:47:07 PM 
Started by rionroc - Last post by rionroc
I suggest to turn this forum into a main page of cuily.com, and any subject regarding to main page ciuly.com shall be transfered to this forum.

So this forum site will be the main page of ciuly.com as a Delphi Zombie website.

What do you think, Sir Ciuly?
What about the other zombies say?

Well its just a suggestion, but its a good start.

   CIULY.COM
Zombie Website

 47 
 on: May 15, 2009, 01:33:02 PM 
Started by bushtor - Last post by bushtor
Thanks rionroc, will look at the code.

Ciuly,
Sorry about the subject name.  I mean:

http://www.ciuly.com/delphi/wmi/networkAdapterStatus/index.html

The example form's caption name use 'Enable/disable ...' so that's where I saw it.

Anyhow, I'm trying to put together an application to be run on students' computers during tests and exams.  In many subjeccts they are allowed to use their own computers with any resource saved to their disks, however they are not allowed to communicate by any means.

Hence I wanted to display a small always-stay-on-top window on their screen listing all their network adapters and dialup connections colored according to their activated state.  Then it's easy for the exam staff to visually verify that all network adapters are deactivated.  

Obviously wireless network, bluetooth and dialup (3G mobile cards) are most interesting.  Loopback, 1394 and  wired adapters could mostly be ignored in this situation due to their nature.

Since I've come to the gurus :-) I'd like to ask some questions, and I'd be happy to receive comments.

With the code from the link above I assume that it might be possible to modify it with other parameters to also get a list of dialup connections.  Is this true or will dialup enumeration require a totally different approach?

Would it be possible to limit the query seeking for specific types of adapters, like wireless and bluetooth one and ignore loopback adapters and 1394 oners by changing parameters in the code above..?

Would it also be possible to check if a network cable is plugged in or not with this code...?

Sorry for bugging you, but thanks for any comments on the above topics :-)

best regards

Tor

 48 
 on: May 15, 2009, 01:05:49 PM 
Started by ciuly - Last post by rionroc
I've read it all, but kind of hard to understand the problem,  I'll be more technomous after this. (^_^)

 49 
 on: May 15, 2009, 12:26:52 PM 
Started by rionroc - Last post by rionroc
Delphi zombie as we are called, zombies live forever and so we are.

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

Go and tell your friends about a zombie website.


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


rionroc
Delphi zombie


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


Cheers!

 50 
 on: May 15, 2009, 12:15:50 PM 
Started by bushtor - Last post by rionroc
Here is some code that should help get you started along. It is able to detect network changes, enumerate the adapter/interface pairs, and also allows you to disable/re-enable any specific interface. I am posting the sample app code first, then the component code. The component code requires the ip helper conversion units from jedi (the link is displayed in the component.).

If you have questions, please do not ask me,  ask Sir Ciuly, because he knows better than me.


Sample app code (form with 2 buttons and 1 memo on it)

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, NetState, IpRtrMib;

type
  TForm1 = class(TForm)
    Button1: TButton;
    NetAdapter1: TNetAdapter;
    Memo1: TMemo;
    Button2: TButton;
    procedure NetAdapter1Connect(Sender: TObject; IntfAdapter: _MIB_IFROW);
    procedure NetAdapter1Disconnect(Sender: TObject; IntfAdapter: _MIB_IFROW);
    procedure NetAdapter1StateChange(Sender: TObject; IntfAdapter: _MIB_IFROW; LastState, LastAdminState: Cardinal);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

procedure UpdateInfo(Memo: TMemo; Row: _MIB_IFROW);
begin
  with Memo do
  begin
     Lines.Add(Format('  Name: %s', [InterfaceName(Row)]));
     Lines.Add(Format('  Operational State: %d', [Row.dwOperStatus]));
     Lines.Add(Format('  Admin State: %d', [Row.dwAdminStatus]));
  end;
end;

procedure TForm1.NetAdapter1Connect(Sender: TObject; IntfAdapter: _MIB_IFROW);
begin
  Memo1.Lines.Add(Format('%s connected', [InterfaceName(IntfAdapter)]));
  UpdateInfo(Memo1, IntfAdapter);
end;

procedure TForm1.NetAdapter1Disconnect(Sender: TObject; IntfAdapter: _MIB_IFROW);
begin
  Memo1.Lines.Add(Format('%s disconnected', [InterfaceName(IntfAdapter)]));
  UpdateInfo(Memo1, IntfAdapter);
end;

procedure TForm1.NetAdapter1StateChange(Sender: TObject; IntfAdapter: _MIB_IFROW; LastState, LastAdminState: Cardinal);
begin
  Memo1.Lines.Add(Format('%s state change', [InterfaceName(IntfAdapter)]));
  UpdateInfo(Memo1, IntfAdapter);
  if InterfaceIsConnected(IntfAdapter) then
     Memo1.Lines.Add('-- Connected -- ')
  else
     Memo1.Lines.Add('-- Disconnected -- ');
end;

procedure TForm1.Button1Click(Sender: TObject);
var  dwIndex:       Integer;
begin
  for dwIndex:=0 to Pred(NetAdapter1.IntfAdapterCount) do
     NetAdapter1.DisableIntfAdapter(NetAdapter1[dwIndex]);
end;

procedure TForm1.Button2Click(Sender: TObject);
var  dwIndex:       Integer;
begin
  for dwIndex:=0 to Pred(NetAdapter1.IntfAdapterCount) do
     NetAdapter1.EnableIntfAdapter(NetAdapter1[dwIndex]);
end;


------------------- Component Code --------------------

unit NetState;
// http://ftp://delphi-jedi.org/api/IPHlpAPI.zip
interface

////////////////////////////////////////////////////////////////////////////////
//   Include Units (IP Helper units: http://ftp://delphi-jedi.org/api/IPHlpAPI.zip)
////////////////////////////////////////////////////////////////////////////////
uses
  Windows,
  SysUtils,
  Messages,
  Classes,
  Graphics,
  Controls,
  ExtCtrls,
  Forms,
  Dialogs,
  WinSock,
  WinInet,
  IpExport,
  IpHlpApi,
  IpTypes,
  IpIfConst,
  IpRtrMib;

////////////////////////////////////////////////////////////////////////////////
//   Network adapter constants
////////////////////////////////////////////////////////////////////////////////
const
  SPEED_MODEM          =  9600;

////////////////////////////////////////////////////////////////////////////////
//   Network adapter component
////////////////////////////////////////////////////////////////////////////////
type
  // Event handler type declarations
  TOnConnect           =  procedure(Sender: TObject; IntfAdapter: TMibIfRow) of object;
  TOnDisconnect        =  procedure(Sender: TObject; IntfAdapter: TMibIfRow) of object;
  TOnStateChange       =  procedure(Sender: TObject; IntfAdapter: TMibIfRow; LastState, LastAdminState: DWORD) of object;
  // Component declaration
  TNetAdapter          =  class(TComponent)
  private
     // Private declarations
     FTimer:           TTimer;
     FTable:           PMibIfTable;
     FOnConnect:       TOnConnect;
     FOnDisconnect:    TOnDisconnect;
     FOnStateChange:   TOnStateChange;
  protected
     // Protected declarations
     function          GetInterval: Integer;
     function          GetWatch: Boolean;
     function          GetIntfAdapters(Index: Integer): TMibIfRow;
     function          GetIntfAdapterCount: Integer;
     procedure         GetIntfAdapterTable;
     procedure         OnWatchFired(Sender: TObject);
     procedure         SetInterval(Value: Integer);
     procedure         SetWatch(Value: Boolean);
  public
     // Public declarations
     constructor       Create(AOwner: TComponent); override;
     destructor        Destroy; override;
     procedure         DisableIntfAdapter(Row: TMibIfRow);
     procedure         EnableIntfAdapter(Row: TMibIfRow);
     property          IntfAdapterCount: Integer read GetIntfAdapterCount;
     property          IntfAdapters[Index: Integer]: TMibIfRow read GetIntfAdapters; default;
  published
     // Published declarations
     property          OnConnect: TOnConnect read FOnConnect write FOnConnect;
     property          OnDisconnect: TOnDisconnect read FOnDisconnect write FOnDisconnect;
     property          OnStateChange: TOnStateChange read FOnStateChange write FOnStateChange;
     property          WatchChanges: Boolean read GetWatch write SetWatch;
     property          WatchInterval: Integer read GetInterval write SetInterval;
  end;

////////////////////////////////////////////////////////////////////////////////
//   Utility functions for handling of the interface row information
////////////////////////////////////////////////////////////////////////////////
function   InterfaceName(IntfAdapter: TMibIfRow): PChar;
function   InterfaceIsConnected(IntfAdapter: TMibIfRow): Boolean;
function   InterfaceIsModem(IntfAdapter: TMibIfRow): Boolean;

procedure Register;

implementation

function InterfaceName(IntfAdapter: TMibIfRow): PChar;
begin
  result:=PChar(@IntfAdapter.bDescr);
end;

function InterfaceIsConnected(IntfAdapter: TMibIfRow): Boolean;
begin
  result:=(IntfAdapter.dwAdminStatus = MIB_IF_ADMIN_STATUS_UP) and (IntfAdapter.dwOperStatus >= MIB_IF_OPER_STATUS_CONNECTED);
end;

function InterfaceIsModem(IntfAdapter: TMibIfRow): Boolean;
begin
  result:=((IntfAdapter.dwType = MIB_IF_TYPE_ETHERNET) and (IntfAdapter.dwSpeed = SPEED_MODEM)) or (IntfAdapter.dwType = MIB_IF_TYPE_PPP);
end;

// TNetAdapter
procedure TNetAdapter.DisableIntfAdapter(Row: TMibIfRow);
begin

  // Set admin status for row and call SetIfEntry
  Row.dwAdminStatus:=MIB_IF_ADMIN_STATUS_DOWN;

  // Set entry
  SetIfEntry(Row);

end;

procedure TNetAdapter.EnableIntfAdapter(Row: TMibIfRow);
begin

  // Set admin status for row and call SetIfEntry
  Row.dwAdminStatus:=MIB_IF_ADMIN_STATUS_UP;

  // Set entry
  SetIfEntry(Row);

end;

function TNetAdapter.GetInterval: Integer;
begin

  // Return the interval for the timer control
  result:=FTimer.Interval;

end;

function TNetAdapter.GetWatch: Boolean;
begin

  // Return the timer control enabled state
  result:=FTimer.Enabled;

end;

procedure TNetAdapter.SetInterval(Value: Integer);
begin

  // Update the timer control interval
  FTimer.Interval:=Value;

end;

procedure TNetAdapter.SetWatch(Value: Boolean);
begin

  // Update the timer control enabled state
  FTimer.Enabled:=Value;

end;

function TNetAdapter.GetIntfAdapters(Index: Integer): TMibIfRow;
begin

  // Check the table to make sure the request is in range
  if (FTable = nil) or (Index < 0) or (DWORD(Index) >= FTable^.dwNumEntries) then raise Exception.Create('Invalid Index');

  // Return the row
  result:=FTable^.Table[Index];

end;

function TNetAdapter.GetIntfAdapterCount: Integer;
begin

  // Check table
  if Assigned(FTable) then
     // Return the current count of interface/adapters
     result:=FTable^.dwNumEntries
  else
     // No table
     result:=0;

end;

procedure TNetAdapter.GetIntfAdapterTable;
var  lpIntfTable:   PMibIfTable;
     lpSwap:        Pointer;
     dwIndex:       ULONG;
     dwOldIndex:    ULONG;
     dwSize:        ULONG;
     bChanged:      Boolean;
     bExists:       Boolean;
begin

  // Set the default table
  lpIntfTable:=nil;

  // Make the call to get the required size
  try
     // Set the default size to allocate
     dwSize:=0;
     // Make the call to get the table size
     if (GetIfTable(nil, dwSize, True) = ERROR_INSUFFICIENT_BUFFER) then
     begin
        // Allocate memory for the table
        lpIntfTable:=AllocMem(dwSize);
        // Make the call again
        if (GetIfTable(lpIntfTable, dwSize, True) = NO_ERROR) then
        begin
           // We now have the table. If the old table is nil, then this is the
           // first call and there is nothing to compare to, so just assign the
           // table over.
           if (FTable = nil) then
           begin
              // Assign and clear var so the memory is not freed
              FTable:=lpIntfTable;
              lpIntfTable:=nil;
           end
           else
           begin
              // Swap table pointers
              lpSwap:=FTable;
              FTable:=lpIntfTable;
              lpIntfTable:=lpSwap;
              // Check for connects first and changes first
              for dwIndex:=0 to Pred(FTable^.dwNumEntries) do
              begin
                 // Check to see if this is a new entry
                 bExists:=False;
                 bChanged:=False;
                 dwOldIndex:=0;
                 while (dwOldIndex < lpIntfTable^.dwNumEntries) do
                 begin
                    // Check index
                    if (FTable^.table[dwIndex].dwIndex = lpIntfTable^.table[dwOldIndex].dwIndex) then
                    begin
                       // Entry exists
                       bExists:=True;
                       // Has it changed?
                       bChanged:=not((FTable^.table[dwIndex].dwAdminStatus = lpIntfTable^.table[dwOldIndex].dwAdminStatus) and
                                 (FTable^.table[dwIndex].dwOperStatus = lpIntfTable^.table[dwOldIndex].dwOperStatus));
                       // Done either way
                       break;
                    end;
                    // Next index
                    Inc(dwOldIndex);
                 end;
                 // Does the entry exist? If not, then we will need to fire a connect change
                 if bExists then
                 begin
                    // Check for change
                    if bChanged and Assigned(FOnStateChange) then
                       FOnStateChange(Self, FTable^.table[dwIndex], lpIntfTable^.table[dwOldIndex].dwOperStatus, lpIntfTable^.table[dwOldIndex].dwAdminStatus);
                 end
                 else if Assigned(FOnConnect) then
                    // Fire the OnConnect event
                    FOnConnect(Self, FTable^.table[dwIndex]);
              end;
              // Now we need to check for disconnects (those in old table but not in new)
              for dwOldIndex:=0 to Pred(lpIntfTable^.dwNumEntries) do
              begin
                 // Check to see if this entry still exists
                 bExists:=False;
                 dwIndex:=0;
                 while (dwIndex < FTable^.dwNumEntries) do
                 begin
                    // Check index
                    if (FTable^.table[dwIndex].dwIndex = lpIntfTable^.table[dwOldIndex].dwIndex) then
                    begin
                       // Entry exists
                       bExists:=True;
                       // Done either way
                       break;
                    end;
                    // Next index
                    Inc(dwIndex);
                 end;
                 // Does the entry exist? If not, then we will need to fire a disconnect event
                 if not(bExists) and Assigned(FOnDisconnect) then FOnDisconnect(Self, lpIntfTable^.table[dwOldIndex]);
              end;
           end;
        end;
     end;
  finally
     // Free the table memory
     if Assigned(lpIntfTable) then FreeMem(lpIntfTable);
  end;

end;

procedure TNetAdapter.OnWatchFired(Sender: TObject);
begin

  // Resource protection
  try
     // Disable the timer
     FTimer.Enabled:=False;
     // Update the network interface table
     GetIntfAdapterTable;
  finally
     // Re-enable the timer
     FTimer.Enabled:=True;
  end;

end;

constructor TNetAdapter.Create(AOwner: TComponent);
begin

  // Perform inherited
  inherited Create(AOwner);

  // Starting defaults
  FTimer:=TTimer.Create(Self);
  FTimer.Interval:=1000;
  FTimer.Enabled:=False;
  FTimer.OnTimer:=OnWatchFired;
  FTable:=nil;

  // Load the initial table
  GetIntfAdapterTable;

end;

destructor TNetAdapter.Destroy;
begin

  // Stop and free the timer
  FTimer.Enabled:=False;
  FTimer.Free;

  // Free memory allocated for the table
  if Assigned(FTable) then FreeMem(FTable);

  // Perform inherited
  inherited Destroy;

end;

procedure Register;
begin

  // Register the component with the IDE
  RegisterComponents('Additional', [TNetAdapter]);

end;

end.


Got it from other sites. (^_^)
And a sample code in zip format that may help you analyze:
http://www.yeahware.com/download/enable.zip


rionroc
Delphi zombie, because delphi is always alive.

Pages: 1 ... 3 4 [5] 6 7 ... 10
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC | Sitemap Valid XHTML 1.0! Valid CSS!
Page created in 0.047 seconds with 19 queries.