Page 1 of 1
Posted: Fri Dec 07, 2001 3:52 am
by BackupUser
Restored from previous forum. Originally posted by Shawn.
Hi.
I am new to PB.
Although it seems simple, does anyone see anything wrong with this code? The registry key does not open.
This example should disable downloads in Internet Explorer. I am using W2K.
Thanks.
Shawn
Code: Select all
If OpenRegKey(#HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3")
MessageRequester("Status","Registry key opened successfully", 0)
WriteRegNumeric("1803",3)
Else
MessageRequester("Status","Registry key failed to open", 0)
EndIf
CloseRegKey()
Posted: Fri Dec 07, 2001 5:05 am
by BackupUser
Restored from previous forum. Originally posted by PB.
The registry key does not open.
The Registry library is apparently broken at the moment...
Mr Skunk, its author, said in another thread in the bug report forum: "It
works with PB 2.40 and lower but not since 2.50. I don't know why as Fred
tells me he had not changed anything."
He goes on to say that a rewrite of the library was due to start at the end
of November, so we'll have to be patient for a little bit, or use the Registry
API calls (if only I knew how!).
PB - Registered PureBasic Coder
Edited by - PB on 07 December 2001 05:06:42
Posted: Fri Dec 07, 2001 6:18 am
by BackupUser
Restored from previous forum. Originally posted by Shawn.
The registry key does not open.
The Registry library is apparently broken at the moment...
Mr Skunk, its author, said in another thread in the bug report forum: "It
works with PB 2.40 and lower but not since 2.50. I don't know why as Fred
tells me he had not changed anything."
He goes on to say that a rewrite of the library was due to start at the end
of November, so we'll have to be patient for a little bit, or use the Registry
API calls (if only I knew how!).
PB - Registered PureBasic Coder
Edited by - PB on 07 December 2001 05:06:42
Mr Skunk looks to be a busy guy. I appreciate the libraries. It really makes things easier. I guess I should learn the Windows API though too...
This one is not urgent as I have already done it with WSH. Just practicing to learn.
Thanks,
Shawn
Posted: Fri Dec 07, 2001 7:33 am
by BackupUser
Restored from previous forum. Originally posted by Paul.
I think there is a bug in PB because you are also unable to use Windows API to access the Registry in versions 2.50 and higher.
I'm still waiting for someone to look into this and find a solution.
Posted: Sat Dec 08, 2001 2:19 am
by BackupUser
Restored from previous forum. Originally posted by PB.
I think there is a bug in PB because you are also unable to use Windows API to access the Registry in versions 2.50 and higher.
I'm still waiting for someone to look into this and find a solution.
Here's how I used to read/write the Registry in Visual Basic...
Perhaps you (or someone else) can translate it to PureBasic?
Code: Select all
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_DYN_DATA = &H80000006
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_USERS = &H80000003
'
' Read Registry string
Public Function GetSettingString(hKey As Long, strPath As String, strValue As String, Optional Default As String) As String
Dim hCurKey As Long
Dim lValueType As Long
Dim strBuffer As String
Dim lDataBufferSize As Long
Dim intZeroPos As Integer
Dim lRegResult As Long
If Not IsEmpty(Default) Then
GetSettingString = Default
Else
GetSettingString = ""
End If
lRegResult = RegOpenKey(hKey, strPath, hCurKey)
lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, lValueType, ByVal 0&, lDataBufferSize)
If lRegResult = 0& Then
If lValueType = 1 Then
strBuffer = String(lDataBufferSize, " ")
lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, ByVal strBuffer, lDataBufferSize)
intZeroPos = InStr(strBuffer, Chr(0))
If intZeroPos > 0 Then
GetSettingString = Left(strBuffer, intZeroPos - 1)
Else
GetSettingString = strBuffer
End If
End If
End If
lRegResult = RegCloseKey(hCurKey)
End Function
'
' Write Registry string
Public Sub SaveSettingString(hKey As Long, strPath As String, strValue As String, strData As String)
Dim hCurKey As Long
Dim lRegResult As Long
lRegResult = RegCreateKey(hKey, strPath, hCurKey)
lRegResult = RegSetValueEx(hCurKey, strValue, 0, 1, ByVal strData, Len(strData))
lRegResult = RegCloseKey(hCurKey)
End Sub
'
' Read Registry DWord
Public Function GetDWord(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
Dim lResult As Long
Dim lValueType As Long
Dim lBuf As Long
Dim lDataBufSize As Long
Dim ret As Long
Dim keyhand As Long
ret = RegOpenKey(hKey, strPath, keyhand): lDataBufSize = 4
lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)
If lResult = 0& And lValueType = 4& Then GetDWord = lBuf
ret = RegCloseKey(keyhand)
End Function
'
' Example usages...
'
' Read PC's current IP address (string)
Dim ip As String
ip = GetSettingString(HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\Class\NetTrans\0000\", "IPAddress")
'
' Change PC's IP address to "192.0.0.1" (string)
Dim ip As String
ip = "192.0.0.1"
SaveSettingString HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\Class\NetTrans\0000\", "IPAddress", ip
'
' Read PC's "Show Full Folder Path" setting (DWord)
Dim r As Long
r = GetDWord(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState\", "FullPath")
PB - Registered PureBasic Coder
Edited by - PB on 08 December 2001 02:22:02
Posted: Sat Dec 08, 2001 2:42 am
by BackupUser
Restored from previous forum. Originally posted by Paul.
Hello PB,
It's not really a matter of not knowing how to call the API, it's that something in version 2.50 and higher is preventing it from working.
Here is some code to read a registry key (it works perfectly under 2.40 or lower.
Code: Select all
keyhandle.l=0
RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings",0,#KEY_READ,@keyhandle)
name$="ActiveXCache"
result$=" "
datasize.l=255
RegQueryValueEx_(keyhandle,@name$,0,0,@result$,@datasize)
RegCloseKey_(keyhandle)
MessageRequester(name$,"Result: "+result$,0)
RegOpenKeyEx_() fails every time under 2.50 and higher but works fine in lower versions.
Edited by - paul on 08 December 2001 02:44:32
Posted: Sat Dec 08, 2001 10:30 am
by BackupUser
Restored from previous forum. Originally posted by wavemaker.
RegOpenKeyEx_ returns ERROR_FILE_NOT_FOUND (the problem must be in the path), so the key handle set is not valid, and RegQueryValueEx_ returns ERROR_BADKEY.
Bye,
Juan Calderón Alonso
Registered user
Posted: Sat Dec 08, 2001 4:17 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.
>>RegOpenKeyEx_ returns ERROR_FILE_NOT_FOUND
Exactly, so something in the newer versions of PB is blocking this from working (along with Mr.Skunks Registry library).
Like I said, this only works in 2.40 or lower.
Hopefully Fred can look into this and find a solution.
Posted: Fri Dec 21, 2001 5:21 am
by BackupUser
Restored from previous forum. Originally posted by Shawn.
Hi.
To finish off this thread, Fred has found the problem and will fix the bug in the next version. For more information, refer to the topic "Registry Keys" in Bug Reports.
Thanks Fred!
Shawn
Posted: Fri Mar 22, 2002 2:45 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> To finish off this thread, Fred has found the problem and will fix the bug
> in the next version.
Did this fix ever happen? Or is it still slated for v3.0? (Sorry I can't test
it right now -- not using a PC with PureBasic installed).
PB - Registered PureBasic Coder
Posted: Fri Mar 22, 2002 2:58 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
This is really fixed (I use the lib in one of the my progs)
Fred - AlphaSND
Posted: Fri Mar 22, 2002 3:32 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> This is really fixed (I use the lib in one of the my progs)
Okay, I just picked up my lazy butt and got my laptop out of the car, and tried
it. It does work except for one thing: CloseRegKey() causes an Illegal Operation
when used -- very strange. No such problem for you...? All I'm doing is reading
a DWORD key (works fine), toggling it with WriteRegNumeric (works fine), and
closing the key with CloseRegKey (crashes).
PB - Registered PureBasic Coder
Edited by - PB on 22 March 2002 16:29:23
Posted: Thu Mar 28, 2002 3:23 am
by BackupUser
Restored from previous forum. Originally posted by Shawn.
> This is really fixed (I use the lib in one of the my progs)
Okay, I just picked up my lazy butt and got my laptop out of the car, and tried
it. It does work except for one thing: CloseRegKey() causes an Illegal Operation
when used -- very strange. No such problem for you...? All I'm doing is reading
a DWORD key (works fine), toggling it with WriteRegNumeric (works fine), and
closing the key with CloseRegKey (crashes).
PB - Registered PureBasic Coder
Edited by - PB on 22 March 2002 16:29:23
CloseRegKey crashed my app too. I just left it out as I only needed to open one key. Then, since the app worked, I forgot about reporting the problem.
Sorry.
Shawn