summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2003-09-17 18:59:21 +0000
committerStef Walter <stef@thewalter.net>2003-09-17 18:59:21 +0000
commit5626343771bae3ef5da6ae6e267e7e358b3626df (patch)
tree07dd927026d20f883f1c5a4ce671646644704c97
Initial ImportHEADmaster
-rw-r--r--.cvsignore5
-rw-r--r--Eject.dsp108
-rw-r--r--eject.c157
-rw-r--r--eject.dsw29
4 files changed, 299 insertions, 0 deletions
diff --git a/.cvsignore b/.cvsignore
new file mode 100644
index 0000000..099d59a
--- /dev/null
+++ b/.cvsignore
@@ -0,0 +1,5 @@
+Debug
+Release
+*.opt
+*.ncb
+*.plg \ No newline at end of file
diff --git a/Eject.dsp b/Eject.dsp
new file mode 100644
index 0000000..c0b3dea
--- /dev/null
+++ b/Eject.dsp
@@ -0,0 +1,108 @@
+# Microsoft Developer Studio Project File - Name="Eject" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=Eject - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Eject.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Eject.mak" CFG="Eject - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Eject - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "Eject - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Eject - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /opt:nowin98
+# SUBTRACT LINK32 /pdb:none
+
+!ELSEIF "$(CFG)" == "Eject - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Eject - Win32 Release"
+# Name "Eject - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\eject.c
+# SUBTRACT CPP /YX /Yc /Yu
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/eject.c b/eject.c
new file mode 100644
index 0000000..c89624a
--- /dev/null
+++ b/eject.c
@@ -0,0 +1,157 @@
+//
+// AUTHOR
+// N. Nielsen
+//
+// LICENSE
+// This software is in the public domain.
+//
+// The software is provided "as is", without warranty of any kind,
+// express or implied, including but not limited to the warranties
+// of merchantability, fitness for a particular purpose, and
+// noninfringement. In no event shall the author(s) be liable for any
+// claim, damages, or other liability, whether in an action of
+// contract, tort, or otherwise, arising from, out of, or in connection
+// with the software or the use or other dealings in the software.
+//
+// SUPPORT
+// Send bug reports to: <nielsen@memberwebs.com>
+//
+
+
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+
+#include <windows.h>
+#include <tchar.h>
+#include <winioctl.h>
+
+// Get first CD-ROM Drive letter
+TCHAR GetCDROM()
+{
+ TCHAR buff[4];
+ TCHAR i;
+
+ _tcscpy(buff, "X:\\");
+
+ for(i = _T('A'); i <= _T('Z'); i++)
+ {
+ buff[0] = i;
+ if(GetDriveType(buff) == DRIVE_CDROM)
+ return i;
+ }
+
+ return 0;
+}
+
+int Usage()
+{
+ MessageBox(NULL, _T("usage: eject [-load] [drive] ..."), _T("Eject Usage"), MB_OK | MB_ICONINFORMATION);
+ return 2;
+}
+
+int DoEject(TCHAR drive, int mode)
+{
+ TCHAR buff[7];
+ HANDLE hDevice;
+
+ _tcscpy(buff, "\\\\.\\X:");
+
+ if(drive == 0)
+ {
+ // Create a CD-ROM drive string
+ buff[4] = GetCDROM(drive);
+ }
+ else
+ {
+ buff[4] = drive;
+ }
+
+ if(buff[4] == 0)
+ {
+ MessageBox(NULL, _T("No CD-ROM drives found on system."), _T("Eject"), MB_OK | MB_ICONSTOP);
+ return 1;
+ }
+
+ // Open the CD device
+ hDevice = CreateFile(buff, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, 0, NULL);
+
+ if(hDevice != INVALID_HANDLE_VALUE)
+ {
+ DWORD code = IOCTL_STORAGE_EJECT_MEDIA;
+ DWORD bytesRet = 0;
+
+ // If specified with the '-load' parameter then load
+ // the drive rather than eject
+ if(mode)
+ code = IOCTL_STORAGE_LOAD_MEDIA;
+
+ DeviceIoControl(hDevice, code, NULL, 0, NULL, 0, &bytesRet, NULL);
+ }
+
+ CloseHandle(hDevice);
+
+ return 0;
+}
+
+int APIENTRY WinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow)
+{
+ int mode = 0;
+ int spec = 0;
+ int i;
+
+ for(i = 0; i < __argc; i++)
+ {
+ /* Specifying a parameter */
+ if(__argv[i][0] == '-')
+ {
+ char* arg = __argv[i] + 1;
+
+ if(strstr(arg, "load"))
+ {
+ mode = 1;
+ continue;
+ }
+
+ else if(strstr(arg, "eject"))
+ {
+ mode = 0;
+ continue;
+ }
+
+ else if(strstr(arg, "h"))
+ {
+ return Usage();
+ }
+ }
+
+ /* Specifying a drive */
+ if(strlen(__argv[i]) == 1)
+ {
+ char drive = tolower(__argv[i][0]);
+ if(drive >= 'a' && drive <= 'z')
+ {
+ if(!DoEject(drive, mode))
+ return 1;
+
+ spec = 1;
+ continue;
+ }
+ }
+
+ return Usage();
+ }
+
+ if(!spec)
+ {
+ if(!DoEject(0, mode))
+ return 1;
+ }
+
+ return 0;
+}
+
+
+
diff --git a/eject.dsw b/eject.dsw
new file mode 100644
index 0000000..61964d0
--- /dev/null
+++ b/eject.dsw
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "Eject"=.\Eject.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+