G
Guest
I am trying to use the below to return different values of an int variable,
but I seem to be running into scope issues as I cannot use the iSize variable
outside of the foreach block. Any help is appreciated.
public int CalcDiskSpace(string strComputer)
{
ManagementScope oMS = new ManagementScope("\\\\" + strComputer);
ObjectQuery oQuery = new ObjectQuery("Select Size From
Win32_DiskDrive");
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMS, oQuery);
ManagementObjectCollection colSearch = oSearcher.Get();
foreach ( ManagementObject oReturn in colSearch )
{
if ( (System.Int32.Parse(oReturn.ToString())/100) < 1048576 )
{
int iSize = 1048576;
}
if ((System.Int32.Parse(oReturn.ToString()) / 100) > 4194304)
{
int iSize = 4194304;
}
else
{
int iSize = System.Int32.Parse(oReturn.ToString());
}
}
int iBytes = iSize + (iSize / 803);
DirectoryInfo odirInfo = new DirectoryInfo(@"c:\");
int iFolders =
Int32.Parse(odirInfo.GetFileSystemInfos().Length.ToString()) * 1280;
int NeededSize = 196096 + iFolders + iBytes;
}
but I seem to be running into scope issues as I cannot use the iSize variable
outside of the foreach block. Any help is appreciated.
public int CalcDiskSpace(string strComputer)
{
ManagementScope oMS = new ManagementScope("\\\\" + strComputer);
ObjectQuery oQuery = new ObjectQuery("Select Size From
Win32_DiskDrive");
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMS, oQuery);
ManagementObjectCollection colSearch = oSearcher.Get();
foreach ( ManagementObject oReturn in colSearch )
{
if ( (System.Int32.Parse(oReturn.ToString())/100) < 1048576 )
{
int iSize = 1048576;
}
if ((System.Int32.Parse(oReturn.ToString()) / 100) > 4194304)
{
int iSize = 4194304;
}
else
{
int iSize = System.Int32.Parse(oReturn.ToString());
}
}
int iBytes = iSize + (iSize / 803);
DirectoryInfo odirInfo = new DirectoryInfo(@"c:\");
int iFolders =
Int32.Parse(odirInfo.GetFileSystemInfos().Length.ToString()) * 1280;
int NeededSize = 196096 + iFolders + iBytes;
}