How to run .exe file from code? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to run .exe file from code?

Last post 06-24-2011 02:36 AM by DaveA. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 09-06-2006 12:50 AM

    How to run .exe file from code?

    How can I run .exe program from an InfoPath form's code (VBscript)?
  • 09-06-2006 04:20 AM In reply to

    Re: How to run .exe file from code?

    Hey,

    This is a quick example to run the calculator program from a button in InfoPath via VbScript:

    Sub btnCalc_OnClick(eventObj)
    ' Write your code here
    Dim wshShell

    Set wshShell = Createobject("WScript.Shell")
    wshShell.Run "calc"
    wshShell.AppActivate "Calculator"
    End Sub

    Hope that helps,
    MB
  • 09-06-2006 09:24 AM In reply to

    Re: How to run .exe file from code?

    Hey,

    Here is another one that creates a simple temporary text file and then displays it in Notepad from a button in the form template.

    Sub btnCreateTempFile_OnClick(eventObj)
    ' Write your code here
    Const iTempFolder = 2
    Dim oFS, oTempFolder, sFile, oTempFile, wshShell
    Dim sRun, sTemp

    Set oFS = CreateObject("Scripting.FileSystemObject")
    Set oTempFolder = oFS.GetSpecialFolder(iTempFolder)
    sFile = oFS.GetTempName

    sTemp = oFS.GetSpecialFolder(iTempFolder)
    If Right(sTemp,1) <> "\" Then
    sTemp = sTemp & "\" & sFile
    Else
    sTemp = sTemp & sFile
    End If


    Set oTempFile = oTempFolder.CreateTextFile(sFile)

    oTempFile.WriteLine "Temp File created on " & Now()


    'show it in notepade
    Set wshShell = Createobject("WScript.Shell")
    sRun = "notepad.exe " & sTemp
    wshShell.Run sRun
    wshShell.AppActivate "NotePad"
    End Sub
  • 09-06-2006 12:36 PM In reply to

    Re: How to run .exe file from code?

    is it possible to pull information from your data fields and insert into the notepad file?
  • 09-07-2006 04:18 AM In reply to

    Re: How to run .exe file from code?

    Hey,

    I don't see why not! You can create the file with File System Object and use the WriteLine method to enter data into the text file (see above with oTempFile.WriteLine) and instead of hard coding the info for the line, use the XDocument.DOM.selectSingleNode("//my:FieldName").Text

    Hope that helps!
    MB
  • 09-07-2006 01:00 PM In reply to

    Re: How to run .exe file from code?

    i usually use jscript, but heres a quick tutorial to switch scripts once you have already chosen a script:

    http://support.microsoft.com/kb/828853/en-us?spid=2515&sid=global


    Also, is there a way to print out a repeating table, maybe store it in an array and then print out the array?

    Thanks.
  • 06-21-2011 12:58 PM In reply to

    • DaveA
    • Not Ranked
    • Joined on 06-19-2011
    • Posts 3

    Re: How to run .exe file from code?

    Hello, I can't get this script to work for me. I have copied and pasted into the correct place in the VBScript code for a button click. I asm using Infopath 2003. I get the error 'ActiveX cannot create the object:'WScript.Shell' Any ideas?
  • 06-22-2011 12:09 AM In reply to

    Re: How to run .exe file from code?

    Try setting your form's security permissions to Full Trust (Tools->Form Options->Security->...)

    Patrick Halstead
    Project Manager at Qdabra
  • 06-24-2011 02:36 AM In reply to

    • DaveA
    • Not Ranked
    • Joined on 06-19-2011
    • Posts 3

    Re: How to run .exe file from code?

    Thank you - it worked! (simple when you know how...)
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.