[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Check the registry to see if the Control Panel is Enable or Disable

Posted on 2009-12-30
8
Medium Priority
?
189 Views
Last Modified: 2012-05-08
What I want here is to check the registry to see
if the status of the Control Panel is Enable or
Disable.

If it is enable, then the code below can give me the option
to disable it and else, it can allow me to enable it.
 
Please help me out what wrong of these code. Thanks ...

' Disable Control Panel in Windows XP SP3:

' System Key: [HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer]

' Value Name: NoControlPanel

' Data Type:  REG_DWORD (DWORD Value)

' Value Data: (0 = Enable, 1 = Disable)


Option Explicit
 
Dim oShell
 
Private Function KeyExists (keyName)
  Dim bKey
                 
  On Error Resume Next
 
  bKey = oShell.RegRead(keyName)
 
  If TypeName (bKey) = "0" Then

    KeyExists = False

  Else

    KeyExists = True

  End If
End Function
 
Set oShell = CreateObject("Wscript.Shell")
 
If keyExists("HKEY_CURRENT_USER\Software\Microsoft\Windows\Current Version\Policies\Explorer") Then

  wscript.echo "The Control Panel in your Windows XP is Disable ..."

Else

Dim WSHShell, RegKey
0
Comment
Question by:cunoc
  • 5
  • 3
8 Comments
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 2000 total points
ID: 26148946
You could try something like this assuming you wanted VBScript.
Option Explicit

Dim WshShell
Dim bKey

'// QueryNoControlPanel()
'// Return 0 if (NoControlPanel) doesn't exists OR the (NoControlPanel) value is equal = (0)
'// Return 1 if (NoControlPanel) value exists and is equal = (1)

If QueryNoControlPanel = 0 Then
	
  Call DisableControlPanel

End If

Set WshShell = Nothing


'//
'// Helpers
'//

Public Function QueryNoControlPanel() 

  On Error Resume Next
  Set WshShell = WScript.CreateObject("WScript.Shell")
  bKey = WshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel")
  If bKey = 0 Then
    QueryNoControlPanel = 0
  Else
    QueryNoControlPanel = 1
  End If

End Function

Public Sub EnableControlPanel()

  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 0, "REG_DWORD"

End Sub

Public Sub DisableControlPanel()

  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 1, "REG_DWORD"

End Sub

Open in new window

0
 

Author Comment

by:cunoc
ID: 26152215
Hi all,
I worked great, but I have to go to HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel
to check whether the NoControlPanel is set as 0 or 1.

Is there a way I can see a message menu that popup when I execute this little program to tell me the Control Panel status (whether it is Disable or Enable) and given me the options to Enable or Disable or exit..

Big thanks for this and
HAPPY NEW YEAR
0
 

Author Closing Comment

by:cunoc
ID: 31671190
Hi all,
I worked great, but I have to go to HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel
to check whether the NoControlPanel is set as 0 or 1.

Is there a way I can see a message menu that popup when I execute this little program to tell me the Control Panel status (whether it is Disable or Enable) and given me the options to Enable or Disable or exit..

Big thanks for this and
HAPPY NEW YEAR
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 26152244
Thanks and Happy New Year to you!

cunoc,

The example already handles this with QueryNoControlPanel() method. When it returns zero(0) the NoControlPanel either hasn't been created or if it does exist is set to 0. If QueryNoControlPanel() returns 1 then it's set to (1).
0
 

Author Comment

by:cunoc
ID: 26152311
Hi egl1044,

This is I just modified, but I can not get to the point how to get it works as if it is disable then I can Enable it and else if it is Enable I can Disable.


Option Explicit
 if Hour(Time()) < 12 then
    MsgBox "Good Morning!"
   
end if

Dim WshShell
Dim bKey
 
'// QueryNoControlPanel()
'// Return 0 if (NoControlPanel) doesn't exists OR the (NoControlPanel) value is equal = (0)
'// Return 1 if (NoControlPanel) value exists and is equal = (1)
 
If QueryNoControlPanel = 0 Then
  ::MsgBox "The Control Panel in your system is currently Disable ..."
   
  WScript.Echo "The Control Panel in your system is currently Disable ..."
  Call DisableControlPanel

else
  MsgBox "The Control Panel in your system is currently Enable ..."
  ::WScript.Echo "The Control Panel in your system is currently Enable ..."
End If
 
Set WshShell = Nothing
 
 
'//
'// Helpers
'//
 
Public Function QueryNoControlPanel()  
 
  On Error Resume Next
  Set WshShell = WScript.CreateObject("WScript.Shell")
  bKey = WshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel")
  If bKey = 0 Then
    QueryNoControlPanel = 0
  Else
    QueryNoControlPanel = 1
  End If
 
End Function
 
Public Sub EnableControlPanel()
 
  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 0, "REG_DWORD"
 
End Sub
 
Public Sub DisableControlPanel()
 
  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 1, "REG_DWORD"
 
End Sub
0
 

Author Comment

by:cunoc
ID: 26152318
For example, when I run the code, it would give me the option like below:

Your Control Panel is now Disable.
1. Do you want to Enable it..
2. Exit

Your Control Panel is now Enable.
1. Do you want to Disable it..
2. Exit
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 26153815
Okay. That makes much more sense cunoc use the following for a replacment.
Option Explicit 
 
Dim WshShell 
Dim bKey 
Dim Result
Dim mb

'// query value
Result = QueryNoControlPanel

Select Case Result

  Case 0 '

    mb = MsgBox("The control panel is enabled would like to disable it now?", VbYesNo,"Option")
	
      If mb = VbYes Then
        '//disable
	Call DisableControlPanel
      End If

  Case 1 '

    mb = MsgBox("The control panel is disabled do you want to enable it now?", VbYesNo,"Option")
	  
    If mb = VbYes Then
      '//enable
	Call EnableControlPanel
    End If

End Select


Set WshShell = Nothing 
 
 
'// 
'// Helpers 
'// 
 
Public Function QueryNoControlPanel()  
 
  On Error Resume Next 
  Set WshShell = WScript.CreateObject("WScript.Shell") 
  bKey = WshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel") 
  QueryNoControlPanel = bkey
 
End Function 
 
Public Sub EnableControlPanel() 
 
  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 0, "REG_DWORD" 
 
End Sub 
 
Public Sub DisableControlPanel() 
 
  WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoControlPanel", 1, "REG_DWORD" 
 
End Sub

Open in new window

0
 

Author Comment

by:cunoc
ID: 26153892
Hi egl1044:

Thanks for quick response. It works great and it is the way I wanted.

HAPPY NEW YEAR.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 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