CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    [RESOLVED] Disallowing user to run application

    Like many program's updater I'm trying to make my own updater which will not allow users to run it by double click.

    It can only be started from my main application by ShellExecute.

    What should be the ideal approach for this ?
    ◄◄ hypheni ►►

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Disallowing user to run application

    Why on earth do you want people not to run a program??

    Anyways, perhaps the updates that are running may not be launched by an exe, ever thought of that?

  3. #3
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Disallowing user to run application

    Quote Originally Posted by HanneSThEGreaT View Post
    Why on earth do you want people not to run a program??

    Anyways, perhaps the updates that are running may not be launched by an exe, ever thought of that?
    Because I don't wanna run the updater from user end at least on the Earth.. :P

    The updater will launch from my main application and kill application if it needs to be updated.
    ◄◄ hypheni ►►

  4. #4
    Join Date
    May 2005
    Posts
    4,954

    Re: Disallowing user to run application

    Quote Originally Posted by hypheni View Post
    Like many program's updater I'm trying to make my own updater which will not allow users to run it by double click.

    It can only be started from my main application by ShellExecute.

    What should be the ideal approach for this ?
    One thing you can do is add the updater.exe file to your main application resource as a bin resource when you will want to use it simply extract it to disc as exe, and launch it.

    When it launched it will close your main application and will do whatever it takes for the update.

    But keep in mind that each time you run the main application, make sure you delete the updater.exe so it won’t remain on the disc.

    This thread might help. (it deals with bmp file but its the same thing for any type of file)

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  5. #5
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Disallowing user to run application

    Thats not my goal. Binding exe as resource with application - I did a lot earlier. You can find my old posts about this which helped other so this is not the way.

    Im talking about the actual procedure which many software's updater uses. For example Garena (a virtual gaming client) updater uses the same mechanism. You cant run the updater by double clicking. It will show you error that "You can't run updater in this way."
    ◄◄ hypheni ►►

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Disallowing user to run application

    Hmmm... Just a quick shot - there may be a far more elegant solution...

    Why not simply define an undocumented command line option for the updater and pass that when invoking the updater from your main app? If the option is not present the updater refuses to run.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  7. #7
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Disallowing user to run application

    Yes thats a good idea. I will give a try and post here..

    BTW. "hmm" is used in Germany too ?. I thought its only Indian shortcut to say "Yes" online.
    ◄◄ hypheni ►►

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Disallowing user to run application

    Quote Originally Posted by hypheni View Post
    Yes thats a good idea. I will give a try and post here..

    BTW. "hmm" is used in Germany too ?. I thought its only Indian shortcut to say "Yes" online.
    Usually it's used to indicate somebody is thinking.

  9. #9
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Disallowing user to run application

    hmm.. Okay
    ◄◄ hypheni ►►

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Disallowing user to run application

    hmm, Sorry, my original post was not very helpful. I understood your question wrong.

  11. #11
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Disallowing user to run application

    Another option might be to have your installer check to see if your main app is already running. If not, issue an error, and close.

    Viggy

  12. #12
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Disallowing user to run application

    Quote Originally Posted by Eri523 View Post
    Why not simply define an undocumented command line option for the updater and pass that when invoking the updater from your main app? If the option is not present the updater refuses to run.
    Another (but similar) idea is to modify the environment variables passed to the child process when using CreateProcess to start your updater, to include a custom variable that your updater checks for.

    This is one of the Microsoft-recommended ways to pass information from a parent process to a child process.

    For an example, see "Changing Environment Variables" at http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx . Look at Example 2, which sends the child process an environment variable named "MyVariable".

    Mike

  13. #13
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Disallowing user to run application

    It can only be started from my main application by ShellExecute.
    So it would be logical to check in updater on its start what process ran it (by parent process id). And quit if it was not your main app. This is going to prevent from env variable frauds.
    Best regards,
    Igor

  14. #14
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Disallowing user to run application

    Nice idea Igor. But checking command line argument is much easier way. But of-course your procedure is more robust.

    Anyways I stick to command line argument checking. A simple strcmp() can do it.
    Last edited by hypheni; April 22nd, 2011 at 11:19 AM.
    ◄◄ hypheni ►►

  15. #15
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: [RESOLVED] Disallowing user to run application

    Why not just build your updater code as a DLL instead of an exe? That way, your main app would be able to run the updater but ordinary users wouldn't.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Page 1 of 2 12 LastLast

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