Assigning a button on Infopath form to execute an exe on local drive - InfoPath Dev
in

InfoPath Dev

Assigning a button on Infopath form to execute an exe on local drive

Last post 01-18-2013 08:23 AM by Hilary Stoupa. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-17-2013 08:44 PM

    Assigning a button on Infopath form to execute an exe on local drive

    I am new at this so try not to laugh too hard if you find my ignorance amusing.

    I've been teaching for 30 years and I have observed that one of the toughest obstacles for a student to overcome is others laughng at a sincere question. So please be kind. i realize there are MANY of you out there who are much smarter than I in this area. I'm OK with that. I'm a humble guy.   :-)

    I am trying to run a program via a button in an InfoPath form.

    I have set security to Full Trust.

    I have added Reference... Windows Script Host Object Model

    the button code is as follows:

    Public Sub CTRL1_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    Dim WshShell As IWshRuntimeLibrary.IWshShell

    Dim CreateObject

    WshShell = Createobject("WScript.Shell")

    WshShell.Run("c:\icmxfer.exe")

    End Sub

    I have no errors reported in the code windows I was getting an error before I added the "Dim CreateObject"

    Error 1 Name 'Createobject' is not declared. C:\VB4InfoPath\test456\FormCode.vb 34 24 test456
    I realize what I have done is probably bogus but I am not familiar enough (yet) with the appropriate way to code this.

    I do have 2 warnings:

    Warning 1 Variable declaration without an 'As' clause; type of Object assumed. C:\VB4InfoPath\test456\FormCode.vb 33 17 test456
    Warning 2 Variable 'CreateObject' is used before it has been assigned a value. A null reference exception could result at runtime. C:\VB4InfoPath\test456\FormCode.vb 34 24 test456

    I am getting the following errors when I test the button.

    System.NullReferenceException
    Object variable or With block variable not set.
       at Microsoft.VisualBasic.CompilerServices.Symbols.Container..ctor(Object Instance)
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.InternalLateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames, Boolean ReportErrors, ResolutionFailure& Failure)
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames)
       at test456.FormCode.CTRL1_5_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

    DMN
  • 01-18-2013 01:21 AM In reply to

    Re: Assigning a button on Infopath form to execute an exe on local drive

    Try using different names when declaring variables.
  • 01-18-2013 05:52 AM In reply to

    Re: Assigning a button on Infopath form to execute an exe on local drive

    thanks for the reply. I'm not sure what you are suggesting specifically, and/or how/why that would help.

    Have you ever been able to get something like this to function effectively? If so, how did you proceed? What was the code used and related configuration parameters?

    Thanks again for your quick reply.

    DMN
  • 01-18-2013 08:23 AM In reply to

    Re: Assigning a button on Infopath form to execute an exe on local drive

    Hi - couple of things - do you know how to run your project in debug so you can see what is happening in your code when it executes? Here's my blog on that, and here's an MSDN article.

    Second, I'm wondering if you could just use Process.Start - You'll find examples here.

    Hilary Stoupa

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.