Java我不会,用C语言吧。C的程序有两个外部变量,__argc, __argv。
其中__argv[0]存放的就是你的EXE程序名。判断这个EXE是不是在光盘
就可以了。bool IsOnDisc()
{
    char buf[4];
    extern char** __argv;    strncpy(buf, __argv[0], 3);
    if (buf[1]!=':'||buf[2]!='\\')
        return false;
    buf[3] = '\0';
    return GetDriveType(buf)==DRIVE_CDROM;
}获取光盘的盘符:
char buf[128]="";
GetLogicalDriveStrings(128, buf);
for(char* s=buf; *s; s+=4) {
    //这儿s的内容就是 C:\\ 或 D:\\ 等
    if (GetDriveType(buf)==DRIVE_CDROM)
        ;//s指向的盘符是光盘
}

解决方案 »

  1.   

    bool IsOnDisc();void main()
    {
        if (!IsOnDisc()) {
            printf("程序不在光盘上。退出");
            return;
        }
        //执行你的程序代码
    }
      

  2.   

    查找第一个光驱盘符(VB):
    Option Explicit
    Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    Public Const DRIVE_CDROM = 5
    Public Const MMSYSERR_NOERROR = 0
    Public Const SND_ASYNC = &H1
    Public Const SND_NODEFAULT = &H2
    Public Const SND_PURGE = &H40
    Public Const SND_FILENAME = &H20000
    Global MyVolume As String' 查找计算机的光驱号
    Public Function FirstCDDrive() As StringConst ASC_A = 65
    Const ASC_Z = ASC_A + 25Dim I As IntegerFor I = ASC_A To ASC_Z
    If GetDriveType(Chr$(I) & ":\") = DRIVE_CDROM Then
        FirstCDDrive = Chr$(I)
        If getPicPath(FirstCDDrive) Then
            Exit For
        Else
            FirstCDDrive = "No"
        End If
    End If
    Next I
    End Function