Solved Why do I keep getting Permission denied in VBS?

August 8, 2017 at 03:23:13
Specs: Windows 10, AMD A10-6700 APU 3.70 GHz / 8 gb RAM
I have a VBS script in an HTA in which I use document.location to detect the current web adress of an IE window, but each time I run the code it outputs: "Permission denied".

The code below is supposed to open "https://www.youtube.com/?gl=EN&hl=en" in IE, and (when finished loading) open a MsgBox if the web adress (IE.document.location) actually is "https://www.youtube.com/?gl=EN&hl=en".

Note: My original code is much longer than this, I just made this example code to show you what my problem is.

<script type="text/vbscript">
Sub Wait(Time)
  Dim wmiQuery, objWMIService, objPing, objStatus
  wmiQuery = "Select * From Win32_PingStatus Where Address = '1.1.1.1' AND Timeout = " & Time
  Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  Set objPing = objWMIService.ExecQuery(wmiQuery)
  For Each objStatus in objPing
  Next
End Sub

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://www.youtube.com/?gl=EN&hl=en"

Do Until IE.ReadyState = 4
  Wait(200)
Loop

Set url = IE.document.location
If url = "https://www.youtube.com/?gl=EN&hl=en" Then
  X = MsgBox("You're on Youtube")
Else
  X = MsgBox("You're not on Youtube")
End If
</script>


See More: Why do I keep getting Permission denied in VBS?

Reply ↓  Report •

#1
August 8, 2017 at 09:19:38
✔ Best Answer
Set url = IE.document.location
Should be:
url = IE.LocationURL

How To Ask Questions The Smart Way


Reply ↓  Report •

#2
August 8, 2017 at 10:13:07
I LOVE YOU MAN!!! You don't know how frikin' much I've been searching for solutions to this problem, I've posted this question on all programming forums I could found. Thanks a lot!

Reply ↓  Report •
Related Solutions


Ask Question