Click here to Skip to main content
15,894,720 members
Home / Discussions / C#
   

C#

 
GeneralRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
Richard MacCutchan19-Jan-24 22:30
mveRichard MacCutchan19-Jan-24 22:30 
GeneralRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
Jens Eckervogt19-Jan-24 23:52
Jens Eckervogt19-Jan-24 23:52 
GeneralRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
Richard MacCutchan20-Jan-24 0:18
mveRichard MacCutchan20-Jan-24 0:18 
GeneralRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
Jens Eckervogt20-Jan-24 5:31
Jens Eckervogt20-Jan-24 5:31 
GeneralRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
Dave Kreskowiak20-Jan-24 4:52
mveDave Kreskowiak20-Jan-24 4:52 
AnswerRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
Gerry Schmitz19-Jan-24 16:41
mveGerry Schmitz19-Jan-24 16:41 
AnswerRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
jschell22-Jan-24 5:34
jschell22-Jan-24 5:34 
GeneralRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
Jens Eckervogt22-Jan-24 14:17
Jens Eckervogt22-Jan-24 14:17 
SuggestionRe: Question about (char* from string) ,(string from char*) and (char* to char) Pin
Richard Deeming29-Jan-24 3:56
mveRichard Deeming29-Jan-24 3:56 
QuestionHow to customize the default .Net Framework Validation Error Messages Pin
Fokwa Divine11-Jan-24 3:30
Fokwa Divine11-Jan-24 3:30 
AnswerRe: How to customize the default .Net Framework Validation Error Messages Pin
Pete O'Hanlon11-Jan-24 3:46
mvePete O'Hanlon11-Jan-24 3:46 
GeneralRe: How to customize the default .Net Framework Validation Error Messages Pin
Fokwa Divine11-Jan-24 4:17
Fokwa Divine11-Jan-24 4:17 
GeneralRe: How to customize the default .Net Framework Validation Error Messages Pin
Pete O'Hanlon11-Jan-24 18:56
mvePete O'Hanlon11-Jan-24 18:56 
Questiondisplay only first 10 files from each directory Pin
picasso29-Jan-24 11:59
picasso29-Jan-24 11:59 
AnswerRe: display only first 10 files from each directory Pin
jschell9-Jan-24 12:39
jschell9-Jan-24 12:39 
AnswerRe: display only first 10 files from each directory Pin
OriginalGriff9-Jan-24 19:54
mveOriginalGriff9-Jan-24 19:54 
AnswerRe: display only first 10 files from each directory Pin
Richard Deeming9-Jan-24 23:44
mveRichard Deeming9-Jan-24 23:44 
GeneralRe: display only first 10 files from each directory Pin
OriginalGriff10-Jan-24 23:27
mveOriginalGriff10-Jan-24 23:27 
GeneralRe: display only first 10 files from each directory Pin
Richard Deeming11-Jan-24 0:45
mveRichard Deeming11-Jan-24 0:45 
QuestionCompatibity Pin
PedroSini9-Jan-24 5:06
PedroSini9-Jan-24 5:06 
AnswerRe: Compatibity Pin
Pete O'Hanlon9-Jan-24 5:15
mvePete O'Hanlon9-Jan-24 5:15 
QuestionGet List Of Physical & Logical Drives Pin
Kevin Marois4-Jan-24 22:15
professionalKevin Marois4-Jan-24 22:15 
I'm trying to load a list of drives. If you went to Windows Explorer and clicked on This PC, you would see all of the drives and devices available to you, physically installed, USB, and phones/tablets. This is the list I want

In addition to my C: hard drive, I have a Lenovo tablet, my Samsung S22 Ultra phone, a USB DVD drive, Seagate USB HDD all plugged in.

So, first I use this to get the HD and DVD drives:
var allDrives = DriveInfo.GetDrives();

First Problem
This gives me the drives, but for the DVD drives the DriveType is showing as 'CDRom'.

Second Problem
I want to get tablets and phones that are plugged in. I found this[^], which works well, with one small problem. Based on that I wrote this bit of code that writes out some of the drive meta data:

I get the ClassId from here[^]. Maybe my class Id is wrong??
public static List GetUSBDevices()
{
    var file = @"c:\projects\usbinfo.csv";
    if (File.Exists(file))
    {
        File.Delete(file);
    }

    var devices = new List();

    ManagementObjectCollection collection;
    using (var searcher = new ManagementObjectSearcher("Select * From Win32_PnPEntity"))
    {
        collection = searcher.Get();
    }

    using (var sw = new StreamWriter(file, true))
    {
        var line = "";

        var keys = new string[]
        {
            "Name",
            "Description",
            "Caption",
            "ClassGuid",
        };

        // Write out header line
        foreach (var key in keys)
        {
            line += $"{key},";
        }
        sw.WriteLine(line);
        line = "";

        foreach (var device in collection)
        {
            var name = (string)device.GetPropertyValue("Name");
            var classGuid = (string)device.GetPropertyValue("ClassGuid");

            if (classGuid == "{eec5ad98-8080-425f-922a-dabf3de3f69a}")
            {
                foreach (var key in keys)
                {
                    try
                    {
                        line += $"{(string)device.GetPropertyValue(key)},";
                    }
                    catch { }
                }
                sw.WriteLine(line);
                line = "";
            }
        }
    }

    collection.Dispose();
    return devices;
}
That produced this
Name,Description,Caption,ClassGuid
One Touch,One Touch HDD   ,One Touch,{eec5ad98-8080-425f-922a-dabf3de3f69a}
E:\,STORAGE DEVICE  ,E:\,{eec5ad98-8080-425f-922a-dabf3de3f69a}
Galaxy S22 Ultra,SM-S908U,Galaxy S22 Ultra,{eec5ad98-8080-425f-922a-dabf3de3f69a}
Lenovo Tab M10,Lenovo TB-X505F,Lenovo Tab M10,{eec5ad98-8080-425f-922a-dabf3de3f69a}
Note the last two, the Galaxy S22 Ultra and Lenovo Tab M10 - these I want. The first two are HDD's, which I already have from GetDriveInfo().

So, to recap
1. With GetDriveInfo, how do I know if a drive that says CDRom is really a DVDRom?
2. Is there some way to get just the tablets & phones?

I'm open to a better way of someone has one.

Thanks!
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.

AnswerRe: Get List Of Physical & Logical Drives Pin
Richard Deeming4-Jan-24 22:50
mveRichard Deeming4-Jan-24 22:50 
GeneralRe: Get List Of Physical & Logical Drives Pin
Kevin Marois5-Jan-24 7:32
professionalKevin Marois5-Jan-24 7:32 
QuestionI need to convert a string to a float.... Pin
glennPattonWork33-Jan-24 2:15
professionalglennPattonWork33-Jan-24 2:15 

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.