zoukankan      html  css  js  c++  java
  • C#中几种不同路径表示在网域和本地的差异

    在C#程序中,有这么几种表示当前路径的方法:

    System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
    System.Environment.CurrentDirectory
    System.IO.Directory.GetCurrentDirectory()
    System.AppDomain.CurrentDomain.BaseDirectory
    System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
    System.Windows.Forms.Application.StartupPath
    System.Windows.Forms.Application.ExecutablePath

    看到这些,不管你晕没晕,反正我晕了,我也懒得去读MSDN看它们的差别,因为我知道如果把这几个的说明都读一遍,我会更晕。于是乎,写个程序来测试一下,主要测试了在本机运行和在局域网运行的情况(由于后两种是在Win Forms中使用的,所以没有测试)。

    另外,两种情况下程序都不是直接运行,而是通过python的os.system()来调用的,运行python的目录是桌面,即C:\Users\xxx\Desktop.

    上图是通过python调用os.system(".\\test\\install.exe")运行的结果,可以看到:

    1. Environment.CurrentDirectory   和   Directory.GetCurrentDirectory()都指向了运行python的目录,即桌面;

    2. AppDomain.CurrentDomain.BaseDirectory   和   AppDomain.CurrentDomain.SetupInformation.ApplicationBase指向了程序真正所在的目录;

    3. Process.GetCurrentProcess().MainModule.FileName则指向了完整的程序路径。

    上图是把程序放在局域网另外一台机器上同样通过python调用os.system(r"\\xx.xx.xx.xx\Home\xxxx\Kelvin\install.exe")运行的情况,可以看到:

    1. Environment.CurrentDirectory   和   Directory.GetCurrentDirectory()仍然指向了运行python的目录,即桌面;

    2. AppDomain.CurrentDomain.BaseDirectory   和   AppDomain.CurrentDomain.SetupInformation.ApplicationBase仍然指向了程序真正所在的目录;

    3. Process.GetCurrentProcess().MainModule.FileName仍然指向了完整的程序路径。

  • 相关阅读:
    聊聊关于性能优化和其他(一)
    JavaScript 事件循环及异步原理(完全指北)
    SPA路由机制详解(看不懂不要钱~~)
    Web安全系列(三):XSS 攻击进阶(挖掘漏洞)
    Web安全系列(二):XSS 攻击进阶(初探 XSS Payload)
    浅谈Generator和Promise原理及实现
    Kubernetes 服务目录
    Kubernetes 网络模型
    个人开源贡献记录
    【转载】DTO – 服务实现中的核心数据
  • 原文地址:https://www.cnblogs.com/ini_always/p/2192250.html
Copyright © 2011-2022 走看看