System.Environment.TickCount;//调用开机时间,毫秒。
Application.StartupPath;//调用应用程序运行路径。
Environment.CurrentDirectory;//应用程序工作路径。
Application.ExecutablePath;//获取应用程序目录名称。
网站中可以在类文件中用绝对方式访问Server对象、Session、Response、Request等对象:
System.Web.HttpContext.Current.Server.MapPath()
System.Web.HttpContext.Current.Session
System.Web.HttpContext.Current.Response
System.Web.HttpContext.Current.Request
//一些系统路径的提取
RegistryKey folders;
folders = OpenRegistryPath(Registry.CurrentUser, @"\software\microsoft\windows\currentversion\explorer\shell folders");
// Windows用户桌面路径
string desktopPath = folders.GetValue("Desktop").ToString();
// Windows用户字体目录路径
string fontsPath = folders.GetValue("Fonts").ToString();
// Windows用户网络邻居路径
string nethoodPath = folders.GetValue("Nethood").ToString();
// Windows用户我的文档路径
string personalPath = folders.GetValue("Personal").ToString();
// Windows用户开始菜单程序路径
string programsPath = folders.GetValue("Programs").ToString();
// Windows用户存放用户最近访问文档快捷方式的目录路径
string recentPath = folders.GetValue("Recent").ToString();
// Windows用户发送到目录路径
string sendtoPath = folders.GetValue("Sendto").ToString();
// Windows用户开始菜单目录路径
string startmenuPath = folders.GetValue("Startmenu").ToString();
// Windows用户开始菜单启动项目录路径
string startupPath = folders.GetValue("Startup").ToString();
// Windows用户收藏夹目录路径
string favoritesPath = folders.GetValue("Favorites").ToString();
// Windows用户网页历史目录路径
string historyPath = folders.GetValue("History").ToString();
// Windows用户Cookies目录路径
string cookiesPath = folders.GetValue("Cookies").ToString();
// Windows用户Cache目录路径
string cachePath = folders.GetValue("Cache").ToString();
// Windows用户应用程式数据目录路径
string appdataPath = folders.GetValue("Appdata").ToString();
// Windows用户打印目录路径
string printhoodPath = folders.GetValue("Printhood").ToString();
获得系统变量
System.Environment.GetEnvironmentVariable("windir");
//操作系统版本 Console.WriteLine("Current OS:\n{0}\n", Environment.OSVersion);
//包含这个应用程序的目录 Console.WriteLine("Current Directory:\n{0}\n", Environment.CurrentDirectory);
//列出这台机器上的驱动器 Console.WriteLine("Current all of logicaldrives:");
string[] drives = Environment.GetLogicalDrives();
foreach (string d in drives)
Console.WriteLine(d);
//当前.Net平台版本 Console.WriteLine("\nExecuting version of .NET:\n{0}\n", Environment.Version);
//当前机器的名字 Console.WriteLine("Current MachineName:\n{0}\n",Environment.MachineName);
//当前环境的换行符 Console.WriteLine("Current Environment's NewLine:\n{0}", Environment.NewLine);
//当前机器的处理器数量 Console.WriteLine("Current ProcessorCount:\n{0}\n", Environment.ProcessorCount);
//当前系统目录 Console.WriteLine("Current SystemDirectory:\n{0}\n", Environment.SystemDirectory);
//启动该程序的用户名 Console.WriteLine("Current UserName:\n{0}\n", Environment.UserName);
//当前域用户名 Console.WriteLine("Current UserDomainName:\n{0}\n", Environment.UserDomainName);
//当前编译生成文件存放位置 Console.WriteLine("Current CompleteFile:\n{0}\n", Environment.CommandLine);
粘贴了:Environment类下的方法和属性,很有用。
属性
| 名称 | 说明 | |
|---|---|---|
![]() ![]() |
CommandLine | 获取该进程的命令行。 |
![]() ![]() |
CurrentDirectory | 获取或设置当前工作目录的完全限定路径。 |
![]() ![]() ![]() |
CurrentManagedThreadId | 获取当前托管线程的唯一标识符。 |
![]() ![]() |
ExitCode | 获取或设置进程的退出代码。 |
![]() ![]() ![]() ![]() |
HasShutdownStarted | 获取一个值,该值指示公共语言运行时 (CLR) 是否正在关闭。 |
![]() ![]() |
Is64BitOperatingSystem | 确定当前操作系统是否为 64 位操作系统。 |
![]() ![]() |
Is64BitProcess | 确定当前进程是否为 64 位进程。 |
![]() ![]() |
MachineName | 获取此本地计算机的 NetBIOS 名称。 |
![]() ![]() ![]() ![]() ![]() |
NewLine | 获取为此环境定义的换行字符串。 |
![]() ![]() ![]() |
OSVersion | 获取包含当前平台标识符和版本号的 OperatingSystem 对象。 |
![]() ![]() ![]() ![]() ![]() |
ProcessorCount | 获取当前计算机上的处理器数。 |
![]() ![]() |
StackTrace | 获取当前的堆栈跟踪信息。 |
![]() ![]() |
SystemDirectory | 获取系统目录的完全限定路径。 |
![]() ![]() |
SystemPageSize | 获取中的字节数操作系统的内存页的。 |
![]() ![]() ![]() ![]() ![]() |
TickCount | 获取系统启动后经过的毫秒数。 |
![]() ![]() |
UserDomainName | 获取与当前用户关联的网络域名。 |
![]() ![]() |
UserInteractive | 获取一个值,用以指示当前进程是否在用户交互模式中运行。 |
![]() ![]() |
UserName | 获取当前已登录到 Windows 操作系统的人员的用户名。 |
![]() ![]() ![]() |
Version | 获取一个 Version 对象,该对象描述公共语言运行时的主版本、次版本、内部版本和修订号。 |
![]() ![]() |
WorkingSet | 获取映射到进程上下文的物理内存量。 |
方法
| 名称 | 说明 | |
|---|---|---|
![]() ![]() |
Exit | 终止此进程并为基础操作系统提供指定的退出代码。 |
![]() ![]() |
ExpandEnvironmentVariables | 将嵌入到指定字符串中的每个环境变量的名称替换为该变量的值的等效字符串,然后返回结果字符串。 |
![]() ![]() ![]() |
FailFast(String) | 向 Windows 的应用程序事件日志写入消息后立即终止进程,然后在发往 Microsoft 的错误报告中加入该消息。 |
![]() ![]() ![]() |
FailFast(String, Exception) | 向 Windows 的应用程序事件日志写入消息后立即终止进程,然后在发往 Microsoft 的错误报告中加入该消息和异常信息。 |
![]() ![]() |
GetCommandLineArgs | 返回包含当前进程的命令行参数的字符串数组。 |
![]() ![]() |
GetEnvironmentVariable(String) | 从当前进程检索环境变量的值。 |
![]() ![]() |
GetEnvironmentVariable(String, EnvironmentVariableTarget) | 从当前进程或者从当前用户或本地计算机的 Windows 操作系统注册表项检索环境变量的值。 |
![]() ![]() |
GetEnvironmentVariables() | 从当前进程检索所有环境变量名及其值。 |
![]() ![]() |
GetEnvironmentVariables(EnvironmentVariableTarget) | 从当前进程或者从当前用户或本地计算机的 Windows 操作系统注册表项检索所有环境变量名及其值。 |
![]() ![]() ![]() |
GetFolderPath(Environment.SpecialFolder) | 获取由指定枚举标识的系统特殊文件夹的路径。 |
![]() ![]() |
GetFolderPath(Environment.SpecialFolder, Environment.SpecialFolderOption) | 获取由指定枚举标识的系统特殊文件夹的路径,并使用用于访问特殊文件夹的指定选项。 |
![]() ![]() |
GetLogicalDrives | 返回包含当前计算机中的逻辑驱动器名称的字符串数组。 |
![]() ![]() |
SetEnvironmentVariable(String, String) | 创建、修改或删除当前进程中存储的环境变量。 |
![]() ![]() |
SetEnvironmentVariable(String, String, EnvironmentVariableTarget) | 创建、修改或删除当前进程中或者为当前用户或本地计算机保留的 Windows 操作系统注册表项中存储的环境变量。 |



浙公网安备 33010602011771号