问题
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.
回答1:
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.
}
}
来源:https://stackoverflow.com/questions/12919784/how-to-programmatically-discover-whether-the-running-application-is-installed