简体   繁体   English

确定是否从基于Windows的应用程序中调用类库

[英]Determine whether the class library is called from a windows based application

This is based on C#. 这是基于C#的。 I am having a classlibrary in which I would like to know specifically if its being called from a windows based application 我在一个图书馆中,我想具体了解它是否从基于Windows的应用程序中调用

I searched a lot but all I found was code to know if it was called from a Console application. 我进行了很多搜索,但发现的只是代码,以了解是否从控制台应用程序调用了它。 I only want to know if its called from a windows based application or not 我只想知道它是否从基于Windows的应用程序中调用

Please Help 请帮忙

If you want to know whether the application is running as a service or system app and thus cannot display a dialogue, test the state of Environment.UserInteractive. 如果您想知道该应用程序是作为服务运行还是作为系统应用程序运行,因此无法显示对话,请测试Environment.UserInteractive的状态。

There is no easy way to determine if the application is a windows or cmd-based application. 没有简单的方法来确定应用程序是Windows还是基于cmd的应用程序。 For example, I might build a winforms-based application that doesn't create a window and instead runs as command-line style application by not opening a window. 例如,我可能会构建一个基于Winforms的应用程序,该应用程序不会创建窗口,而是通过不打开窗口而作为命令行样式的应用程序运行。

Two (not necessarily reliable) ways of testing if it's a windows-based app would be to test Application.OpenForms (if it contains forms, then it's a windows app) or Environment.GetCommandLineArgs() (if 0 args, assume it's a windows app). 两种(不一定可靠)测试它是否为基于Windows的应用程序的方法是测试Application.OpenForms(如果包含表单,则为Windows应用程序)或Environment.GetCommandLineArgs()(如果args为0,则假定它为Windows。应用)。

If you absolutely need to know whether the app is a console or windows one, then you need to step out of the world of managed code and start delving into the exe file using unmanaged C++ code. 如果您绝对需要知道该应用程序是控制台还是Windows,那么您需要走出托管代码领域,并开始使用非托管C ++代码深入研究exe文件。 There is just one byte difference between the two in the PE header of the exe file: Subsystem is set to 2 for a windows app and 3 for a cmd app. exe文件的PE标头中的两个字节之间只有一个字节的差异:Windows应用程序的子系统设置为2,cmd应用程序的子系统设置为3。 See http://msdn.microsoft.com/en-us/library/ms809762.aspx and http://support.microsoft.com/kb/90493/en-us for details if you really want to do this. 如果您确实要执行此操作,请参阅http://msdn.microsoft.com/zh-cn/library/ms809762.aspxhttp://support.microsoft.com/kb/90493/zh-cn了解详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定 Windows 应用程序是否在屏幕外? - How to determine whether a Windows application is offscreen? 如何确定一个类是在控制台应用程序或wpf中实例化的? - How to determine whether a class is instantiated within a console application or wpf? 在Windows Phone 8中,从源应用程序调用Launcher.LaunchUriAsync时是否可以确定源应用程序? - In Windows Phone 8, is it possible to determine source app when Launcher.LaunchUriAsync was called from that source application? 从C#中的类库访问Windows应用程序表单 - Accessing windows application forms from class library in C# 确定 Windows 机器上的时间是否从服务器自动更新 - Determine whether time on Windows machine is updated automatically from server or not 确定控制台应用程序是从命令行还是从 Powershell 运行 - Determine whether Console Application is run from command line or Powershell 如何确定来自其他应用程序的窗口是否可见? - How can I determine whether a window from another application is visible? 确定程序集是否是GUI应用程序 - Determine whether assembly is a gui application Windows应用商店:通过反射从customcontrol类库加载样式,未调用OnApplyTemplate吗? - Windows Store Apps : Loading styles from a customcontrol class library via reflection, OnApplyTemplate is not called? 从类库C#Windows应用程序访问Windows应用程序控件 - Accessing windows applications controls from class library c# windows application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM