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仍然指向了完整的程序路径。

  • 相关阅读:
    C#基础—string等类的有趣方法_1
    设计模式
    OOP-面向对象程序设计
    CSS3实用效果大全
    HTML5 DOM元素类名相关操作API classList简介(转载自张鑫旭大神)
    Js写的一个倒计时效果实例
    垂直居中的几种方案
    大图片加载优化解决方案
    DomReady实现策略
    脱离文档流
  • 原文地址:https://www.cnblogs.com/ini_always/p/2192250.html
Copyright © 2011-2022 走看看