Link to home
Start Free TrialLog in
Avatar of zhijun_chen
zhijun_chen

asked on

How can I disable the network card in delphi?

hello,
  I want to disable the network card in delphi just as device manager do,how can I do it?
  Hope for your answer.
Avatar of RBertora
RBertora
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi when you say device manager I assume you mean control panel -> devices... and I assumed you use NT (big assumption) any way to disable your network card you can stop the device service : here is the code I wrote to disable my network card:

Rob ;-)


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  Name : Pointer;
  NameSize : DWord;
  DeviceServiceHandle : THandle;
  DeviceServiceSatus :TServiceStatus;

begin
  NameSize := 100;
  Name := allocmem(NameSize);

// a quick showmessage to see if you can find the service:
// If the showmessage is empty then you have not typed in a valid service name!
   GetServiceKeyName(
      OpenSCManager('PC-199',Nil,GENERIC_READ      ),
      '3Com Etherlink III Adapter Driver',
      Name,
      NameSize);
    showmessage(String(Name));


// get the service handle:
    (*
SC_HANDLE OpenService(

    SC_HANDLE hSCManager,      // handle to service control manager database
    LPCTSTR lpServiceName,      // pointer to name of service to start
    DWORD dwDesiredAccess       // type of access to service
   );
*)
    DeviceServiceHandle :=  OpenService(
                              OpenSCManager('PC-199',Nil,GENERIC_READ      ),
                             '3Com Etherlink III Adapter Driver',
                              SERVICE_STOP);
// stop the service
    ControlService(DeviceServiceHandle,
                   SERVICE_CONTROL_STOP,DeviceServiceSatus);

(*
BOOL ControlService(

    SC_HANDLE hService,      // handle to service
    DWORD dwControl,      // control code
    LPSERVICE_STATUS lpServiceStatus       // pointer to service status structure
   );

*)


end;

end.
ASKER CERTIFIED SOLUTION
Avatar of RBertora
RBertora
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zhijun_chen
zhijun_chen

ASKER

Thank u,RBertora
  I am working on windows98,not NT,can u give a clue?

 
That might work on win98, run a search on your hard drive for file: win32.hlp
if its there then there is a chance it will work.

Meikl any ideas?
Rob ;-)
hi rob,

>Meikl any ideas?
I? no, I'm not very familar with set hardwareoptions by code, therefore i just look, to learn this. and in this case i've learned something from you ;-)
but i will examine the win-api, maybe i find a starting-point.

meikl
thank u,
  I have tried , It doesn't work on win98.
  Any way, I will give u the points.
That would be very kind of you, but I feel bad taking 200 points off your account. So I suggest you don't do it.
But I wouldn't feel so bad taking 50pts if you don't mind Delete this question. Post another one for 50 I will cut&paste my suggestion in aagain...

your call.
Rob ;-)