开发者

Detect if my application is being executed from the users directory

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