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(s tring strComputer)
{
ManagementScope oMS = new ManagementScope ("\\\\" + strComputer);
ObjectQuery oQuery = new ObjectQuery("Se lect Size From
Win32_DiskDrive ");
ManagementObjec tSearcher oSearcher = new
ManagementObjec tSearcher(oMS, oQuery);
ManagementObjec tCollection colSearch = oSearcher.Get() ;
foreach ( ManagementObjec t oReturn in colSearch )
{
if ( (System.Int32.P arse(oReturn.To String())/100) < 1048576 )
{
int iSize = 1048576;
}
if ((System.Int32. Parse(oReturn.T oString()) / 100) > 4194304)
{
int iSize = 4194304;
}
else
{
int iSize = System.Int32.Pa rse(oReturn.ToS tring());
}
}
int iBytes = iSize + (iSize / 803);
DirectoryInfo odirInfo = new DirectoryInfo(@ "c:\");
int iFolders =
Int32.Parse(odi rInfo.GetFileSy stemInfos().Len gth.ToString()) * 1280;
int NeededSize = 196096 + iFolders + iBytes;
}