שתף באמצעות


Disable RightClick Mouse and Disable Print Screen Key...

Question

Thursday, April 6, 2006 4:37 AM

Hi everybody,
 
   How to disable the right click of mouse? Please provide codes. How to disable
the Print Screen Key so that user cannot use it? Please provide codes. Applicable
to both windows and web applicatuions. Thanks.

 

den2005

 

All replies (9)

Thursday, May 4, 2006 9:51 AM | 1 vote

Hi Den

Please try this

********To disable Print Screen feature**********

<body onload=setInterval("window.clipboardData.setData('text','')",2) oncontextmenu="return false" onselectstart="return false">

************************************************

***********To disable right click in the web page**************

<script language=JavaScript>
function clickIE() {
if (document.all) {
return false;
}
}
function clickNS(e) {
if (document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS;
}
else{
document.onmouseup=clickNS;
document.oncontextmenu=clickIE;
}
document.oncontextmenu=new Function("return false")
</script>
************************************************

****************To Disable Text Selection***************

<script language="JavaScript1.2">

function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function ("return false")

//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>

I hope you find answers in these scripts

bye Happy coading

sagar

 


Tuesday, May 9, 2006 6:42 AM

Hi Sagar,

   Pardon me for replying just now, in your statement of disabling print screen:

<body onload=setInterval("window.clipboardData.setData('text','')",2) oncontextmenu="return false" onselectstart="return false">

This <body> is html <body> tag, right? There is no oncontextmenu and onselectstart events.

 

den2005

 


Tuesday, June 26, 2007 11:01 AM

Pointless if they want it, they will get it. Photograph the screen, take them from saved temp internet files and software programs that grabs pictures fron internet sights.


Thursday, November 8, 2007 5:14 PM

i am not in thish quesiion know i am desir inthish my anser.

 


Wednesday, September 15, 2010 3:40 PM

I am using this registry entry to disable print screen. However, I need help implementing it on GPO to computers. Currently it only works with elevated permission rights and a reboot.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,00,00,2a,e0,00,00,37,e0,\
00,00,54,00,00,00,00,00

Or this vbs script:

'Disable Print Screen Function
const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SYSTEM\ControlSet001\Control\Keyboard Layout"
strComputer = "."
BinaryValueName = "Scancode Map"
iValues = Array(&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H04,&H00,&H00,&H00,&H00,&H00,&H2a,&He0,&H00,&H00,&H37,&He0,&H00,&H00,&H54,&H00,&H00,&H00,&H00,&H00)
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "\root\default:StdRegProv")
disablePS = oReg.SetBinaryValue(HKEY_LOCAL_MACHINE,strKeyPath,BinaryValueName,iValues)

"There's a time and place for that. The time is... Never. You can figure out the place on your own".


Wednesday, September 15, 2010 11:59 PM

I am using this registry entry to disable print screen. However, I need help implementing it on GPO to computers. Currently it only works with elevated permission rights and a reboot.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,00,00,2a,e0,00,00,37,e0,\
00,00,54,00,00,00,00,00

Or this vbs script:

'Disable Print Screen Function
const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SYSTEM\ControlSet001\Control\Keyboard Layout"
strComputer = "."
BinaryValueName = "Scancode Map"
iValues = Array(&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H04,&H00,&H00,&H00,&H00,&H00,&H2a,&He0,&H00,&H00,&H37,&He0,&H00,&H00,&H54,&H00,&H00,&H00,&H00,&H00)
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "\root\default:StdRegProv")
disablePS = oReg.SetBinaryValue(HKEY_LOCAL_MACHINE,strKeyPath,BinaryValueName,iValues)

"There's a time and place for that. The time is... Never. You can figure out the place on your own".

Hello esteban2800,

Your code convertred to VB.NET is the following:

Option Strict On
Public Class Form1

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim val() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, &H4, 0, 0, 0, 0, 0, &H2A, &HE0, 0, 0, &H37, &HE0, 0, 0, &H54, 0, 0, 0, 0, 0}
  Dim regkey As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("system\currentcontrolset\control\keyboard layout", True)
  regkey.SetValue("Scancode Map", val, Microsoft.Win32.RegistryValueKind.Binary)
 End Sub

End Class 

 

Also try this code:

 

Option Strict On
Option Explicit On
Imports System.Runtime.InteropServices
Imports System.Reflection

