Microsoft KB Archive/184741

= PRB: MsgBox with Script Control Produces Run-Time Error 70 =

Article ID: 184741

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
 * Microsoft Visual Basic for Applications 5.0

-



This article was previously published under Q184741



SYMPTOMS
When you run a script in an application that hosts the Microsoft Script control, MsgBox causes the following error message to appear:

Run-time error #70:

Permission Denied



CAUSE
The AllowUI property of the control is FALSE.



RESOLUTION
Set the AllowUI property of the script control to TRUE either through code at run time or through the property sheet at design time.



STATUS
This behavior is by design.



MORE INFORMATION
Active Scripting, which the script control enables, allows scripting host applications to turn off user interface access from scripts. The purpose of this feature is to prevent rogue scripts from subverting the host application or the operating system.

IMPORTANT: Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures.

Step-by-Step Example
 In Visual Basic, create a new project (Form1 is created by default). Click Components on the Project menu, and then select the "Microsoft Script Control 1.0" check box. Add the Script control (ScriptControl1), a text box (Text1), and a command button (Command1) to Form1. Set the MultiLine property of the text box to TRUE.  Add the following code to Form1: Private Sub Command1_Click On Error Resume Next With ScriptControl1 .Language = "VBScript" .AllowUI = False .AddCode Text1.Text .Run "Hello" End With If Err Then MsgBox Err & " " & Error End Sub

 Run Form1, and open the Debug window.</li>  Type the following script in the text box: Sub Hello MsgBox "Hello World" End Sub

</li> Click the command button. As a result, the run-time error 70, "Permission Denied" appears.</li>  In the Command1_Click, change: .AllowUI = False

to: .AllowUI = True

</li> Run Form1 again. The error message does not appear.</li></ol>

<div class="references_section">