I have problems in my registry app, please help?

Hello,

I got this application which was compatiable with Visual Basic 6.0 so i upgraded to Visual Studio (basic) 2005 BETA 2 and then it didnt work.

What it does you click a command button and it inserts keys to the registry and adds a Shell Context Menu and 'Upload to GuruImages' will appear when you right click a .png file.

Could somebody tell me why this doesnt work, and how would I make it insert these keys into the registry on installation and how will I set the values

Thank You,

Here is the code:

Option Strict Off
Option Explicit On
Friend Class Form1
    Inherits System.Windows.Forms.Form
   
    'UPGRADE_NOTE: Command was upgraded to Command_Renamed. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Sub Rightclick_shell(ByVal EXT As String, ByVal Command1 As String, ByVal FileName As String)

        Dim b As Object
        On Error Resume Next
        b = CreateObject("wscript.shell")

        With b
            'UPGRADE_WARNING: Couldn't resolve default property of object b.regwrite. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            .regwrite("HKCR\" & EXT)
            'UPGRADE_WARNING: Couldn't resolve default property of object b.regwrite. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            .regwrite("HKCR\" & EXT & "\shell\" & Command1 & "\command\", FileName & " %1")
        End With 'b

        On Error GoTo 0
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Rightclick_shell(".png", "Upload to GuruImages", My.Application.Info.DirectoryPath & "\" & My.Application.Info.ProductName & ".exe")
    End Sub
End Class

Thank you in advance,
MSDN Forum User

(Sorry, I dont know what forum to post in.)


Answer this question

I have problems in my registry app, please help?

  • MCairney

    Wow, thank you it worked. Well it worked with no errors.

    Can you help me with one LAST thing. What if you want to enter values into files that already exist

    AND MULTIPLE OF THEM.

    HKEY_CLASSES_ROOT\.jpg\shell\Mushroom\Sausage\Pepperoni
    HKEY_CLASSES_ROOT\.bmp\shell\Mushroom\Sausage\Pepperoni
    HKEY_CLASSES_ROOT\.png\shell\Mushroom\Sausage\Pepperoni
    HKEY_CLASSES_ROOT\.jpeg\shell\Mushroom\Sausage\Pepperoni
    HKEY_CLASSES_ROOT\.gif\shell\Mushroom\Sausage\Pepperoni
    HKEY_CLASSES_ROOT\.swf\shell\Mushroom\Sausage\Pepperoni

    So if those files exist. IT WILL NOT OVERWRITE, But it'll go into it and add the values that are not their.

    Could you put it in your first code you made me and re-send please. Thank You

  • stxrxgl

    Yes, I did. I posted code that works here and certainly can't help you with your problem with out adequate information.

    I cannot know what your problem is on Beta II, if you don't carefully convey it.

    Along with this line:

    <Assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify:="HKEY_CLASSES_ROOT\")> 

    Make that a single line, and it should work.

    I suspect the problem is that the editor on this board made one line into three lines. Make it just one line and I suspect that your problem, will be solved.

    If using the registry seems inconvenient, I'd recommend that the settings facility may be something you may want to investigate toward solving your problem.

    Have a good day. :)




  • jesus m

    When you right click any of the following file extensions on your PC; .png .gif .jpeg .jpg .swf .bmp it gives you a menu am i correct Then added to that menu (Above SendTo: or something) will say "Upload to Pizza" Pizza being an example.

    Then when you click that it'll execute my programe, automatically adding the PATH (E.G C:/user/user/coo.jpg) of the image you just right clicked into text1 of my application made in VB 2005 BETA 2.

    Then their'll be a 'Host It' which you will click and it'll upload to Pizza, Pizza being an example.

    Once you press host it, the URL of the image you uploaded will appear in text2.

    (Image Host)

  • RayHzz

    Hi,

    I am so sorry for not making myself clear.

    1. I am not distributing my code or applications I make, I am learning this language :)
    2. I know what .msi is but how do they make those installers As these installers automatically install registry values so I dont have to do all this. Or do I

    Here is some more infomation about the errors of the FIRST code you gave me (When I click the error it highlights the error, I have made the text blue where it highlights):

    Expression Expected: Line 5, Colunm 39
    <Assembly: RegistryPermissionAttribute( _

    Declartion Expected: Line 7, Colunm 1
    SecurityAction.RequestMinimum, ViewAndModify:="HKEY_CLASSES_ROOT\")>

    ---

    If you want the full code, just go to the second reply on this topic. You posted it yourself ;).

    Remember I need this to be compatiable with Microsoft Visual Basic/Studio 2005 BETA 2. This is what I am using.

    Thanks in advance,
    MSDN Forum User


  • susanowo

    Thank you,

    I'll try this code out soon. Can I ask how would you make it so it only will enter the keys the FIRST time you run the application and never again

    Is their any installer that automatically puts registry keys like these

    How can i add multiple keys & values into the registry at once (Load up) for just the first time.

    Thank you in advance,
    MDSN Forum User

    EDIT: And if you dont mind, would you please tell me a little more about strings & values

  • Wollmatt

    I need to see the line of code you have. I deleted mine.

    You and I are running two different version of VS2005.

    Beta-II is the second beta test. I have a later release which is called Release Candidate 1.

    In my personal experience there are differences.

    You know, a person can ask extensive questions in a single sentence.

    You asked about .msi files which is almost a science in itself. They are installation files and internally they are quite complex. If you want to learn about them, I can best refer you to the Windows Server 2003 Platform SDK which is also the XP sdk. In it, is a tutorial on .msi files and the Microsoft Orca Msifile editor. Mind you, Orca is basic and the task is complex.

    Keep in mind a couple of things. You can publish code with Beta-II. It's very easy.

    In the long time there will be several problems. If you sent me an image, I could not execute it as I am running a different version of the framework. In the long run this will become true  for the majority of the world as the official release comes out and Beta-II as well as RC1 dies out. You may want to consider what you are distributing.

    if you get me the lines of code where things failed for you, I do what I can.

    That code compiled and ran here and it was taken from code the was developed under Beta-II although I must admit that it required about ten hours to convert 4000 lines of Beta-II code to RC1 code. So I am confused as to why that isn't compiling for you.

    I hope you included the imports at the top of the file. That's one of the few things I can think of that would cause that problem.

    Renee

  • SamSmithnz


    The key creation and value setting, would look like this:

    Imports System.Security.Permissions

    Imports Microsoft.Win32

    <Assembly: RegistryPermissionAttribute( _

    SecurityAction.RequestMinimum, ViewAndModify:="HKEY_CLASSES_ROOT\")>

    Public Class Form1

    Dim RegKeySettings As Microsoft.Win32.RegistryKey

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    AddtoRegistry("Mushroom\Sausage\Pepperoni")

    WriteRegistrySubKeyValue(
    "flavors", "Yummy")

    End Sub

    Private Sub AddtoRegistry(ByVal Subkeys As String)

    Dim Root As RegistryKey = Registry.ClassesRoot.CreateSubKey(Subkeys)
    Root.Close()

    End Sub

    Private Sub WriteRegistrySubKeyValue(ByVal SubkeyName As String, ByVal Value As Object)

    My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\Mushroom\Sausage\Pepperoni", SubkeyName, Value)

    End Sub
    end class


    This is working code. I didn't know your values for Ext etc, so I made up a fun example that I hope you are able to use.
     

    When I look in the registry I see the Keys and data and am able to export it.

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\Mushroom]

    [HKEY_CLASSES_ROOT\Mushroom\Sausage]
    [HKEY_CLASSES_ROOT\Mushroom\Sausage\Pepperoni]
    "flavors"="Yummy"


    Now I must go clean the pizza out of my registry.



  • WarrenT

    You suggested organization is not really consistent with convention. It wouldn't damage your registry but it would make it messy and less than tidy.

    Once you understand the registry, it's not hard. I remember people used to talk about it

    Here is the organization I think you want:

    HKEY_Users\Software\MSDNuser\jpg
    HKEY_Users\Software\MSDNuser\bmp
    HKEY_Users\Software\MSDNuser\gif

    Lets say that you wanted to put things in subkey gif

    Public Sub WriteRegistrySubKeyValue(ByVal SubkeyName As String, ByVal Value As Object)

    My.Computer.Registry.SetValue("HKEY_Users\Software\MSDNuser\gif
    "
    , SubkeyName, Value)

    End Sub

    You want to add a name-value pair of "photo1"  value:10 (numeric)

    WriteRegistrySubkeyValue("photo1",10)

    But you can also do something else by modifying the routine:


    Public Sub WriteRegistrySubKeyValue(Byval Keyname as string, ByVal SubkeyName As String, ByVal Value As Object) as boolean

    WriteRegistrySubKeyValue = True

    try

    My
    .Computer.Registry.SetValue("HKEY_Users\Software\MSDNuser\"  _
    &   keyname, 
     SubkeyName, Value)

    catch
        WriteRegistrySubKeyValue = False
    end try


    End
    Sub


    And call this:

    Const cgif as string = "gif"
    Const cjpg as string = "jpg"


    WriteRegistrySubkeyValue(cgif,"photo1",10)

    This will specify the gif subkey and add the name value pair.

    * Note keep in mind that this editor is doing funning things to line wrapping. You're not responsible for it but in cases like ths, I'm going to ask that you be responsible for editoral syntax issues meaning that if the editor breaks the code, you fix it.



  • mhmani21

    "When you right click any"

    Right click with what utility

    I have a GUI-based user written utility that I use on a variety of files.

    What I have done is make sure that it can take filenames in as a command line.

    I then place a shortcut to that utility in my SendTO directory so that utility becomes a send selection on my explorer context menu.

    I think that captaures the functionality you are looking for, without rewiring Windows.





  • abhi243

    Sorry, last thing I found 2 errors in your code;

    Expression Expected: Line 5, Colunm 39
    Declaration Expected: Line 7, Colunm 1

    Thank you.


  • daidaiNeko

    That last arrangement is a desirable key specifiication unless you want multiple users users to have access to the same set of data.

    With this arrangement, each user will have her own set of data.

  • Deivich

    Thnx,

    See what I intend to get when I finish is;

    When you right click any, .png, .gif, .jpeg, .jpg, .bmp, .swf file their will be new option 'Upload to Pizza' of course Pizza is just EXAMPLE.

    You'd click Pizza and it'll execute my application made in Visual Studio 2005 BETA 2 (VB). Then it'll automatically put the path where you right clicked that image from into text1 in my application.

    Is this possible lol

  • Ponnaravi

    Wow, thank you very much!

    Errors:
    Expression Expected: Line 5, Colunm 39
    Declaration Expected: Line 7, Colunm 1 (OF YOUR FIRST CODE U GAVE ME)


    You have once again helped me alot. And that is exactly all I wanted.

    Unfortunatly I dont know what RC1 is, I got Visual Studio 2005 BETA 2... I ordered the trail/evaluation.

    By the way, would you mind telling me a bit about MSI (the installer thing, and how to make one).

    Beacuse I looked in all the toolbars in Microsoft Visual Studio 2005 BETA 2 and cant find

    Thank you!


  • Peter Villadsen

    Hmmmm

    Having run both Beta-II and RC1, I know there are some differences. There are no errors here with the code on RC1 or I couldn't have run it, so I need more information from you on the errors to be able to assist you. I'm sure I didn't save the code and this editor distorts line numbers, so I need for you supply the line where you have the errors.

    Yes, you can check for "first time" conditions....

    Here's how to check for firstime


    Private Function IsFirstTimeForUser() As Boolean

    If My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\Mushroom\Sausage\Pepperoni", "Flavors", "KeyIsPresent") <> "KeyIsPresent" Then

    IsFirstTimeForUser = True

    Else

    IsFirstTimeForUser = False

    End If

    End Function


    How can i add multiple keys & values into the registry at once (Load up) for just the first time


    Multiple Keys:

    AddtoRegistry("Mushroom\Sausage\Pepperoni")
    AddtoRegistry("Mushroom\Sausage\Olives")
    AddtoRegistry("Mushroom\Sausage\Hambuger")
    AddtoRegistry("Mushroom\Sausage\Pineapple")
    AddtoRegistry("Mushroom\Sausage\Anchovie")  'Eeeeeeeewwwwwww


    Values:

    AddtoRegistry("Mushroom\Sausage\Pepperoni")
    WriteRegistrySubKeyValue("Aroma", "Mmmmmmmm)
    WriteRegistrySubKeyValue("Garlic", "Wow")

    Probably won't be as interested in keys as you will be values. Here is the organization of an actual project. Notice that there is one set keys and multiple values:


    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\RenToolBar]

    [HKEY_CURRENT_USER\Software\RenToolBar\Values]
    "Region"="1"
    "ToolBar"="office"
    "iARGBColor1"=dword:ff5a11b2
    "iARGBColor2"=dword:ffcbbcbb
    "iARGBChosenColor1"=dword:ffb22222
    "iARGBChosenColor2"=dword:ff7b68ee
    "iARGBRandomColor1"=dword:ffb22222
    "iARGBRandomColor2"=dword:ff7b68ee
    "iSnap_X"=dword:0000009d
    "iSnap_Y"=dword:000000a3
    "iSnap_Height"=dword:000000fa
    "iSnap_Width"=dword:000000fa
    "iCntnr_Top"=dword:00000052
    "iCntnr_Left"=dword:000000af
    "iCntnr_Height"=dword:0000002d
    "iCntnr_Width"=dword:000002b8
    "ChkbxUseGradient_Enabled"="True"
    "ChkbxUseGradient_Checked"="True"
    "ChkbxRandomlySelectedGradient_Checked"="True"
    "ChkbxUseSystemColors_Enabled"="True"
    "ChkbxUseSystemColors_Checked"="False"
    "ChkbxLargeIcons_Checked"="True"
    "ChkbxAOT_Checked"="False"
    "ChkbxRunAtStartup_Checked"="False"
    "ChkbxStartAtBootDontAsk_Checked"="False"
    "ChkbxAutoFit_Checked"="False"
    "ChkbxSound_Checked"="True"
    "ChkbxSplashScreenatLaunch_Checked"="True"
    "ChkbxAutoHide_Enabled"="True"
    "ChkbxAutoHide_Checked"="True"
    "ChkbxRandomlySelectedGradient_Enabled"="True"

    The Hive is HKEY_CURRENT_USER

    Subkeys are Software and RenToolbar

    Every else is a value and note.....the variety of values under the Key RenToolbar

    There are Booleans, strings and double words under one key. This a rather typical scheme and organization of the registry


    Strings and values....

    A string a a set of one or more characters in memory. These days a character is two bytes of memory.

    A value can be any datatype  a boolean, a string, a byte or an integer which is why that routine uses object  as the dataype as the value argument. That makes that routine very flexible and easier to use than usual because an object can be any datatype and that routine is used in conjunction with a host of datatypes. Although that doesn't look like an overly clever routine, it's deceptive because it is so flexible.

    If you are going to start writing to the registry, I would encourage you to make a restore point before beginning and to make sure that your autorestore disks are up to date.



  • I have problems in my registry app, please help?