-
Aug 4th, 2020, 09:34 PM
#1
Thread Starter
New Member
VBscript to verify "Apple iPhone" is connected
First off I have to tell you I am no programmer so please bear with me if you please.
I am attempting to write a small vbscript routine to assist in copying photos from an iPhone to a Win10 machine. I am using MTPdrive to map the iPhone (P:\DCIM\). I have a couple conditional statements that run the copy routine if the folder exists -- if not, it prompts to connect. However, what would be tremendously helpful is if there is a way to test if the “Apple iPhone” device connection exists (not the mapped drive).
My question - is it possible to verify an “Apple iPhone” connection via vbscripting or some other coding prior to the iPhone being mapped? That is, I only want to run MTPdrive.exe program if it can first be confirmed the “Apple iPhone” device is connected.
Thanks,
Steve
-
Aug 22nd, 2020, 09:06 AM
#2
Re: VBscript to verify "Apple iPhone" is connected
Hello Skipping, welcome to the forum. Sorry for the late reply, but it took me a while to think of an answer. This vbscript code should be able to detect whether or not an iPhone is connected to your computer:
Code:
Option Explicit
wscript.echo iPhoneConnected
Private Function iPhoneConnected()
Dim colItems
Dim objItem
Dim objWMIService
Dim strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("select * from Win32_PnPEntity",,48)
For Each objItem in colItems
If LCase(Trim(objItem.Caption)) = "apple iphone" Then
iPhoneConnected = True
Exit Function
End If
Next
iPhoneConnected = False
End Function
.
This code can also be easily modified to detect/list other devices btw.
yours,
Peter Swinkels
-
Aug 22nd, 2020, 10:09 PM
#3
Thread Starter
New Member
Re: VBscript to verify "Apple iPhone" is connected
Originally Posted by Peter Swinkels
Hello Skipping, welcome to the forum. Sorry for the late reply, but it took me a while to think of an answer. This vbscript code should be able to detect whether or not an iPhone is connected to your computer:
Code:
Option Explicit
wscript.echo iPhoneConnected
Private Function iPhoneConnected()
Dim colItems
Dim objItem
Dim objWMIService
Dim strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("select * from Win32_PnPEntity",,48)
For Each objItem in colItems
If LCase(Trim(objItem.Caption)) = "apple iphone" Then
iPhoneConnected = True
Exit Function
End If
Next
iPhoneConnected = False
End Function
.
This code can also be easily modified to detect/list other devices btw.
yours,
Peter Swinkels
Peter,
Thank you for your response. I must note that I am not a programmer so some of my questions may seem frivolous or quite silly.
This routine appears to be doing what I had in mind. It returns a “-1”, if the iPhone is connected (i.e., an “Apple iPhone” connection exists); and returns a “0” if not connected. However, I’m not sure how this is to be applied. As an example - is there way to call sub1 if connected else call sub2?
Thanks,
Steve
-
Aug 23rd, 2020, 05:33 AM
#4
Re: VBscript to verify "Apple iPhone" is connected
Steve,
Don't worry about your questions appearing to be silly, they're not for someone with no experience in programming. Your questions however are so basic that it seems you would have to learn vbscript before accomplishing your goal. If you like you could post what you already wrote yourself and I will have a shot at writing the required script. As to your question, you need to use If/Then/Else statements:
Code:
If iPhoneConnected Then do something with phone Else report to user there is no iphone connected
[i]The function in the code I posted here needs to be placed here.[i/]
Here's a tutorial about If/Then/Else statements: https://www.tutorialspoint.com/vbscr..._decisions.htm. You can also learn about other vbscript related stuff over there.
yours,
Peter Swinkels
Last edited by Peter Swinkels; Aug 23rd, 2020 at 09:30 AM.
-
Aug 23rd, 2020, 09:23 AM
#5
Thread Starter
New Member
Re: VBscript to verify "Apple iPhone" is connected
Peter,
Again, thank you for your response. I am familiar with If/Then statements. I just wasn’t sure how to proceed with a function as such. As a test, what I did was.
If iPhoneConnected then
MsgBox “ YES . . .”
Else
MsgBox “ NOPE . . .”
End If
I remarked out the “wscript.echo iPhoneConnected” line to suppress the Windows Script Host message (0 or -1). This works fine. I will incorporate this into the rest of my program.
Much appreciated,
Steve
-
Aug 23rd, 2020, 09:31 AM
#6
Re: VBscript to verify "Apple iPhone" is connected
-
Oct 15th, 2020, 09:17 PM
#7
New Member
Re: VBscript to verify "Apple iPhone" is connected
Thanks for the information. I was looking for this...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|