Cd shell

  • Thread starter Thread starter twistedmetal
  • Start date Start date
T

twistedmetal

anyone know the code for runnign a shell off a cd? i'm
using the code:

dim retval
retval = shell("e:/night.exe",1)

yet i doubt that everyone elses cd-rom drive's a E: drive,
how do i change that? I am guessing its something like %
system% but i am not sure...

If anyone coudl reply then plz reply asap to
(e-mail address removed) (any spam will be blocked)
 
Hi twisted Metal

Copied from HKW and a little bit changed, not tested
\\\
Set a reference to .Net System.Management

Dim allDrives() As String = Environment.GetLogicalDrives()
Dim drive As String
For Each drive In allDrives
Dim win32Drive As String = _
"Win32_LogicalDisk='" & drive.Substring(0, 2) & "'"
Dim moDisk As System.Management.ManagementObject _
= New System.Management.ManagementObject(win32Drive)
If moDisk("DriveType").ToString = "5" Then
Try
shell(drive & "\night.exe",1)
Exit For
Catch ex As Exception
MessageBox.Show(ex.tostring)
End Try
End If
Next
///
I hope this helps a little bit?
Cor
 
* "twistedmetal said:
anyone know the code for runnign a shell off a cd? i'm
using the code:

dim retval
retval = shell("e:/night.exe",1)

In Windows we use "\" instead of "\".
yet i doubt that everyone elses cd-rom drive's a E: drive,
how do i change that? I am guessing its something like %
system% but i am not sure...

There can be more than one CD-ROM drive on the system.

\\\
Public Enum DriveType
Unknown = 0
NoRootDirectory = 1
RemoveableDisk = 2
LocalDisk = 3
NetworkDrive = 4
CompactDisk = 5
RamDisk = 6
End Enum

Public Function GetDriveType(ByVal strDrive As String) As DriveType
strDrive = "Win32_LogicalDisk='" & strDrive.Substring(0, 2) & "'"
Dim moDisk As ManagementObject = New ManagementObject(strDrive)
Return _
DirectCast( _
[Enum].Parse(GetType(DriveType), moDisk("DriveType").ToString()), _
DriveType _
)
End Function
///

Add a reference to "System.Management.dll" and import the
'System.Management' namespace:

\\\
Dim astrDrives() As String = Environment.GetLogicalDrives()
Dim strDrive As String
For Each strDrive In astrDrives
MessageBox.Show( _
"Drive: " & strDrive & ControlChars.NewLine & _
"Type: " & GetDriveType(strDrive).ToString() _
)
Next strDrive
///
 
Cor said:
Hi twisted Metal

Copied from HKW and a little bit changed, not tested
\\\

Hi
This probably works ok, but what if the user has multiple cd drives and the
cd isn't in the first drive? (some hardware setups are quite odd)
So perhaps adding a check to see if the file exists and then if not move on
to next cd drive... :
Set a reference to .Net System.Management

Dim allDrives() As String = Environment.GetLogicalDrives()
Dim drive As String
For Each drive In allDrives
Dim win32Drive As String = _
"Win32_LogicalDisk='" & drive.Substring(0, 2) & "'"
Dim moDisk As System.Management.ManagementObject _
= New System.Management.ManagementObject(win32Drive)
If moDisk("DriveType").ToString = "5" Then

If System.IO.File.Exists(drive & "\night.exe") Then
Try
shell(drive & "\night.exe",1)
Exit For
Catch ex As Exception
MessageBox.Show(ex.tostring)
End Try

End If
 
Hi Herfried,

Reading ?
yet i doubt that everyone elses cd-rom drive's a E: drive,
how do i change that? I am guessing its something like %
system% but i am not sure...

Did I read "are" ?

Do I give you a lot of credit with naming you and then such a answer

:-)))

Cor
 
* "Jens Andersen said:
This probably works ok, but what if the user has multiple cd drives and the
cd isn't in the first drive? (some hardware setups are quite odd)
So perhaps adding a check to see if the file exists and then if not move on
to next cd drive... :


If System.IO.File.Exists(drive & "\night.exe") Then

\\\
Exit For
///

;-)
 
* "Cor said:
Reading ?


Did I read "are" ?

Sorry, I didn't see your post when writing mine.
Do I give you a lot of credit with naming you and then such a answer

Thanks! I am not sure if the code was written by me, but thanks anyway.
 
Back
Top