Solved

How to turn on/off  the pc speaker in W2K?

Posted on 2002-06-23
7
342 Views
Last Modified: 2010-04-04
Hi all,
This codes work fine with win98, but can't work with Win2000, How to change it? (Please don't just tell me a component, I need the source)


 if BeepOn then        //BeepOn is a logic flag
 begin
 asm
   mov al,3            //turn on the pc speaker
   out $61,al
   mov al,$0B6
   out $43,al
   mov al,200
   out $42,al
   mov al,20
   out $42,al
 end;
 end
 else
 begin
 asm
  mov al,0            //turn off the pc speaker
  out $61,al
 end;
 end;
0
Comment
Question by:xbbin
7 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7101585
hello

  I think you can't do that with win2000/xp, cuz it's not allowed you to direct access the hardware

the code which using assemply with ports, doesn't work in any version based on NT, i'm not sure with that also with the PC speaker, but i think it's the same cuz u r using assembly code to access the hardware
0
 

Author Comment

by:xbbin
ID: 7101682
Hi,
I just want to turn on/off the pc speaker, How to do that without assembly code?
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 7101693
Try this:

// Disable Enable:
procedure TForm1.Button1Click(Sender: TObject);
begin
  SystemParametersInfo(SPI_SETBEEP,0,NIL,SPIF_SENDWININICHANGE);
end;


// Enable Beep:
procedure TForm1.Button2Click(Sender: TObject);
begin
  SystemParametersInfo(SPI_SETBEEP,1,NIL,SPIF_SENDWININICHANGE);
end;
 
tas
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:xbbin
ID: 7101706
Hi Tasomia,
Not have any sound at all.
0
 
LVL 2

Accepted Solution

by:
freshman3k earned 50 total points
ID: 7101927
Hello!

1)Download the following component:
http://www.torry.net/vcl/system/portaccess/smport.zip

2)Install the component

3)Place the component on the form

4)Put the following code in the formshow event:
SmallPort->OpenDriver;

5)Put the following code in the formclose event:
SmallPort->CloseDriver;

6)Use the following code to turn the pc speaker off:
SmallPort->SpeakerOff;

7)Use the following code to enable the pc and beep the speaker with a specified tone:
SmallPort->SpeakerOn(Tone);

8)Use the following code to enable the pc and beep the speaker with a specified Freq and delay:
SmallPort->Sound(Freq,Delay);

And This will work in all versions of windows.

>Please don't just tell me a component, I need the source

There is no way to accomplish that you want in winnt/win2k/winxp with just using assembly and not using drivers.

This component is free and includes sources for the drivers and the component.  

Good Luck! :-)
0
 

Author Comment

by:xbbin
ID: 7114073
Hi freshman,
Why can't install it on Delphi3? The compiler say: SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START and SERVICE_ERROR_NORMAL are undeclared identifier.

(Should I need to declared some unit on the "use" section??)

Delphi4 not have this problem.

Regards, bin
0
 
LVL 2

Expert Comment

by:freshman3k
ID: 7114901
Hello bin,

Try Putting 'WinSvc.pas' unit in the implementation's uses
 

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now