Thread: Qt5/C++ - QRrocess and DISKPART.exe

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    56

    Qt5/C++ - QRrocess and DISKPART.exe

    Qt5 - Windows 10

    Hello,

    I'm using QProcess to run DISKPART to create a 1.5gig FAT32 partition on an SD card.
    The problem I have is that I have to run QProcess twice for it work.
    If I run it once, the SD card ends up empty and unformatted.
    It seems I have an error in QProcess or the DISKPART script,
    maybe some time delays?.
    Any ideas, please?

    Regards
    Code:
    QString program = "diskpart.exe";
    QStringList arguments;
    arguments << "/s" << filename;
    
    for (int i = 0; i < 2; i++)
    {
        process = new QProcess(this);
        process->start(program, arguments);
    
        process->waitForStarted(-1);
        process->waitForFinished(-1);
        process->terminate();
        process->close();
        process->deleteLater();
    }
    Code:
    filename (script):-
    
    select disk 1
    clean
    create partition primary size=1536
    active
    format fs=fat32 label=Noobs quick

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Does running diskpart.exe /s filename from a command line shell actually work first time?

    See also this gotcha in the QProcess manual page.
    Windows: The arguments are quoted and joined into a command line that is compatible with the CommandLineToArgvW() Windows function. For programs that have different command line quoting requirements, you need to use setNativeArguments(). One notable program that does not follow the CommandLineToArgvW() rules is cmd.exe and, by consequence, all batch scripts.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    56
    Hello,

    Thanks for your reply.
    Does running diskpart.exe /s filename from a command line shell actually work first time?
    Every time, using an Administrator command prompt, and I'm running the program as Administrator.

    Regards

  4. #4
    Registered User
    Join Date
    May 2015
    Posts
    56
    Hello,

    This morning its showing an error.
    I'm going to buy some new SD Cards, just in case its a faulty card.

    Regards

    Its possible this is a solution:-
    If you get an error at CLEAN simply ensure you don't have file explorer or control panel open and try again.
    Code:
    H:\Qt\myProgDir>diskpart /s wipeSD.txt
    
    Microsoft DiskPart version 10.0.10586
    
    Copyright (C) 1999-2013 Microsoft Corporation.
    On computer: WIN10
    
    Disk 1 is now the selected disk.
    
    DiskPart has encountered an error: Access is denied.
    See the System Event Log for more information.
    
    H:\Qt\myProgDir>
    Code:
    EventLog:-
    Log Name:      System
    Source:        VDS Basic Provider
    Date:          15/08/2016 09:07:01
    Event ID:      5
    Task Category: None
    Level:         Error
    Keywords:      Classic
    User:          N/A
    Computer:      Win10
    Description:
    Cannot zero sectors on disk \\?\PhysicalDrive1. Error code: 5@0101000F
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="VDS Basic Provider" />
        <EventID Qualifiers="49664">5</EventID>
        <Level>2</Level>
        <Task>0</Task>
        <Keywords>0x80000000000000</Keywords>
        <TimeCreated SystemTime="2016-08-15T08:07:01.759152200Z" />
        <EventRecordID>17325</EventRecordID>
        <Channel>System</Channel>
        <Computer>Win10</Computer>
        <Security />
      </System>
      <EventData>
        <Data>\\?\PhysicalDrive1</Data>
        <Data>5@0101000F</Data>
      </EventData>
    </Event>
    Last edited by mad-hatter; 08-15-2016 at 02:53 AM.

Popular pages Recent additions subscribe to a feed

Tags for this Thread