使用C 來清除系統環境變數中無效的路徑

2021-06-09 11:56:13 字數 1654 閱讀 5597

主要使用到envrionment類的設定和獲取環境變數的方法,見具體的**吧。

//	file name:	cleanenvironmentvariables.cs

// author: peng qianhe

// date: 2012.9.13

using system;

using system.collections;

using system.collections.generic;

using system.io;

namespace qhcsharp

}if( !path.contains(":") )

return true;

} private static void cleanspecifiedvariables(environmentvariabletarget target)] ......",target,de.key);

string dirs = de.value.tostring().split(';');

string newvalue = string.empty;

foreach(string dir in dirs) is not exist.",dir);

}else is not exist.",dir);

}else

}}else

}else is not a valid path.",dir);

newvalue += dir+ (dirs.length>1?";":"");}}

}console.setcursorposition(60,console.cursortop);

// console.writeline(" = ",de.key,newvalue);

if(newvalue != string.empty)else = ",de.key,newvalue);

needprocess.add(de.key.tostring(),newvalue);

}}else

}// user decided to process or not

if(needprocess.count > 1) = ",d.key,d.value);}}

}else

}catch(exception e)

} public static void main(string args)

} }}

效果圖:

但是,有乙個問題是,設定process中的環境變數的時候,沒有效果。不清楚是為什麼了。

[原]wmicodecreator:c#產生wmi**的工具

[原]getalpha:c#實現獲取網頁驗證碼,並識別出其中的字母

[原]geticons:c#提取應用程式的圖示資源

[原]cls_ini.cls:vb寫的操作ini配置檔案的類

[譯]用c#檢測你的印表機是否連線

[原]hotkey.cs:為應用程式新增熱鍵

[原]pjconvertimageformat:用freeimage.net寫的乙個35種影象格式轉換程式

[譯]用c#檢測你的印表機是否連線

C 中如何獲取系統環境變數等

c 中獲取系統環境變數需要用到environment 類。其中提供了有關當前環境和平台的資訊以及操作它們的方法。該類不能被繼承 以下 得到 systemdrive 的值,即 c string spath environment.getenvironmentvariable systemdrive c...

在uboot裡面加入環境變數使用run來執行

author 楊正date 2014.11.11 email yz2012ww gmail.com 在移植uboot的時候,能夠在uboot裡面加入定義一些自己的環境變數,這些環境變數能夠大大提高以後的工作效率,比方我在uboot裡面加入例如以下環境變數 bbl sf probe 0 mw.b 82...

C 實現設定系統環境變數設定

以前實現系統環境變數設定時是要在電腦屬性 高階 環境變數設定,實現方式主要有2種,修改登錄檔,新增環境變數 呼叫系統kernel32.dll函式,設定環境變數 登錄檔方式,是要修改登錄檔的位置是 hkey local machine system currentcontrolset control ...