-1

I want the program to check if it's installed on the computer (using Clickonce) or just being run (e.g. by Visual Studio).

EDIT: Not a duplicate of How to detect that C# Windows Forms code is executed within Visual Studio? . "e.g." means for example.

Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291
  • @downvoter Care to explain why? Obvious answer? (Well, I don't know it.) Easily found by searching? (try it first. I did.) – ispiro Oct 16 '12 at 17:06
  • 1
    (Not the downvoter) Is this a website or a winforms application? If the latter, look at this question: http://stackoverflow.com/questions/2427381/how-to-detect-that-c-sharp-winform-code-is-executed-within-visual-studio – Bob Kaufman Oct 16 '12 at 17:06
  • @BobKaufman Added tag - Winforms. (Does it matter?) – ispiro Oct 16 '12 at 17:07
  • @BobKaufman Thanks. You can transform your comment into an answer. Although I'll still be waiting for a direct way for finding if it's installed - your answer's surely worth an upvote. I didn't realize `Debugger.IsAttached` would be `true` even if the Solution Configuration is Release. – ispiro Oct 16 '12 at 17:14
  • 4
    thanks for the offer, but I can't take credit for another's work. If one of the answers in that question helped you, by all means upvote that answer! :) – Bob Kaufman Oct 16 '12 at 17:18
  • 2
    @BobKaufman, I wish you'd put your last comment as an answer and I'd upvote it, that is really becoming a problem. For whatever reason SO has become a competition rather than a community it seems. – Mike Perrenoud Oct 16 '12 at 17:22
  • There isn't a single way. You could check to see if the virtual hosting process was running and/or if Visual Studio itself is running. – Security Hound Oct 16 '12 at 17:25
  • @Ramhound See Maarten's answer. ("e.g." means [for example](http://en.wikipedia.org/wiki/Exempli_gratia).) – ispiro Oct 16 '12 at 17:26

1 Answers1

3

You can use the ApplicationDeployment.IsNetworkDeployed property. Please note that this only works with ClickOnce installations.

private void CheckApplicationStatus() {
    if (ApplicationDeployment.IsNetworkDeployed) {
        // Do something that needs doing when the application is installed using ClickOnce.
    } else {
        // Do something that needs doing when the application is run from VS.
    }
}
Maarten
  • 22,527
  • 3
  • 47
  • 68