PDA

Click to See Complete Forum and Search --> : Please Read


Chris_SE
Sep 28th, 2000, 10:09 AM
Okay I know these can be done with API, but havent found the declares in the viewer.
1. Hiding/showing a disk drive
2. diabling registry editing(w/o deleting regedit)
3. Diabling the run dialog
4. diabling a drives autorun
Anyone know any of these? Thanks in advance. ;)

shtirliz
Oct 6th, 2000, 01:09 PM
What you are trying to do I guess is set policies for the local system. To accomplish this you need to find the registry keys in
HKLM\Software\Microsoft\Windows\Current Verssion\Explorer\Policies\
Use Policy Editor Teplate files (*.pol, *.adm) available with resource kit. Open them in Notepad and find the settings you want to change - this will guide you to the key in Registry.

Here is an example of hiding a drive letter
http://support.microsoft.com/support/kb/articles/Q220/9/55.ASP

Then simply use REG API calls to change the values of this keys.

http://www.vb-world.net/registry/registry2/

hitcgar
Oct 6th, 2000, 01:36 PM
Turn off Autorun:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\
Services\Cdrom\AutoRun - set value to 0

(from MSDN)
HKEY_CURRENT_USER\Software\Microsoft\
Windows\CurrentVersion\Policies\Explorer


Under this key, is the following value:

NoDriveTypeAutoRun = 95 00 00 00


This value is a single 32-bit number. When Windows is installed, the default value is 0x00000095. Only the low bits, 0 through 7, are used. The remaining bits are reserved and should always be set to 0. Each of the low 7 bits corresponds to a possible return value from the GetDriveType function. This function returns one of the values listed in Figure 3.
A value of 0x00000095 is the same as 10010101 binary. This means that bits 0, 2, 4, and 7 are turned on. The bits that are turned on represent the drive types for which AutoPlay is disabled. In this example, AutoPlay is disabled for unknown drives, removable drives, remote drives, and some undefined types of drives. One thing to note is that on Windows NT you must log off and log on again for this AutoPlay registry change to take effect. On Windows 95, the change takes effect immediately upon changing the registry value.


Other than that shtirliz' post is right - policies.

Chris_SE
Oct 9th, 2000, 10:44 AM
Thanks, I forgot I psted this is ASP also :)

Oct 9th, 2000, 01:59 PM
To disable the Run Dialog, you can use a Timer to search for any dialog-classed window with the name of "Run" and close it if it's found.

Add the following to a Form with a Timer.

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const WM_CLOSE = &H10

Private Sub Form_Load()
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()

Dim Wnd As Long
Wnd = FindWindowEx(0, 0, "#32770", "Run")

If Wnd <> 0 Then
SendMessage Wnd, WM_CLOSE, 0, 0
DestroyWindow Wnd
End If

End Sub

Oct 9th, 2000, 02:01 PM
For saving and retrieving registry values, use the following.

Add this to a Module

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal HKEY As Long, ByVal lpValueName As String) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const REG_SZ = 1

Function RegQueryStringValue(ByVal HKEY As Long, ByVal strValueName As String)
Dim lResult As Long
Dim lValueType As Long
Dim strBuf As String
Dim lDataBufSize As Long

On Error GoTo 0
lResult = RegQueryValueEx(HKEY, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(HKEY, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
RegQueryStringValue = StripTerminator(strBuf)
End If
End If
End If
End Function

Public Function GetSettingEx(HKEY As Long, sPath As String, sValue As String)
Dim KeyHand&
Dim datatype&
Call RegOpenKey(HKEY, sPath, KeyHand&)
GetSettingEx = RegQueryStringValue(KeyHand&, sValue)
Call RegCloseKey(KeyHand&)
End Function

Function StripTerminator(ByVal strString As String) As String
Dim intZeroPos As Integer

intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function

Public Sub SaveSettingEx(HKEY As Long, sPath As String, sValue As String, sData As String)
Dim KeyHand As Long
Call RegCreateKey(HKEY, sPath, KeyHand)
Call RegSetValueEx(KeyHand&, sValue, 0, REG_SZ, ByVal sData, Len(sData))
Call RegCloseKey(KeyHand&)
End Sub


Usage:

'Save a Value to the Registry
SaveSettingEx HKEY_CURRENT_USER, "Software\Myapp", "Testing", "Hello"


'Get a value from the Registry
Retval = GetSettingEx(HKEY_CURRENT_USER, "Software\Myapp", "Testing")
Print Retval