前台
<asp:Button ID="button1" runat="server" OnClick="button1_Click1" Text="检测磁盘空间" />
后台
[DllImport("kernel32.dll ", EntryPoint = "GetDiskFreeSpaceExA")]
public static extern int GetDiskFreeSpaceEx(string lpRootPathName, out long lpFreeBytesAvailable, out long lpTotalNumberOfBytes, out long lpTotalNumberOfFreeBytes);
protected void button1_Click1(object sender, EventArgs e)
{
long a, b, c;
GetDiskFreeSpaceEx("C:\\ ", out a, out b, out c);
long all =Convert.ToInt64(long.Parse(a.ToString()).ToString()) / 1024 / 1024 / 1024;
Response.Write("<script>alert('C盘剩余" + all + "G');</script>");
这样能查看本地的磁盘空间 现在我想查看其他机器的磁盘空间(查看服务器的,有访问权限)
有大神告诉下吗。。灰常谢谢!!!!!!!!
<asp:Button ID="button1" runat="server" OnClick="button1_Click1" Text="检测磁盘空间" />
后台
[DllImport("kernel32.dll ", EntryPoint = "GetDiskFreeSpaceExA")]
public static extern int GetDiskFreeSpaceEx(string lpRootPathName, out long lpFreeBytesAvailable, out long lpTotalNumberOfBytes, out long lpTotalNumberOfFreeBytes);
protected void button1_Click1(object sender, EventArgs e)
{
long a, b, c;
GetDiskFreeSpaceEx("C:\\ ", out a, out b, out c);
long all =Convert.ToInt64(long.Parse(a.ToString()).ToString()) / 1024 / 1024 / 1024;
Response.Write("<script>alert('C盘剩余" + all + "G');</script>");
这样能查看本地的磁盘空间 现在我想查看其他机器的磁盘空间(查看服务器的,有访问权限)
有大神告诉下吗。。灰常谢谢!!!!!!!!
我最近刚做完,需要用户名密码和远程机器名称
options.Username = UserName;
options.Password = Password;
options.Authority = "ntlmdomain:FAREAST";
ManagementScope scope = new ManagementScope(@"\\" + machinename + @"\root\cimv2", options);
scope.Connect();
ObjectQuery query = new ObjectQuery("select * from Win32_LogicalDisk");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query); ManagementObjectCollection queryCollection = searcher.Get(); foreach (ManagementObject nic in queryCollection)
{
foreach (PropertyData property in nic.Properties)
Console.WriteLine(property.Name + "\t\t" + property.Value);
}
options.Authority = "ntlmdomain:"+域名;
System.Management并引用命名空间,
using System.Management;
protected void Button1_Click(object sender, EventArgs e)
{
long mb = 1048576;
//1024x1024
//设定生成的WMI所需的所有设置
ConnectionOptions Conn = new ConnectionOptions();
//设定用于WMI连接操作的用户名
Conn.Username = "用户名";
//设定用户的口令
Conn.Password = "密码";
//设定用于执行WMI操作的范围
ManagementScope Ms = new ManagementScope("\\\\10.27.1.158\\root\\cimv2", Conn);
try
{
//连接到实际操作的WMI范围
Ms.Connect();
//设定通过WMI要查询的内容
ObjectQuery Query = new ObjectQuery("select FreeSpace ,Size ,Name from Win32_LogicalDisk where DriveType=3");
//WQL语句,设定的WMI查询内容和WMI的操作范围,检索WMI对象集合
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Ms, Query);
//异步调用WMI查询
ManagementObjectCollection ReturnCollection = Searcher.Get();
double free = 0;
double use = 0;
double total = 0;
Listbox1.Items.Clear();
//通过对产生的WMI的实例集合进行检索,获得硬盘信息
foreach (ManagementObject Return in ReturnCollection)
{
Listbox1.Items.Add("磁盘名称:" + Return["Name"].ToString());
//获得硬盘的可用空间
free = Convert.ToInt64(Return["FreeSpace"]) / mb;
//获得硬盘的已用空间
use = (Convert.ToInt64(Return["Size"]) - Convert.ToInt64(Return["FreeSpace"])) / mb;
//获得硬盘的合计空间
total = Convert.ToInt64(Return["Size"]) / mb;
Listbox1.Items.Add(" 总计:" + total.ToString() + "MB");
Listbox1.Items.Add("已用空间:" + use.ToString() + "MB");
Listbox1.Items.Add("可用空间:" + free.ToString() + "MB");
}
}
catch (Exception ee)
{
Response.Write("连接10.27.1.158出错,出错信息为:" + ee.Message);
}
}
解决问题,请给分
Conn.Username = "对方计算机用户名";
Conn.Password = "密码";楼主,如解决问题,请给分!
字符串写跟要查询的地址??
字符串写啥,IP 也不变啊? 没IP 怎么查啊
ManagementScope Ms = new ManagementScope("\\\\10.27.1.158\\root\\cimv2", Conn);
字符串写跟要查询的地址??
ConnectionOptions Conn = new ConnectionOptions();
字符串写跟要查询的地址??