Public Class Form1
 Private Const HC_ACTION As Integer = 0
 Private Const WH_KEYBOARD_LL As Integer = 13&

 Private Structure KBDLLHookStruct
  Public vkCode As Integer
  Public scanCode As Integer
  Public flags As Integer
  Public time As Integer
  Public dwExtraInfo As Integer
 End Structure

 <MarshalAs(UnmanagedType.FunctionPtr)> _
 Private callback As KeyboardHookDelegate
 Private mbBlockKeys As Boolean = True
 Private miKeyboardHandle As Integer = 0
 Private Delegate Function KeyboardHookDelegate(ByVal Code As Integer, _
 ByVal wParam As Integer, ByRef lParam As KBDLLHookStruct) As Integer
 Private Declare Function CallNextHookEx Lib "user32" ( _
 ByVal hHook As Integer, ByVal nCode As Integer, _
 ByVal wParam As Integer, ByVal lParam As KBDLLHookStruct) As Integer
 Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As KeyboardHookDelegate, _
 ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
 Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer

 Public Property BlockKeyCombinations() As Boolean
  Get
   Return mbBlockKeys
  End Get
  Set(ByVal value As Boolean)
   mbBlockKeys = value
  End Set
 End Property

 Public ReadOnly Property IsHooked() As Boolean
  Get
   Return miKeyboardHandle <> 0
  End Get
 End Property

 Public Function IsInIDE() As Boolean
  Return System.Diagnostics.Debugger.IsAttached
 End Function

 Public Sub HookKeyboard()
  UnhookKeyboard()
  If Not IsInIDE() Then
   callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)
   miKeyboardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, callback, _
   Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
  End If
 End Sub

 Public Sub UnhookKeyboard()
  If (IsHooked()) Then Call UnhookWindowsHookEx(miKeyboardHandle)
 End Sub

 Private Function BlockKeyCombination(ByVal Hookstruct As KBDLLHookStruct) As Boolean
  Dim bResult As Boolean = False
  If mbBlockKeys Then
   If Hookstruct.vkCode = Keys.PrintScreen Then
    bResult = True
   End If
  End If
  Return bResult
 End Function

 Private Function KeyboardCallback(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHookStruct) As Integer
  Dim lResult As Integer = 0
  If (Code = HC_ACTION) AndAlso (BlockKeyCombination(lParam)) Then
   lResult = 1
  Else
   lResult = CallNextHookEx(miKeyboardHandle, Code, wParam, lParam)
  End If
  Return lResult
 End Function

 Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
  UnhookKeyboard()
 End Sub

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  HookKeyboard()
 End Sub
End Class

 

Right after the form loads, the Print Screen button is disabled until the form closes. But to use it you need to run the *.exe file from the Debug Folder, it will not work if you just start debugging from Visual Basic.

 

Bill

HrBill32


Tuesday, August 9, 2011 5:34 PM

Sagar....

GREAT SCRIPT - works FAB!!!  Only problem I am having is that I have a form on each of my pages (www.staff2rent.com) and the visitor can't enter data.  Is there solution to fix this?  I have both of your scripts installed - see below.

 

Thanks,

Stafono

 

///////////////////////

 

<script language="JavaScript1.2">

 

function disableselect(e){

return false

}

 

function reEnable(){

return true

}

 

//if IE4+

document.onselectstart=new Function ("return false")

 

//if NS6

if (window.sidebar){

document.onmousedown=disableselect

document.onclick=reEnable

}

</script>

<script language=JavaScript>

function clickIE() {

if (document.all) {

return false;

}

}

function clickNS(e) {

if (document.layers||(document.getElementById&&!document.all)) {

if (e.which==2||e.which==3) {

return false;

}

}

}

if (document.layers) {

document.captureEvents(Event.MOUSEDOWN);

document.onmousedown=clickNS;

}

else{

document.onmouseup=clickNS;

document.oncontextmenu=clickIE;

}

document.oncontextmenu=new Function("return false")

</script>

//////////////////////////////////////////////////////////////////////////////////


Thursday, September 15, 2011 9:45 AM

Hi Sagar,

Can you please explain how the following line, which you suggested, can "disable Print Screen feature"? I tried and it doesn't work. But it does indeed prevent the user from selecting text and right-clicking to show the context menu.

********To disable Print Screen feature**********

<body onload=setInterval("window.clipboardData.setData('text','')",2) oncontextmenu="return false" onselectstart="return false">

************************************************


Thursday, September 15, 2011 11:31 AM

If you don't want to use it in a windows forms application,  than don't use an event to that in your program. There is no print screen in a windows forms application.

If you want to disable the possibility in an ASP.Net page, than you need a little piece of javascript which is available on Windows.

Be aware that disables only the possibility if that is in a HTML page.

In fact of topic for this forum.

Try for that 

http://forums.asp.net

Be aware if it is for a windows desktop to disable the right click, it can be seen as malicious code. 

See this message from Rudy to see in how far you can be held responsible if you supply code for that in a Microsoft forum.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/dd4c2e57-ba8b-476c-8f39-38bf623e64ff

Success
Cor