Hi all,
I have this code - Option Explicit
-
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
-
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
-
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
-
Private Const HKEY_LOCAL_MACHINE = &H80000002
-
Private Const REG_DWORD = 4
-
Dim nBufferKey As Long
-
Dim nVal As Long
-
-
Private Sub Form_Load()
-
nVal = 2
-
RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey
-
RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)
-
'MsgBox "Sandbox Mode Changed", vbInformation, "Sandbox"
-
RegCloseKey nBufferKey
-
Unload Me
-
End Sub
All I am try to do is write a DWORD value of 2 to the registry. The above code does work without error but the key has a value of 32(50), if I change nVal to 0 the key reads 30(48). Can anyone assist in get the key to read 2.
3 10060
Hi all,
I have this code - Option Explicit
-
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
-
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
-
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
-
Private Const HKEY_LOCAL_MACHINE = &H80000002
-
Private Const REG_DWORD = 4
-
Dim nBufferKey As Long
-
Dim nVal As Long
-
-
Private Sub Form_Load()
-
nVal = 2
-
RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey
-
RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)
-
'MsgBox "Sandbox Mode Changed", vbInformation, "Sandbox"
-
RegCloseKey nBufferKey
-
Unload Me
-
End Sub
All I am try to do is write a DWORD value of 2 to the registry. The above code does work without error but the key has a value of 32(50), if I change nVal to 0 the key reads 30(48). Can anyone assist in get the key to read 2.
I didn't test your code but at a first glance
You are passing integer to a string requested value so convert to string before passing.
Dim nVal As Long
ByVal lpData As String
[PHP]Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long[/PHP]
Also I would do this
[PHP]If RegOpenKey( HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey) = ERROR_SUCCESS Then
RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)
End If[/PHP]
I didn't test your code but at a first glance
You are passing integer to a string requested value so convert to string before passing.
Dim nVal As Long
ByVal lpData As String
[PHP]Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long[/PHP]
Also I would do this
[PHP]If RegOpenKey( HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey) = ERROR_SUCCESS Then
RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)
End If[/PHP]
If I dim nVal as a string, then the result is the DWORD value becomes invalid once the code is ran. So I'm not really sure I'm passing nVal as a string by declaring it as a string, is that enough?
I may also use the second code quote, thanks.
That happends because DWORD way for "RegSetValueEx" reads the "nVal" component of the pinvoke as an ASCII character. A string that receives "0" is "30" in ASCII hex, same for "1" -> "31" and "2" -> "32".
To set the DWORD registry "0x00000000" just use the string representation of 0 ASCII member which is "\u0000".
Example:
string value = "\u0000"; //To set 0 for DWORD registry
RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, value, Len(nVal)//Setting the string "value" for the pinvoke
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lee K |
last post by:
This is not strictly a C++ issue but if anyone will know the answer its you
guys!
I am trying to figure out a date format stored in the registry by a piece of
software (I am trying to write...
|
by: Action |
last post by:
I can add a systray icon in normal windows application...
but when i do it in windows service, the systray icon just don't show up
is that because i don't have any "component" to contain the...
|
by: CMG |
last post by:
I am writing a little code to associate an extention with
my program. And as far as i can see, i need to do the
following:
Public Function associatefile(ByVal
FILE_EXTENTION_TO_ASSOCIATE As...
|
by: bohuge |
last post by:
Hey!
At the time being I'm working on a backup solution for a Qtek9090
pocketpc, which should be able to find and backup outlook data to a
server, local files, messages and contact from the sim...
|
by: xieliwei |
last post by:
Hello, I'm attempting to write a WinNT service that basically changes
the time zone and forces a resync with a time server on initialisation.
The service will then restore the original time zone...
|
by: RhavoX |
last post by:
Hi. This may be a very stupid question but I'll leave you to judge
it ;) I know there were lots of questions about this but none of the
answers suits me.
I'm wondering how to get the BINARY type...
|
by: projectVBA |
last post by:
Hi ,
I wrote some add in for PowerPoint and i'm trying to find an automatic way to load it every time PowerPoint starts.
I found Microsoft Code example (see below ) BUT the problem is :
I can't...
|
by: teddysnips |
last post by:
I have a notional Boolean value stored in the Registry. Actually it's
a REG_DWORD capable of taking values of either 0 or 1.
So, I need to populate a checkbox on a form dependent on this value....
|
by: terryastone |
last post by:
I have an application that reads some registry values stored in the
Local Machine\Software\... key.
In XP, I can see these values using RegEdit. In my application I can
read the values at...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |