我正在使用Directory.Exists(<path>)
来检查网络/映射驱动器当前是否已连接。我正在使用通过阅读系统注册表获得的UNC路径。
如果我通过Visual Studio运行我的代码(它告诉我该目录确实存在),这完全正常,但是,每当我运行与Windows服务完全相同的代码时它就会失败。我检查了服务的用户名和密码,这是正确的 - 一切都检查出来。
我还注意到,作为管理员运行Visual Studio时,作为普通用户运行时返回false,返回true。有没有人知道究竟发生了什么?无论我是从Visual Studio还是作为Windows服务运行,我都试图让我的程序行为相同。
答案 0 :(得分:1)
很明显,您的服务没有看到网络驱动器,
void getMonthlyBudget(fstream& budgetFile, int months)
{
MonthlyBudget mb;
int count = 1;
budgetFile.open("budget.bin", ios::out|ios::binary);
if(budgetFile.fail())
{
cout<<"Could not find file: budget.bin \n";
system("PAUSE");
}
try
{
do
{
cout<<"Enter your housing budget for month "<<count<<":\n";
cin>>mb.housing;
cout<<"Enter your utilities budget for month "<<count<<":\n";
cin>>mb.utilites;
cout<<"Enter your household expense budget for month "<<count<<":\n";
cin>>mb.houseHold;
cout<<"Enter your transportation budget for month "<<count<<":\n";
cin>>mb.transportation;
cout<<"Enter your food budget for month "<<count<<":\n";
cin>>mb.food;
cout<<"Enter your medical budget for month "<<count<<":\n";
cin>>mb.medical;
cout<<"Enter your insurance budget for month "<<count<<":\n";
cin>>mb.insurance;
cout<<"Enter your entertainment budget for month "<<count<<":\n";
cin>>mb.entertainment;
cout<<"Enter your clothing budget for month "<<count<<":\n";
cin>>mb.clothinng;
cout<<"Enter your Miscellaneous budget for month "<<count<<":\n";
cin>>mb.misc;
budgetFile.write(reinterpret_cast<char*>(&mb),sizeof(mb));
count++;
months --;
}while(months != 0);
}
catch(...)
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<"Error, invalid input entered.";
}
注意 :关于最后一个选项。设置共享权限是不够的。您需要适当地设置NTFS权限