Open USB Pendrive from Desktop

ravi varma

Club Cricketer
Joined
Mar 17, 2008
Location
Usa/newyork
Online Cricket Games Owned
This is the application which i have scripted. this is lahiru software C 2009
It contain source and released application and the way to function it. this is C++ source code.

Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.



To open a USB drive connected to your Windows installed computer, you have to go to My Computer. But, with this simple program, you can do it from your desktop. Also,if there are multiple USB drives connected, it will give a window to choose the drive you need to open. Also,if you double click a pen drive icon in My Computer, there is a risk that the viruses that may be in the pen drive will infect your computer by auto running. But, there is no such risk when you use this program.

Here is the Source code:-
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
driveselectdlg dlg;
CString driveletter;
POSITION pos;
LPWSTR lable=new WCHAR[50];
UINT drivetype;
DWORD logicaldrives, devider;
logicaldrives=GetLogicalDrives();
devider=8;
for(int i=0; i<10; i++)
{
driveletter=finddrive(devider);
devider*=2;
drivetype=GetDriveType(driveletter);
if(drivetype==DRIVE_REMOVABLE)
{
dlg.drivelist.AddTail(driveletter);
GetVolumeInformation(driveletter, lable, 50, NULL, NULL, NULL, NULL, 0);
dlg.lablelist.AddTail(lable);
}
}
if(dlg.lablelist.GetSize()==0)
{
::MessageBox(0, TEXT("No pen drive detected!"), TEXT("Message"), 0);
return 0;
}
if(dlg.lablelist.GetSize()==1)
{
pos=dlg.drivelist.GetHeadPosition();
ShellExecute(NULL,TEXT("open"), dlg.drivelist.GetNext(pos), NULL, NULL, SW_SHOWMAXIMIZED);
return 0;
}
if(dlg.DoModal()==IDOK)
{
pos=dlg.drivelist.GetHeadPosition();
for(int i=0; i<(dlg.selection-1); i++)
{
dlg.drivelist.GetNext(pos);
}
ShellExecute(NULL,TEXT("open"), dlg.drivelist.GetNext(pos), NULL, NULL, SW_SHOWMAXIMIZED);
}
return 0;
}

NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.


For more: www.planet-source-code.com

Just Thanks and reputation
 

Attachments

  • source-code (lahiru C 2009).zip
    118.6 KB · Views: 4
Last edited:

omkarjere

International Cricketer
Joined
Jan 11, 2007
Online Cricket Games Owned
Don't mind me but you don't need to script for opening your Pen Drive from your desktop just create its shortcut on the desktop then double-click to open(just like any other app :p) whenever you attach the pen drive you can double click the shortcut and it will open :)

And BTW don't join ARENA Multimedia I m having a terrible experience :p
 

Users who are viewing this thread

Top