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.
zhijun_chenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RBertoraCommented:
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.
0
RBertoraCommented:
<lock>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kretzschmarCommented:
8^)
0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

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

 
0
RBertoraCommented:
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 ;-)
0
kretzschmarCommented:
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
0
zhijun_chenAuthor Commented:
thank u,
  I have tried , It doesn't work on win98.
  Any way, I will give u the points.
0
RBertoraCommented:
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 ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.