Click here to Skip to main content
12,064,498 members (62,701 online)
   

C#

 
GeneralRe: C# and SQL Part 2: Attack of the "Login Failed For (thiscomputer)/Guest"! Pin
Mika Wendelius26-Jan-09 19:24
mvpMika Wendelius26-Jan-09 19:24 
GeneralRe: C# and SQL Part 2: Attack of the "Login Failed For (thiscomputer)/Guest"! Pin
Michael Fritzius1-Feb-09 13:41
memberMichael Fritzius1-Feb-09 13:41 
GeneralRe: C# and SQL Part 2: Attack of the "Login Failed For (thiscomputer)/Guest"! Pin
Mika Wendelius2-Feb-09 7:25
mvpMika Wendelius2-Feb-09 7:25 
GeneralRe: C# and SQL Part 2: Attack of the "Login Failed For (thiscomputer)/Guest"! Pin
Michael Fritzius2-Feb-09 16:30
memberMichael Fritzius2-Feb-09 16:30 
QuestionMessengerAPI Pin
shopi3026-Jan-09 11:12
membershopi3026-Jan-09 11:12 
AnswerRe: MessengerAPI Pin
Xmen 26-Jan-09 14:58
member Xmen 26-Jan-09 14:58 
Questionapplicationsecurityinfo class Pin
bolly-8126-Jan-09 10:53
memberbolly-8126-Jan-09 10:53 
AnswerRe: applicationsecurityinfo class Pin
crudeCodeYogi26-Jan-09 11:19
membercrudeCodeYogi26-Jan-09 11:19 
QuestionImpersonation With Md5 Pin
asafbs200426-Jan-09 10:25
memberasafbs200426-Jan-09 10:25 
AnswerRe: Impersonation With Md5 Pin
Computafreak26-Jan-09 11:00
memberComputafreak26-Jan-09 11:00 
AnswerRe: Impersonation With Md5 Pin
Dave Kreskowiak26-Jan-09 17:09
mvpDave Kreskowiak26-Jan-09 17:09 
Questionthe result of DefragAnalysis method in c# Pin
SAKRA26-Jan-09 8:06
memberSAKRA26-Jan-09 8:06 
AnswerRe: the result of DefragAnalysis method in c# Pin
musefan26-Jan-09 8:25
membermusefan26-Jan-09 8:25 
AnswerRe: the result of DefragAnalysis method in c# Pin
ChunkyStool28-Jan-09 20:00
memberChunkyStool28-Jan-09 20:00 
Yeah, there's not much C# sample code for WMI anywhere -- including MSDN. That really sucks because WMI isn't very intuitive. I tested WMI for 8+ years and still struggle with some features... WTF | :WTF:
The DefragAnalysis method returns 3 things: return code (which you got), a bool that indicates whether or not a defrag is recommended, and an instance of Win32_DefragAnalysis. The bool & instance get "wrapped" in an object array. All you have to do is tell the method where to put the objects. Think of the "outParams" array as a mailbox with 2 slots. Null values are fine.
Here's some sample code. (Note, it isn't necessary to specify scope for Vista or Server 2008 because the defaults are local machine & “root\cimv2”. I only included it for backward compatibility.)
using System;
using System.Management;
 
namespace DefragAnalysis
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string scope = @"\\.\root\cimv2";
                string query = @"SELECT * FROM Win32_Volume WHERE Name = 'C:\\'";
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
                object[] outputArgs = new object[2];
 
                foreach (ManagementObject volume in searcher.Get())
                {
                    UInt32 result = (UInt32)volume.InvokeMethod("DefragAnalysis", outputArgs);
 
                    if (result == 0)
                    {
                        Console.WriteLine("Defrag Needed = {0}\n", outputArgs[0]);
                        ManagementBaseObject defragAnalysis = outputArgs[1] as ManagementBaseObject;
 
                        if (null != defragAnalysis)
                        {
                            foreach (PropertyData property in defragAnalysis.Properties)
                            {
                                Console.WriteLine("{0} = {1}", property.Name, property.Value);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Method return code = 0x{0:X}", result);
                    }
                }
            }
 
            catch (Exception ex)
            {
                Console.WriteLine("Something bad happened.\n" + ex);
            }
 
            finally
            {
                Console.WriteLine("\npress any key to exit...");
                Console.ReadKey();
            }
        }
    }
}
OUTPUT:
Defrag Needed = False

AverageFileSize = 210971
AverageFragmentsPerFile = 1.01
AverageFreeSpacePerExtent = 1486924
ClusterSize = 4096
ExcessFolderFragments = 2
FilePercentFragmentation = 0
FragmentedFolders = 2
FreeSpace = 51929346048
FreeSpacePercent = 43
FreeSpacePercentFragmentation = 30
LargestFreeSpaceExtent = 23083888640
MFTPercentInUse = 72
MFTRecordCount = 286135
PageFileSize = 0
TotalExcessFragments = 2833
TotalFiles = 250258
TotalFolders = 35176
TotalFragmentedFiles = 876
TotalFreeSpaceExtents = 34924
TotalMFTFragments = 3
TotalMFTSize = 403636224
TotalPageFileFragments = 0
TotalPercentFragmentation = 15
TotalUnmovableFiles = 149
UsedSpace = 66455265280
VolumeName =
VolumeSize = 118384611328

