Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to create a user privileged exe that detect the formatting of USB device and inform that the device is starts formatting and when it completed it shows a message formatting is completed.

What I have tried:

created a c++ console application with the below example code.
but it need admin privilage.

C++
#include "stdafx.h"
#include <fstream>
#include <windows.h>
#include <iostream>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
	char *Fpath="D:\\$Extend\\$RmMetadata\\$TxfLog\\$TxfLog.blf";
	std::ifstream is;
	while(true)
	{
		is.open(Fpath);
		if(is.is_open())
		{
			std::cout<<"Waiting for format\n";
			is.close();
		}
		else
		{
			std::cout<<"formating device\n";
		}
		Sleep(1000);
	}
	getchar();
	return 0;
}
Posted
Updated 8-Jun-16 21:58pm
v2
Comments
Richard MacCutchan 9-Jun-16 3:29am    
You need to add the requested access level to your project settings or manifest.

1 solution

I got the solution

C++
#include "stdafx.h"
#include <fstream>
#include <windows.h>
#include <iostream>
#include <stdio.h>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	while(true)
	{
		WIN32_FIND_DATA data;
		HANDLE h = FindFirstFile(L"D:\\*.*",&data); \\ Specify the drive letter

		if( h!=INVALID_HANDLE_VALUE ) 
		{
			cout << "Waiting\n";
		} 
		else 
			cout << "Formatting\n";
		FindClose(h);
		Sleep(1000);
	}
	getchar();
	return 0;
}
 
Share this answer
 
Comments
Richard MacCutchan 9-Jun-16 4:09am    
How do you know it's formatting, rather than some other reason for the failure?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900