Get CD letter and run appropriate .vbs - help 
Author Message
 Get CD letter and run appropriate .vbs - help

Dear all,

Can some write me a script that I will burn in a CD and give it to a user.

When the user doubleclicks the script it will automatically detect
the drive letter of the user CD ROM it was doubleclicked from.

If the drive letter is D:\ it will activate another script called D.VBS
If the drive letter is E:\ it will activate another script called E.VBS

Thanks for your help!
Carlos.



Mon, 27 Sep 2004 00:03:10 GMT  
 Get CD letter and run appropriate .vbs - help
Call WScript.ScriptFullName to get the name & path of the script that is
running.

Then parse the string to find the drive letter.  The FileSystemObject
GetDriveName method would be the easist way to do that.

Enjoy


Quote:
> Dear all,

> Can some write me a script that I will burn in a CD and give it to a user.

> When the user doubleclicks the script it will automatically detect
> the drive letter of the user CD ROM it was doubleclicked from.

> If the drive letter is D:\ it will activate another script called D.VBS
> If the drive letter is E:\ it will activate another script called E.VBS

> Thanks for your help!
> Carlos.



Mon, 27 Sep 2004 05:16:27 GMT  
 Get CD letter and run appropriate .vbs - help
Does this script finds the drive letter?

Dim fso
 Set fso = CreateObject("Scripting.FileSystemObject")
 script_directory  = fso.GetParentFolderName(Wscript.ScriptFullName)

Function GetAName(script_directory)
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   GetAName = fso.GetDriveName(script_directory)
End Function

Then I need the script to do something like this:

set shell = createobject("wscript.shell")
if DriveName = "D" then
shell.run "D:\D.vbs"
if DriveName = "E" then
shell.run "E:\E.vbs"
if DriveName = "F" then
shell.run "F:\F.vbs"
Else WScript.Echo "message alert"
End if

(I know it's not correct i'm a newbie)



Quote:
> Call WScript.ScriptFullName to get the name & path of the script that is
> running.

> Then parse the string to find the drive letter.  The FileSystemObject
> GetDriveName method would be the easist way to do that.

> Enjoy



> > Dear all,

> > Can some write me a script that I will burn in a CD and give it to a
user.

> > When the user doubleclicks the script it will automatically detect
> > the drive letter of the user CD ROM it was doubleclicked from.

> > If the drive letter is D:\ it will activate another script called D.VBS
> > If the drive letter is E:\ it will activate another script called E.VBS

> > Thanks for your help!
> > Carlos.



Mon, 27 Sep 2004 12:23:22 GMT  
 Get CD letter and run appropriate .vbs - help
He was trying to show you details and apparently that made it more complex for
you.

Here's an example - I included a bunch of extra wscript.echo statements so you
get an idea of what happens in the script flow.

' I put  a bunch of wscript.echo lines in so you can see logic

' this will get the drive letter and ":" where the script lives
theDrive = GetAName(Wscript.ScriptFullName)
wscript.echo "The drive is: " & theDrive

' Now we trim off the ":"
theLetter = Replace(theDrive,":","")
wscript.echo "The letter is: " & theLetter

set shell = createobject("wscript.shell")

'to make this easier, we can use error control
' and do ONE line for the execution:
On Error Resume Next
theCommand = theDrive & "\" & theLetter & ".vbs"
wscript.echo "The command to run will be: " & theCommand

'now we run it
shell.run theCommand

'if the errorlevel is not 0, there was a problem
If Err.Number<>0 Then
 WScript.Echo "message alert"
 'this next is for you to see:
 wscript.echo err.number & "," & err.description & "," & err.source
End If

Function GetAName(script_directory)
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   GetAName = fso.GetDriveName(script_directory)
End Function


Quote:
> Does this script finds the drive letter?

> Dim fso
>  Set fso = CreateObject("Scripting.FileSystemObject")
>  script_directory  = fso.GetParentFolderName(Wscript.ScriptFullName)

> Function GetAName(script_directory)
>    Dim fso
>    Set fso = CreateObject("Scripting.FileSystemObject")
>    GetAName = fso.GetDriveName(script_directory)
> End Function

> Then I need the script to do something like this:

> set shell = createobject("wscript.shell")
> if DriveName = "D" then
> shell.run "D:\D.vbs"
> if DriveName = "E" then
> shell.run "E:\E.vbs"
> if DriveName = "F" then
> shell.run "F:\F.vbs"
> Else WScript.Echo "message alert"
> End if