press any key to exit...
QuestionC# Threading help!! cant seem to get going.... Pin
alexleslie26-Jan-09 7:07
memberalexleslie26-Jan-09 7:07 
AnswerRe: C# Threading help!! cant seem to get going.... Pin
EliottA26-Jan-09 7:23
memberEliottA26-Jan-09 7:23 
AnswerRe: C# Threading help!! cant seem to get going.... Pin
Giorgi Dalakishvili26-Jan-09 7:24
mvpGiorgi Dalakishvili26-Jan-09 7:24 
GeneralRe: C# Threading help!! cant seem to get going.... Pin
EliottA26-Jan-09 7:27
memberEliottA26-Jan-09 7:27 
AnswerRe: C# Threading help!! cant seem to get going.... Pin
John Simmons / outlaw programmer26-Jan-09 12:26
mvpJohn Simmons / outlaw programmer26-Jan-09 12:26 
QuestionDifficulty communicating with capture Device Pin
Alex_xso26-Jan-09 6:41
memberAlex_xso26-Jan-09 6:41 
AnswerCP: repeat post for like 3 times now. Pin
EliottA26-Jan-09 6:54
memberEliottA26-Jan-09 6:54 
Questionswitch off computer Pin
likefood26-Jan-09 6:39
memberlikefood26-Jan-09 6:39 
AnswerRe: switch off computer Pin
EliottA26-Jan-09 6:55
memberEliottA26-Jan-09 6:55 
GeneralRe: switch off computer Pin
Greeeg26-Jan-09 7:00
memberGreeeg26-Jan-09 7:00 
GeneralRe: switch off computer Pin
likefood26-Jan-09 7:35
memberlikefood26-Jan-09 7:35 
GeneralRe: switch off computer Pin
likefood26-Jan-09 7:35
memberlikefood26-Jan-09 7:35 
AnswerRe: switch off computer Pin
Giorgi Dalakishvili26-Jan-09 7:10
mvpGiorgi Dalakishvili26-Jan-09 7:10 
GeneralRe: switch off computer Pin
likefood26-Jan-09 7:36
memberlikefood26-Jan-09 7:36 
QuestionRe: switch off computer Pin
likefood26-Jan-09 9:16
memberlikefood26-Jan-09 9:16 
AnswerRe: switch off computer Pin
likefood26-Jan-09 9:25
memberlikefood26-Jan-09 9:25 
AnswerRe: switch off computer Pin
Xmen 26-Jan-09 15:03
member Xmen 26-Jan-09 15:03 
GeneralRe: switch off computer Pin
likefood27-Jan-09 16:58
memberlikefood27-Jan-09 16:58 
QuestionLinq to SQL question Pin
pprice26-Jan-09 6:21
memberpprice26-Jan-09 6:21 
AnswerRe: Linq to SQL question Pin
Mika Wendelius26-Jan-09 10:00
mvpMika Wendelius26-Jan-09 10:00 
QuestionHow to have access the drivers and API? Pin
Alex_xso26-Jan-09 6:16
memberAlex_xso26-Jan-09 6:16 
AnswerRe: How to have access the drivers and API? Pin
EliottA26-Jan-09 6:32
memberEliottA26-Jan-09 6:32 
GeneralRe: How to have access the drivers and API? Pin
Mantrata26-Jan-09 6:45
memberMantrata26-Jan-09 6:45 
QuestionEmpty cell in gridview Pin
Raskelmos26-Jan-09 5:51
memberRaskelmos26-Jan-09 5:51 
AnswerRe: Empty cell in gridview Pin
Jim (SS)26-Jan-09 12:35
memberJim (SS)26-Jan-09 12:35 
QuestionParsing Log Files Pin
alwaysthinking26-Jan-09 5:24
memberalwaysthinking26-Jan-09 5:24 
AnswerRe: Parsing Log Files Pin
Manas Bhardwaj26-Jan-09 5:29
memberManas Bhardwaj26-Jan-09 5:29 
AnswerRe: Parsing Log Files Pin
Mustafa Ismail Mustafa26-Jan-09 5:41
memberMustafa Ismail Mustafa26-Jan-09 5:41 
GeneralRe: Parsing Log Files Pin
alwaysthinking26-Jan-09 5:59
memberalwaysthinking26-Jan-09 5:59 
GeneralRe: Parsing Log Files Pin
Mark Churchill26-Jan-09 15:44
memberMark Churchill26-Jan-09 15:44 
GeneralRe: Parsing Log Files Pin
Mustafa Ismail Mustafa27-Jan-09 0:49
memberMustafa Ismail Mustafa27-Jan-09 0:49 
Question[Message Deleted] Pin
myventsi26-Jan-09 4:34
membermyventsi26-Jan-09 4:34 
AnswerRe: CopyFromScreen() question. Pin
PIEBALDconsult26-Jan-09 6:20
memberPIEBALDconsult26-Jan-09 6:20 
General[Message Deleted] Pin
myventsi26-Jan-09 7:50
membermyventsi26-Jan-09 7:50 
GeneralRe: CopyFromScreen() question. Pin
PIEBALDconsult26-Jan-09 8:08
memberPIEBALDconsult26-Jan-09 8:08 
QuestionHow do I bounce an old thread? Pin
Butter18526-Jan-09 4:29
memberButter18526-Jan-09 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.160204.4 | Last Updated 6 Feb 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid