0

I need to run a exe file in my local machine through javascript. I use

<script language="JavaScript" type="text/javascript">  
     MyObject = new ActiveXObject( "WScript.Shell" )  
     function RunExe()   
     {  
        MyObject.Run('"file:///C:/Users/username/Desktop/app.exe" "hello" "hi"') ;  
    }  

</script> 

This script runs fine when I create a aspx page and run from it. But it doesn't work if this is added to the script editor webpart. Any thoughts?

3
  • What's your browser? Do you see any entries in browser console (F12)? Commented Mar 9, 2016 at 11:18
  • Start with inspecting what SharePoint makes of this in the HTML delivered to the browser (not the source you paste into the WebPart) Commented Mar 9, 2016 at 11:22
  • @AzizKabyshev browser IE11 the error I get is 'unable to get property Run of undefined or null reference'. Once I put the initialization inside the function, I get 'automation server cant create object'
    – Obiliraj
    Commented Mar 9, 2016 at 11:33

2 Answers 2

0

Make sure you have wrapped your code inside script tag even in script editor web part.

<script language="JavaScript" type="text/javascript">//code</script>

source: This reference

0

I can confirm it works fine in Content Editor Web Part. Just tried this code:

<script>
    MyObject = new ActiveXObject("WScript.Shell");
    function RunNotepad()
    {
        MyObject.Run("C:\\Windows\\system32\\notepad.exe");
        return true;
    }
</script>
<input onclick="return RunNotepad()" type="button" value="Run Notepad"/>

As long as we are discussing SharePoint Online, your SP addresses should already be included in one of IE's security zones. I've got 4 https://{site}.sharepoint.com entries in Trusted zone, but you may want to take a look at In what Security Zone should SharePoint Online (Office 365) be added? or search for official recommendations from Microsoft.

Then I've opened IE -> Tools -> Internet Options -> Security tab, selected Trusted zone, pressed Custom level... and set ActiveX-related options to Prompt. Now at the page load I see this:

enter image description here

notepad is launched fine from that button now.


So you see there is nothing SP-related here - it's IE security restrictions in action. Adjust your security zone settings, and script will work 100%. But stay informed that it lowers overall security.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.