Jump to content

failure with scriptControl object (my fault of course)


Recommended Posts

Hi all.
I'm playing a bit with the ScriptControl object using as base this example by @genius257.

here is a very simple try, ... but it fails. what I'm doing wrong?

Local $oSC = ObjCreate("ScriptControl")
$oSC.Language = "JScript"

$oSC.ExecuteStatement('alert("I am a javascript alert box!");')

MsgBox(0,'AutoIt','Pause')

Thanks

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Thanks @junkew,

AllowUI is now set to True but I got same result

Local $oSC = ObjCreate("ScriptControl")
$oSC.Language = "JScript"

$oSC.AllowUI = True
ConsoleWrite("Debug:" & @CRLF & "Language:" & @TAB & $oSC.Language & @CRLF & "AllowUI:" & @TAB & $oSC.AllowUI & @CRLF)

$oSC.ExecuteStatement('alert("I am a javascript alert box!");')

MsgBox(0,'AutoIt','Pause')

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

alert is not a function from javascript its a function from the internet explorer window object.
As such you cannot call a msgbox/alert function from JavaScript. Although I remember something as you host the control you can call an AutoIt function within the JScript you run.

examplevbs()
exampleJS()

MsgBox(0,'AutoIt','Pause')


func exampleJS()
    Local $oSC = ObjCreate("MSScriptControl.ScriptControl")
$oSC.Language = "JScript"

$oSC.AllowUI = True
ConsoleWrite("Debug:" & @CRLF & "Language:" & @TAB & $oSC.Language & @CRLF & "AllowUI:" & @TAB & $oSC.AllowUI & @CRLF)

;~ $oSC.ExecuteStatement("alert('I am a javascript alert box!');")
;~ $oSC.Run("alert('I am a javascript alert box!');")

$strCode= "alert(" & Chr(39) & "I am a javascript alert box!" & Chr(39) & ");"
ConsoleWrite("strCode:" & $strCode & @CRLF )
$oSC.ExecuteStatement("alert('I am a javascript alert box!');")


EndFunc

func exampleVBs()
    Local $oSC = ObjCreate("MSScriptControl.ScriptControl")
$oSC.Language = "VBScript"

$oSC.AllowUI = True
ConsoleWrite("Debug:" & @CRLF & "Language:" & @TAB & $oSC.Language & @CRLF & "AllowUI:" & @TAB & $oSC.AllowUI & @CRLF)

$strCode= "msgbox " & Chr(34) & "test" & Chr(34)
ConsoleWrite("strCode:" & $strCode & @CRLF )
 $oSC.ExecuteStatement($strCode)

$oSC.Run("alert('I am a javascript alert box!');")

EndFunc

 

Not sure what you want to achieve but following roads you could follow

1. mangle JScript with VBScript and AutoIT (with registering AutoIt as com on the fly https://www.autoitscript.com/forum/topic/128627-access-autoit/)

2. Load ChakraCore engine (search ChakraCore in the forums)
https://www.autoitscript.com/forum/topic/185996-chakra-native-javascript-runtime-jsrt

3. Embed JScript in a C# module and run it with help of CLR.AU3 examples (not done before I think but then you are less dependent on the MSScriptcontrol.

 

 

 

Edited by junkew
Link to comment
Share on other sites

11 hours ago, junkew said:

alert is not a function from javascript its a function from the internet explorer window object.
As such you cannot call a msgbox/alert function from JavaScript. ......

... that make sense....
Thanks @junkew for the suggestions, I will do some tests

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Triggered by this thread I will check more on chakra.dll

see here the base references of microsoft on embedding

 

 

Link to comment
Share on other sites

Hi, Chimp

Here is a way to use a msgbox or alert in jscript.

Local $oSC = ObjCreate("ScriptControl")
$oSC.Language = "JScript"

local $jcode = "function alert(iData,iTitle,iFlag,timeout){" & _
               "iTitle = iTitle || 'Info';" & _
               "iFlag = iFlag || 64;" & _
               "timeout = timeout || 0;" & _
               "return new ActiveXObject('WScript.Shell').Popup(iData,timeout,iTitle,iFlag);}"

$oSC.AddCode($jcode)

$oSC.ExecuteStatement("alert('I am a javascript alert box!')")

MsgBox(0,'AutoIt','Pause')

This runs on IE 11 win 7.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...