neilwhite
asked on
Drive Letters
I have a problem with the CD-ROM drive letter. I have a product running from a CD. This product does not allow you to call a file by just entering "folder\file.123" you have to enter the full path, "e:\work\folder\file.123".
As this is running from a CD this causes a problem, because the CD drive is not always e:, it could d:. I have found a way of creating a work drive using VB script. This pops up a prompt asking the user to specify what drive letter the CD is on and then it creates a duplicate drive called z: which is the sames as the CD (A bit like a mapped drive).
Heres is the script I used
Dim WinShell, prompt, folderpath, substcmd
Set WinShell = WScript.CreateObject("WScr ipt.Shell" )
prompt = "Type the path that you want to assign to drive w." & vbCrLf &_
"" & vbCrLf &_
"(Be sure to enclose the path in double quotes if it includes spaces.)"
folderpath = InputBox(prompt, "Where do you want to work today?")
If folderpath = "" Then
Wscript.Quit
Else
substcmd ="subst w: " & folderpath
WinShell.Run substcmd, 2, False
'MsgBox "Ready?", 32, "Make Work Drive"
'WinShell.Run "explorer.exe /n, /e, w:\",1,False
End If
Wscript.Quit
There is also a script to remove the work drive. I have tried to put this into VB put have been unable because VB doesn't like the WScript.CreateObject("WScr ipt.Shell" ). After searching on the web it turns out Wscript can only be used in scripting languages.
Is there a way of doing this in VB. The reasons for wanting to do this is, 1) People are reluctant to run VB scripts 2) Doesn't look very good and 3) I'd like to have an autorun on the CD which u can choose to create the work drive.
Thanks in advance
Neil White
As this is running from a CD this causes a problem, because the CD drive is not always e:, it could d:. I have found a way of creating a work drive using VB script. This pops up a prompt asking the user to specify what drive letter the CD is on and then it creates a duplicate drive called z: which is the sames as the CD (A bit like a mapped drive).
Heres is the script I used
Dim WinShell, prompt, folderpath, substcmd
Set WinShell = WScript.CreateObject("WScr
prompt = "Type the path that you want to assign to drive w." & vbCrLf &_
"" & vbCrLf &_
"(Be sure to enclose the path in double quotes if it includes spaces.)"
folderpath = InputBox(prompt, "Where do you want to work today?")
If folderpath = "" Then
Wscript.Quit
Else
substcmd ="subst w: " & folderpath
WinShell.Run substcmd, 2, False
'MsgBox "Ready?", 32, "Make Work Drive"
'WinShell.Run "explorer.exe /n, /e, w:\",1,False
End If
Wscript.Quit
There is also a script to remove the work drive. I have tried to put this into VB put have been unable because VB doesn't like the WScript.CreateObject("WScr
Is there a way of doing this in VB. The reasons for wanting to do this is, 1) People are reluctant to run VB scripts 2) Doesn't look very good and 3) I'd like to have an autorun on the CD which u can choose to create the work drive.
Thanks in advance
Neil White
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you mean open a text file in notepad?You can use the ShellExecute API.
' Declarations
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
Call ShellExecute(hwnd, "Open", ("C:\Textfile.txt"), "", App.Path, 1)
End Sub
' Declarations
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
Call ShellExecute(hwnd, "Open", ("C:\Textfile.txt"), "", App.Path, 1)
End Sub
ASKER
doesn't work, nothing happens
ASKER
Does what I want excellent
Thanks you
Thanks you
ASKER
If you don't mind could u tell me how to execute a text file from VB. I;ve tried the follwoing code with no sucess.
Private Sub butReadMe_Click()
Dim DocPath, WinShell
DocPath = "notepad.exe" & App.Path & "/files/GeoTechnical_Datab
Set WinShell = CreateObject("WScript.Shel
WinShell.Run DocPath
End Sub
I get the message
Run Time error '70':
Permission denied
Cheers
Neil