c# windows 服务 与 桌面解决方案之间的区别

我在做服务期间遇到了两个问题如下:
double dSpace = 0;
System.Management.SelectQuery selectQuery = new System.Management.SelectQuery("select * from win32logicaldisk ");
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(selectQuery);
foreach (System.Management.ManagementObject disk in searcher.Get())
{
if (disk["Name"].ToString().Equals(DeviceID))
dSpace = System.Convert.ToDouble(disk["FreeSpace"].ToString());
}

同样的代码 服务下运行无法获取映射的可用空间大小,桌面应用没问题。

NetResource netResource = new NetResource();
netResource.dwScope = 2;
netResource.dwType = 0x1;
netResource.dwDisplayType = 3;
netResource.dwUsage = 1;
netResource.LocalName = localName;
netResource.RemoteName = remotePath;
netResource.provider = null;
int ret = WNetAddConnection2(netResource, password, userName, 0);
if (ret == 0)
return true;
return false;

同样的代码 服务下 ret为1312 桌面应用下为0

谁能给解答一下。

查看全部
dkdhn
dkdhn
2015/08/31 09:39
  • c#
  • 代码
  • window服务
  • 点赞
  • 收藏
  • 回答
    私信

2个回复