script newbie here and i am banging my head against my keyboard trying
to figure this one out. i am sure it is easy to all of the guru's
here. what i am trying to do is check to see if an assigned drive
letter (i: in this case) exists before i allow a script to copy data
to it. if it doesn't i want the script to continue as planned, if it
doesn't i want the script to prompt the end user to insert his/her usb
drive. i know there has to be a way to do it so any help would be
greatly appreciated. thanks in advance...
here is what i have so far.
Dim objfso, msg, i
drv = "i"
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(drv) Then
End If
Set i = objfso.GetDrive(drv)
If i.IsReady Then
Else
msg = "Please plug USB drive into laptop..."
End If
Else
msg = "Please plug USB drive into laptop..."
End If
Set objShell = CreateObject("Wscript.Shell")
objshell.Popup msg, AUTO_ANSWER, "Insert USB Drive", OK_Button
Sorry for the rush I am trying to finish this up and can't seem to pry
myself away from the computer. PLEEAAASSSEEE HELP! tia.
GP
--->
> hey all,
>
> script newbie here and i am banging my head against my keyboard trying
> to figure this one out. i am sure it is easy to all of the guru's
> here. what i am trying to do is check to see if an assigned drive
> letter (i: in this case) exists before i allow a script to copy data
> to it. if it doesn't i want the script to continue as planned, if it
> doesn't i want the script to prompt the end user to insert his/her usb
> drive. i know there has to be a way to do it so any help would be
> greatly appreciated. thanks in advance...
>
> here is what i have so far.
>
>
>
> Dim objfso, msg, i
>
> drv = "i"
> Set objfso = CreateObject("Scripting.FileSystemObject")
> If objfso.DriveExists(drv) Then
> End If <------------------------------------------------------------ HERE
Thanks for the response. What I was trying to accomplish is for the
script to continue without any notification if the the drive exists.
I only want to be prompted if the drive letter doesn't exist. If I
remove that END IF it prompts me with a blank echo/msgbox and I have
to click ok. I don't want any user interaction unless the drive
doesn't exist. Any other ideas? Thanks ...
--->
Your logic might go like this (this can be simplified with multiple
logic statements):
IF (drive exists) Then
IF (drive is ready) Then
' Do nothing - EXIT
ELSE
' wait until drive is ready
ENDIF
ELSE
' Tell OP to plug the drive in; and ...
' wait until drive is ready
ENDIF
GP
Thanks for your continued help. Here is the edited script with the
logic you mentioned. It looks good but I get an invalid "exit"
statement. We're almost there, thanks!
Dim objfso, msg, i
drv = "i"
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(drv) Then
Set i = objfso.GetDrive(drv)
If i.IsReady Then
EXIT
--->
Sorry - the EXIT was pseudocode - what you need to do there is either
delete the "EXIT" and let the logic take over, or add some sort of jump
or Return out of the entire routine.
GP
I thought I already responded but it isn't showing my last post so
here goes again. I apologize in advance if this comes up as a
duplicate. Following the logic you listed here is the script the way
I have it now. I am getting and invalid EXIT error when I try to run
it. Thanks for your continued efforts.
Dim objfso, msg, i
drv = "i"
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(drv) Then
Set i = objfso.GetDrive(drv)
If i.IsReady Then
EXIT
GP
--->
Jason
"GRAND_POOBAH" <iss_bos...@delete.sbcglobal.net> wrote in message
news:udmCBGRf...@TK2MSFTNGP03.phx.gbl...
GP,
If I let the logic handle it I get a blank popup/msgbox message that I
have to click ok on. I want to skip past the rest of that part of the
routine and let the script finish. I am not familiar enough with VB
script to know what code to use for that functionality. Thanks again
for all of your help thus far.
Jay,
I don't want to quit the script but that info you provided will be put
to good use in other scripts. Thanks. Any other responses will be
greatly appreciated.
Ryan
[snip]
>I thought I already responded but it isn't showing my last post so
>here goes again. I apologize in advance if this comes up as a
>duplicate. Following the logic you listed here is the script the way
>I have it now. I am getting and invalid EXIT error when I try to run
>it. Thanks for your continued efforts.
>
>Dim objfso, msg, i
>drv = "i"
>Set objfso = CreateObject("Scripting.FileSystemObject")
>If objfso.DriveExists(drv) Then
> Set i = objfso.GetDrive(drv)
> If i.IsReady Then
> EXIT
> Else
> msg = "Please plug USB drive into laptop..."
> End If
> Else
> msg = "Please plug USB drive into laptop..."
> End If
> Set objShell = CreateObject("Wscript.Shell")
> objshell.Popup msg, AUTO_ANSWER, "Insert USB Drive", OK_Button
Either, make the line "EXIT" a comment (by preceding it with a single
quote), or remove it altogether, or simplify the logic:
If Not objfso.DriveExists(drv) Or Not objfso.GetDrive(drv).IsReady
Set objShell = CreateObject("Wscript.Shell")
objshell.Popup "Please plug USB drive into laptop...", _
AUTO_ANSWER, "Insert USB Drive", OK_Button
End If
--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Thanks for the response. I copied your script here and tried to get
it to work with no luck. I also tried editing it where I thought the
problems were, still no luck. Like I mentioned above, I get a blank
popup type message when the drive is present with the script I was
running (pasted above). I need to eliminate that positive
notification and I only want to be notified if the drive DOESN'T
exist. Please help. This thing can't be this hard as I am sure I am
making it much more difficult some how. Thanks again for all of the
responses. Here is a copy of the last thing I tried.
Dim objsfo, drv, i
drv = "i"
Set objfso = CreateObject("Scripting.FileSystemObject")
If Not objfso.DriveExists(drv) Or Not objfso.GetDrive(drv).IsReady
Then
Set i = objfso.GetDrive(drv)
'End If
Set objShell = CreateObject("Wscript.Shell")
'first thing check the drive status, don't continue until it
'becomes available.
Do Until DriveStatus = True
DriveStatus = CheckDrive("i")
Loop
'some code down here to do some more stuff
'This function at the end of your code
Function CheckDrive(sDriveLetter)
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(sDriveLetter) Then
Set i = objfso.GetDrive(sDriveLetter
If Not i.IsReady Then Wscript.Echo "Please plug USB drive into
laptop..."
CheckDrive = False
Else
Wscript.Echo "Please plug USB drive into laptop..."
CheckDrive = False
End If
CheckDrive = True
End Function
Hope this helps. As always watch for line wrapping.
For some reason my replies aren't showing up in this group...:(
Thanks for the help with the script. It looks like the script above
will do what I want it to but I am getting an error when I try to run
it. It tells me that it is "Expected IF" state between the End &
Function of the last line of code. Any help? Tia...
Check your newsreader settings and what newsgroup server are you connecting
to?
--
Shenan Stanley
MS-MVP
--
How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html
Did you see this clue?
>>
>> Hope this helps. As always watch for line wrapping.
>>
I think you will see that line wrapping did occur here:
>> If Not i.IsReady Then Wscript.Echo "Please plug USB drive into
>> laptop..."
That is supposed to be one line, not two. Some newsreaders don't handle
long lines well.
-Paul Randall
This is the text I have in this script. I checked the line wrapping
and it appears correct. Please help...I think I just bit a pen in 1/2
trying to figure this out. LOL!
'first thing check the drive status, don't continue until it
'becomes available.
Do Until DriveStatus = True
DriveStatus = CheckDrive("i")
Loop
'some code down here to do some more stuff
'This function at the end of your code
Function CheckDrive(sDriveLetter)
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(sDriveLetter) Then
Set i = objfso.GetDrive(sDriveLetter)
> This is the text I have in this script. I checked the line wrapping
> and it appears correct. Please help...I think I just bit a pen in 1/2
> trying to figure this out. LOL!
>
> 'first thing check the drive status, don't continue until it
> 'becomes available.
>
> Do Until DriveStatus = True
> DriveStatus = CheckDrive("i")
> Loop
>
>
> 'some code down here to do some more stuff
>
>
> 'This function at the end of your code
> Function CheckDrive(sDriveLetter)
> Set objfso = CreateObject("Scripting.FileSystemObject")
> If objfso.DriveExists(sDriveLetter) Then
> Set i = objfso.GetDrive(sDriveLetter)
> If Not i.IsReady Then
> Wscript.Echo "Please plug USB drive into laptop..."
> CheckDrive = False
> Else
> Wscript.Echo "Please plug USB drive into laptop..."
> CheckDrive = False
> End If
>
> CheckDrive = True
> End Function
You have two if/then's up there, but only one else/endif. Programming
languages don't much like that kind of thing. Try adding another "End
If". ;)
Editors with syntax highlighting can be useful, too!
Thanks for the response Brian. Here is the corrected script with the
appropriate (I think) # of if/end if statements. Now I am getting a
"Device Unavailble" message. AGGGHHHHH!
'first thing check the drive status, don't continue until it
'becomes available.
Do Until DriveStatus = True
DriveStatus = CheckDrive("i")
Loop
'some code down here to do some more stuff
'This function at the end of your code
Function CheckDrive(sDriveLetter)
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(sDriveLetter) Then
Set i = objfso.GetDrive(sDriveLetter)
End If
Shouldn't that be "i:"?
Didn't notice that. I changed it and am still getting the "Device
Unavailable" message. I must be an idiot...
'first thing check the drive status, don't continue until it
'becomes available.
Do Until DriveStatus = True
DriveStatus = CheckDrive("i:")
Loop
'some code down here to do some more stuff
'This function at the end of your code
Function CheckDrive(sDriveLetter)
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(sDriveLetter) Then
Set i = objfso.GetDrive(sDriveLetter)
End If
Set objfso = CreateObject("Scripting.FileSystemObject")
Set i = objfso.GetDrive("i:")
Please copy and paste the code below but take note of the line that is
between the "all on one line" remarks.
'first thing check the drive status, don't continue until it
'becomes available.
Do Until DriveStatus = True
DriveStatus = CheckDrive("i")
Loop
'some code down here to do some more stuff
'This function at the end of your code
Function CheckDrive(sDriveLetter)
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(sDriveLetter) Then
Set i = objfso.GetDrive(sDriveLetter
'vvvvvvvAll on one line vvvvv
If Not i.IsReady Then Wscript.Echo "Please plug USB drive into
laptop..."
'^^^^^^END All on one line^^^^^^
CheckDrive = False
Else
Wscript.Echo "Please plug USB drive into laptop..."
CheckDrive = False
End If
CheckDrive = True
End Function
As I said earlier, the problem is here:
>> If Not i.IsReady Then Wscript.Echo "Please plug USB drive into
>> laptop..."
This statement was supposed to be all on one line.
You changed it to two lines which has incorrect syntax:
> If Not i.IsReady Then
> Wscript.Echo "Please plug USB drive into laptop..."
It could have been written as one physical long line or one logical line
split up into two physical lines with a continuation (underscore):
If Not i.IsReady Then _
Wscript.Echo "Please plug USB drive into laptop..."
Or it could have been written as three physical lines with an If ... Then
... Endif block:
If Not i.IsReady Then
Wscript.Echo "Please plug USB drive into laptop..."
End If
>On Apr 17, 2:06 pm, Brian Wolven <brian.wol...@domain.invalid> wrote:
>> shrpshtr wrote:
>>
>> > Thanks for the response Brian. Here is the corrected script with the
>> > appropriate (I think) # of if/end if statements. Now I am getting a
>> > "Device Unavailble" message. AGGGHHHHH!
This has been tested and works here:
01 Option Explicit
02
03 Dim objShell
04 Set objShell = CreateObject("Wscript.Shell")
05
06 Do Until CheckDrive("I") = True
07 objShell.Popup "Please plug USB drive into laptop...", 0, "Insert USB Drive", 48
08 Loop
09 WScript.Quit
10
11 Function CheckDrive(strDriveLetter)
12
13 Dim objFSO
14
14 Set objFSO = CreateObject("Scripting.FileSystemObject")
16 CheckDrive = False
17 If objFSO.DriveExists(strDriveLetter) Then If objFSO.GetDrive(strDriveLetter).IsReady Then CheckDrive = True
18
19 End Function
This code has 19 lines; the line numbers must be removed.
Line 07 is 82 characters long, line 17 is 108 characters long.
Thanks for all of the great help everyone. I know it took an act of
congress just about but the script is functioning just fine. I really
appreciate it.
Ryan