> (I know it's not correct i'm a newbie)



> > Call WScript.ScriptFullName to get the name & path of the script that is
> > running.

> > Then parse the string to find the drive letter.  The FileSystemObject
> > GetDriveName method would be the easist way to do that.

> > Enjoy



> > > Dear all,

> > > Can some write me a script that I will burn in a CD and give it to a
> user.

> > > When the user doubleclicks the script it will automatically detect
> > > the drive letter of the user CD ROM it was doubleclicked from.

> > > If the drive letter is D:\ it will activate another script called D.VBS
> > > If the drive letter is E:\ it will activate another script called E.VBS

> > > Thanks for your help!
> > > Carlos.



Mon, 27 Sep 2004 12:56:49 GMT  
 Get CD letter and run appropriate .vbs - help

Thanks Alex for your help!
my script now works as I want it from top to bottom
Thanks also for your detail explanations.
I'm really grateful!
Carlos.



Quote:
> He was trying to show you details and apparently that made it more complex
for
> you.

> Here's an example - I included a bunch of extra wscript.echo statements so
you
> get an idea of what happens in the script flow.

> ' I put  a bunch of wscript.echo lines in so you can see logic

> ' this will get the drive letter and ":" where the script lives
> theDrive = GetAName(Wscript.ScriptFullName)
> wscript.echo "The drive is: " & theDrive

> ' Now we trim off the ":"
> theLetter = Replace(theDrive,":","")
> wscript.echo "The letter is: " & theLetter

> set shell = createobject("wscript.shell")

> 'to make this easier, we can use error control
> ' and do ONE line for the execution:
> On Error Resume Next
> theCommand = theDrive & "\" & theLetter & ".vbs"
> wscript.echo "The command to run will be: " & theCommand

> 'now we run it
> shell.run theCommand

> 'if the errorlevel is not 0, there was a problem
> If Err.Number<>0 Then
>  WScript.Echo "message alert"
>  'this next is for you to see:
>  wscript.echo err.number & "," & err.description & "," & err.source
> End If

> Function GetAName(script_directory)
>    Dim fso
>    Set fso = CreateObject("Scripting.FileSystemObject")
>    GetAName = fso.GetDriveName(script_directory)
> End Function



> > Does this script finds the drive letter?

> > Dim fso
> >  Set fso = CreateObject("Scripting.FileSystemObject")
> >  script_directory  = fso.GetParentFolderName(Wscript.ScriptFullName)

> > Function GetAName(script_directory)
> >    Dim fso
> >    Set fso = CreateObject("Scripting.FileSystemObject")
> >    GetAName = fso.GetDriveName(script_directory)
> > End Function

> > Then I need the script to do something like this:

> > set shell = createobject("wscript.shell")
> > if DriveName = "D" then
> > shell.run "D:\D.vbs"
> > if DriveName = "E" then
> > shell.run "E:\E.vbs"
> > if DriveName = "F" then
> > shell.run "F:\F.vbs"
> > Else WScript.Echo "message alert"
> > End if

> > (I know it's not correct i'm a newbie)



> > > Call WScript.ScriptFullName to get the name & path of the script that
is
> > > running.

> > > Then parse the string to find the drive letter.  The FileSystemObject
> > > GetDriveName method would be the easist way to do that.

> > > Enjoy



> > > > Dear all,

> > > > Can some write me a script that I will burn in a CD and give it to a
> > user.

> > > > When the user doubleclicks the script it will automatically detect
> > > > the drive letter of the user CD ROM it was doubleclicked from.

> > > > If the drive letter is D:\ it will activate another script called
D.VBS
> > > > If the drive letter is E:\ it will activate another script called
E.VBS

> > > > Thanks for your help!
> > > > Carlos.



Tue, 28 Sep 2004 01:24:54 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Set/Change CD-ROM drive letter with VBS

2. Newby: Determine CD-ROM drive letter

3. Change CD-ROM Drive Letter

4. Retrieving drive letters and paths on a CD using client side VBScript

5. CD-Rom Drive Letter

6. Change CD-ROM Drive Letter

7. Getting Local IP address running a VBS script locally

8. Getting .vbs script to run at logon..

9. Help: Looping a script until appropriate input.

10. Help getting Gsview up and running

11. HELP - getting Security Alert trying to run my VBscript

12. Running VBS Through HTML - HELP!!

 

 
Powered by phpBB® Forum Software