Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Create a key  (Read 4839 times)

0 Members and 1 Guest are viewing this topic.

usman.sialkot

  • Guest
Create a key
« on: October 23, 2008, 10:54:04 AM »
sir Sidewinder,

i want to create a key in registery with VB. with the name of system

Would you please tell me the way.

aslo plz tell me creating sub keys by programming


Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Create a key
« Reply #1 on: October 23, 2008, 12:44:05 PM »
Quote
Would you please tell me the way.

Would you please tell me the way to convince you to stop creating polls everytime you post? <sigh>

Check out this method. Most of my snippets are for VBScript, but basically you end up with the same results.

Why this huge interest in the registry? What are you trying to accomplish?

 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

usman.sialkot

  • Guest
Re: Create a key
« Reply #2 on: October 24, 2008, 03:02:07 AM »
As processor is the brain of computer similarly registery is aslo the brain of OS as u know. Secondly i add pol because u can limitize the days of ur post. that's why i use poll method. Due to this my question will be deleated after 5 days.

every one says i ask too much questions, well, asking question is the main step of getting knowledge form a knowledgeable persone; like u
Hope u r not anoyed   :'(

usman.sialkot

  • Guest
Re: Create a key
« Reply #3 on: October 24, 2008, 03:12:34 AM »
i tried that code; the code was quit difficutl for me because i dont know how u program with "Public" ; i usually use private method to solve my problems.

So would u please explain this in easy way. Suppose i want to create a key

sys in HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS \

so ..............  ???

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Create a key
« Reply #4 on: October 24, 2008, 05:06:49 AM »
The whole purpose of the forum is to ask questions. This way we all learn together. Don't worry about asking too many.

Quote
Secondly i add pol because u can limitize the days of ur post. that's why i use poll method. Due to this my question will be deleated after 5 days.

Actually, I think the poll is only open for 5 days. The post stays around for eternity. Many people read these posts, so the questions and answers are available to help someone else.

Quote
i tried that code; the code was quit difficutl for me because i dont know how u program with "Public" ; i usually use private method to solve my problems.

Private methods (functions and subs) can only be called by other methods in the same class. Public methods can be called from anywhere in your program.

The Windows registry is a hierarchical database. In order to access the registry in VB, it's necessary to call the Windows API. To do this you must first define which Windows library to use (advapi32.dll) and which functions to use (RegCreateKeyExA and RegCloseKey). That's what the private declare functions do. When Microsoft wrote the library, they defined values that need to be passed to the function for it to work. The constants you see define those values.

After all the smoke has settled, all you need to provide is the key name and the hive name. The hive names are defined in this section of the code:

Code: [Select]
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003

The key name you provide. See the example in the code.

Good luck. 8)

Note: Either take a restore point or create private keys  in the hkey_current_user hive. As you mentioned, the registry may be the brain of the OS, but it has been known to flat line from time to time.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

usman.sialkot

  • Guest
Re: Create a key
« Reply #5 on: October 24, 2008, 09:28:36 PM »
i tried the method. the method is quit difficult and hard to understand
because "Public" function is used. if u expalin in with  "Private" then it will easy for me.
suppose

HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSI

ON\"system"  is the key i want to create, what would be the code

but adding DWORD value and string value we dont useing functions as

HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSI

ON\RUN\OPTIONAL COMPONENTS\IMAIL, 1, "REG_DWORD"

AND AND AND

Dim Reg As Object
Set Reg = CreateObject("wscript.shell")

' Suppose Write App to Startup with Computer

Reg.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\

CURRENTVERSION\RUN\" & App.EXEName, App.Path & "\" & App.EXEName

& ".exe"


SIMILARLY CAN WE USE PRIVATE METHOD TO CREATE A SUB KEY IN REGISTERY

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Create a key
« Reply #6 on: October 25, 2008, 06:01:53 AM »
In your other post, I gave you a VBScript solution, which you said was fine. I took it to mean that you created a script object reference in your VB program, compiled the program and it ran successfully.

This time I posted a VB5 solution. Did you put the code into a console application? Did you compile it? Did it run?

Please post the portion of the code you're having trouble with. There is only one public function in the code. There are no classes, so if you prefer to make it private, go ahead.

Are you trying to learn VB or do you only want to change the registry? If it's the latter, you can do it from the command prompt with reg

 8)

The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

usman.sialkot

  • Guest
Re: Create a key
« Reply #7 on: October 29, 2008, 09:12:14 AM »
Ya i tried that code. i put the code same to same in the Visual basic and done some change in that portion of code where to give the name to the key. i compiled that, not error occured. but The key was not created. so dont know what happened........

So what should i do ::)

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Create a key
« Reply #8 on: October 29, 2008, 05:02:40 PM »
I tried to simplify the API call as best I could.

Code: [Select]
Module Program
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" Alias "RegCloseKey" (ByVal hKey As Long) As Long
Sub Main()
Dim rc as Long
RegCreateKey(HKEY_LOCAL_MACHINE, "Your Key Goes Here",  rc)
RegCloseKey(rc)
End Sub
End Module

What are you trying to do? A skilled programmer wouldn't need to ask on a forum about the registry and API calls. If you are not skilled, you should not be mucking around in the registry. One misplaced API call can severely cripple your machine.

Check out this site to see all the functions in the advapi32 library. Not as friendly, but still useful also read MSDN

Good luck.  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Create a key
« Reply #9 on: October 29, 2008, 05:13:27 PM »
I no longer need to bother with the actual API functions and can rather use the class module I made that wraps them! HA HA HA!


but I found that too inflexible, so I created an entire library devoted to saving a programs settings. I have yet to use that library at all...

the MSDN is great- especially when you pair it with APIViewer 2004, which contains a lot of API declarations not found in the pitiful APILOAD.EXE included with VB.
I was trying to dereference Null Pointers before it was cool.

usman.sialkot

  • Guest
Re: Create a key
« Reply #10 on: October 31, 2008, 10:01:38 PM »
Done it. Yahooooooooooooooooooooo . THankx Brothers.

According to my observation Adding DWORD value or a file in register is easy but

creating a key is a difficult thing.