Because the company has multiple servers, to check the use of the disk to determine which server the program to put and clean the garbage, so write a small program to help check.
Effect Chart:
Background code:
private void btnCheck_Click (object sender, EventArgs e) {listBox1.Items.Clear (); if (rbtnremote.checked) {//Remote Remotedi
SK ();
else {//local localdisk ();}}
View local private void Localdisk () {wqlobjectquery wmiquery = new Wqlobjectquery ("SELECT * from Win32_LogicalDisk");
ManagementObjectSearcher wmifind = new ManagementObjectSearcher (wmiquery);
Display Showinfo (wmifind); //Remote private void Remotedisk () {if (Cbip.text = = "" | Cbusername.text = "" |
Txtpwd.text = = "") {MessageBox.Show ("Please add the information complete!");
Return
string ip = cbip.text;
string username = Cbusername.text;
string password = Txtpwd.text;
ConnectionOptions conn = new connectionoptions (); Conn.
Username = Username; Conn.
Password = Password; Conn.
Timeout = new TimeSpan (1,1,1,1);//connection time//managementscope server and namespace. String path = string.
Format (@ "\\{0}\root\cimv2", IP);
Represents the scope (namespace) of an administrative operation, using the specified options to initialize a new instance of the Managementscope class that represents the specified range path.
Managementscope scope = new Managementscope (PATH, conn); Scope.
Connect (); Query string strquery = "SelecT * from Win32_LogicalDisk ";
ObjectQuery query = new ObjectQuery (strquery);
Query Managementobjectcollection Returns the result set ManagementObjectSearcher Wmifind = new ManagementObjectSearcher (scope, query);
Showinfo (Wmifind);
#region Display disk information private void Showinfo (ManagementObjectSearcher wmifind) {Long GB = 1024 * 1024 * 1024; String type = "";
String str = "";
Double Freepath = 0d; foreach (Var mobj in Wmifind. Get ()) {type = mobj["Description"].
ToString (); Determine if this is a native fixed disk if (type = = "Local Fixed disk") {str = "disk name:" + mobj["name"].
ToString ();
Freepath = Math.Round (convert.todouble (mobj["FreeSpace"))/GB, 1);
STR + + "free space:" + freepath+ "G"; str + = "Actual Size:" + Math.Round (convert.todouble (mobj["size").
ToString ())/GB, 1) + "G";
if (Freepath <) {str = "----Please clean up as soon as possible!";} listBox1.Items.Add (str);
#endregion private void Rbtnlocal_checkedchanged (object sender, EventArgs e) {//locally Select if (rbtnlocal.checked = = True) {cbip.enabled = false; cbusername.enabled = false; txtpwd.enabled = false;}
private void Rbtnremote_checkedchanged (object sender, EventArgs e) {if (rbtnremote.checked = = true) {cbip.enabled = t
Rue
Cbusername.enabled = true;
Txtpwd.enabled = true; }
}