开发者

Detect if my application is being executed from the users directory

开发者 https://www.devze.com 2023-04-02 00:34 出处:网络
I need to detect if my application is being executed from t开发者_如何学Gohe users directory. For example c:/users on Windows7.

I need to detect if my application is being executed from t开发者_如何学Gohe users directory.

For example c:/users on Windows7.

But i need it to work on all Windows versions.


You can get the directory of the current application as follows:

string appPath = Path.GetDirectoryName(Application.ExecutablePath);

You then need a string compare to see to check if the path startswith:

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

Or which ever location you want to test against, see here for list os special folders. These resolve appropriately under each OS version.


bool isUsersPath = System.Reflection.Assembly.GetExecutingAssembly().Location.StartsWith(System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号