CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Location
    France
    Posts
    14

    Using registry...

    Hi..
    Here's a new question for you programmers..
    I'm writing an application which should start up with Windows, but without having a 'myapp.lnk' in the start up menu..So, to do this, I thought I should use the registry, but the problem is that I never used registry before...So, imagine I have the full path of my app in

    CString myPath = "c:\mypath\myapp.exe";



    ..then, how can I add it into registry so that the app start up automatically with Windows..I think that I should write it into
    HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Run
    in the registry, is this right ?..
    If so, how can I write myPath into it if it doesn't already exists ?..hey, also I would like to know how I can remove it ?
    Could you send me some sample code..?
    Thanks a lot..
    -Cedric-


  2. #2
    Join Date
    May 1999
    Posts
    12

    Re: Using registry...

    Hi,
    You have to use the follwing piece of code. The RegOpenKeyEx creates the key for you. Use RegSetValueEx to set the path of the exe you want to write.


    char filepath[] = "c:\mypath\myapp.exe";
    HKEY hKey;
    RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run\\",0,KEY_ALL_ACCESS,&hKey);
    LONG i = RegSetValueEx( hKey,"YourApp",0,REG_SZ,(BYTE*) filepath,sizeof(filepath)+1);
    RegCloseKey(hKey);




    Regards,
    M. Jose Wilson,
    Software Engineer,
    Aditi Technologies Pvt Ltd,
    Bangalore,
    India.



  3. #3
    Join Date
    May 1999
    Location
    France
    Posts
    14

    Re: Using registry...

    thanks a lot...I'll try this code..

    -Cedric-


  4. #4
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Using registry...

    Sorry, RegOpenKeyEx() does NOT create the key if it does not already exist. The required function is RegCreateKeyEx(), which will create it if it does not exist or just open it if it does exist.


    --
    Jason Teagle
    [email protected]

  5. #5
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Using registry...

    RegOpenKeyEx() does NOT create the key if it does not already exist. The required function is RegCreateKeyEx(), which will create it if it does not exist or just open it if it does exist.


    --
    Jason Teagle
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured