Results 1 to 13 of 13

Thread: Vb. Error accessing the system registry

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Vb. Error accessing the system registry

    I have a program of mine writen in VB4. It is a simple calendar program and works fine all these years. But when it is installed (from its setup file) in a computer with windows vista or 7, then the first time that the user tries to run it, he receives the message: "Error accessing the system registry" and then: "Unexpected error; quitting". I know the solution. Right click and select "Run as administrator". But some computer users do not know that (to select the first time this selection - Run as administrator).
    So my question has 2 brunches.
    1. Is it possible to add something in the program's code to inform or warn the user, just before or just after these messages above, (and before the program closes), as a promptness or instruction, to select the next time "Run as administrator"? (like a msg box for example).
    2. Or anything else in the program's source code or in setup building to bypass this problem?

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Vb. Error accessing the system registry

    Programs should not normally do this. The installer should run "as administrator" (this is called "elevated" these days) and take care of registering components and creating folders and setting permissions on them.

    But the question is, can your program detect these errors and handle them?

    If so, the program could just rerun itself elevated and terminate.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Vb. Error accessing the system registry

    i read this differently to dilettante, looks like your instal works correctly but the program fails when run
    if you add a manifest to /for your program, it can prompt for admin password
    search in this and codebank forums for manifest files
    la volpe has posted a project, in codebank, to add /create manifests to put into resource file
    there is also a method /program available, to add a manifest directly to a compiled exe
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    Lively Member
    Join Date
    Mar 2011
    Posts
    118

    Re: Vb. Error accessing the system registry

    Quote Originally Posted by giann View Post
    I have a program of mine writen in VB4. It is a simple calendar program and works fine all these years. But when it is installed (from its setup file) in a computer with windows vista or 7, then the first time that the user tries to run it, he receives the message: "Error accessing the system registry" and then: "Unexpected error; quitting". I know the solution. Right click and select "Run as administrator". But some computer users do not know that (to select the first time this selection - Run as administrator).
    So my question has 2 brunches.
    1. Is it possible to add something in the program's code to inform or warn the user, just before or just after these messages above, (and before the program closes), as a promptness or instruction, to select the next time "Run as administrator"? (like a msg box for example).
    2. Or anything else in the program's source code or in setup building to bypass this problem?
    You could include a manifest file with your executable (this tells Windows to run the program as administrator automatically.)

    OR

    You can embed the manifest file inside the EXE directly with Resource Hacker.

    It was really grinding away at me until I figured this one out... I was so happy I had to blog about it. Here is my blog with instructions and a sample manifest file: http://blog.foolishit.com/2011/01/vb...embedding.html

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Re: Vb. Error accessing the system registry

    Quote Originally Posted by Foolish Tech View Post
    You can embed the manifest file inside the EXE directly with Resource Hacker.
    What is a manifest file and how could I embed it inside the exe?

  6. #6
    Lively Member
    Join Date
    Mar 2011
    Posts
    118

    Re: Vb. Error accessing the system registry

    Quote Originally Posted by giann View Post
    What is a manifest file and how could I embed it inside the exe?
    ahem... see the link to my blog :P

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Re: Vb. Error accessing the system registry

    Or how can I create this manifest file and how can I include it with my executable? (to tell Windows to run the program as administrator automatically.)

  8. #8
    Lively Member
    Join Date
    Mar 2011
    Posts
    118

    Re: Vb. Error accessing the system registry

    Quote Originally Posted by giann View Post
    Or how can I create this manifest file and how can I include it with my executable? (to tell Windows to run the program as administrator automatically.)
    IF YOU CLICK THE LINK I POSTED TO MY BLOG....

    it will answer all your questions. Just use the sample manifest file I provided for download, and follow the instructions!

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Re: Vb. Error accessing the system registry

    Quote Originally Posted by Foolish Tech View Post
    IF YOU CLICK THE LINK I POSTED TO MY BLOG....

    it will answer all your questions. Just use the sample manifest file I provided for download, and follow the instructions!
    Thank you!

  10. #10
    Lively Member
    Join Date
    Mar 2011
    Posts
    118

    Re: Vb. Error accessing the system registry

    Quote Originally Posted by giann View Post
    Thank you!
    Your welcome, glad you got it sorted. This is the first time I've actually had something to *contribute* to these forums rather than coming here with my own problems.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Re: Vb. Error accessing the system registry

    What is the difference if in manifest file instead of, level="requireAdministrator" I put, level="asInvoker" ?

  12. #12
    Lively Member
    Join Date
    Mar 2011
    Posts
    118

    Re: Vb. Error accessing the system registry

    Quote Originally Posted by giann View Post
    What is the difference if in manifest file instead of, level="requireAdministrator" I put, level="asInvoker" ?
    source: HERE

    asInvoker

    The application runs with the same access token as the parent process.

    Recommended for standard user applications. Do refractoring with internal elevation points, as per the guidance provided earlier in this document.

    highestAvailable

    The application runs with the highest privileges the current user can obtain.

    Recommended for mixed-mode applications. Plan to refractor the application in a future release.

    requireAdministrator

    The application runs only for administrators and requires that the application be launched with the full access token of an administrator.

    Recommended for administrator only applications. Internal elevation points are not needed. The application is already running elevated.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Re: Vb. Error accessing the system registry

    Everything is ok! I created a manifest file with level="asInvoker" and I embed this file inside the EXE with Resource Hacker.
    Thank you all!

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