baffling C# question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    baffling C# question

    I have posted this before, but no one responds, so here
    it goes again. I think my question is intimidating people
    and I have no idea why?!? This is not a new concept. You
    can do this with other programming languages, so why is
    C# so different? Again, here is my baffling C# question.

    I have C# code that opens an application, but right after
    it opens I am confronted by prompts for information
    (i.e. "Please enter your id"). I would like to handle
    these prompts programmaticall y with C#. Is there some C#
    code that passes a value to a prompt and then forces
    the "ok" button?
  • Daniel O'Connell

    #2
    Re: baffling C# question

    It can be done, but i wouldn't use C# for it.
    From waht you are saying, you want to get the windowhandle of the dialog,
    fill in text into a set of textboxes for hte prompt, and hit ok.
    I know of no .NET classes that can do that nativly. You will have to go down
    to the platform invoke level and call win32 functions directly.
    Due to the amount of p\invoke, i'd advise using MC++ and asking in a Win32
    group how exactly to do everything you need to. Such things are really
    beyond the topic here. If you ahve done it before in C++ or delphi or VB6,
    you should have a pretty good idea of what API's you want to call.
    But by using MC++, you should be able to create an assembly that just
    handles that lowerlevel stuff and can be called from C# where the bulk of
    your work can still be done.
    "Mike" <mike@nospamher e.net> wrote in message
    news:0c0d01c36d a6$33b38e70$a00 1280a@phx.gbl.. .[color=blue]
    > I have posted this before, but no one responds, so here
    > it goes again. I think my question is intimidating people
    > and I have no idea why?!? This is not a new concept. You
    > can do this with other programming languages, so why is
    > C# so different? Again, here is my baffling C# question.
    >
    > I have C# code that opens an application, but right after
    > it opens I am confronted by prompts for information
    > (i.e. "Please enter your id"). I would like to handle
    > these prompts programmaticall y with C#. Is there some C#
    > code that passes a value to a prompt and then forces
    > the "ok" button?[/color]


    Comment

    • Val Savvateev

      #3
      Re: baffling C# question

      > I have posted this before, but no one responds, so here[color=blue]
      > it goes again. I think my question is intimidating people
      > and I have no idea why?!? This is not a new concept. You
      > can do this with other programming languages, so why is
      > C# so different?[/color]

      Would you be so kind and give us an example?
      [color=blue]
      > Again, here is my baffling C# question.
      > I have C# code that opens an application, but right after
      > it opens I am confronted by prompts for information
      > (i.e. "Please enter your id").
      > I would like to handle
      > these prompts programmaticall y with C#. Is there some C#
      > code that passes a value to a prompt and then forces
      > the "ok" button?[/color]


      Comment

      • John Timney \(Microsoft MVP\)

        #4
        Re: baffling C# question

        You should be able to send keystrokes uisng the
        System.Windows. Forms.SendKeys class, it ought to be capable of doing most of
        what you need.


        --
        Regards

        John Timney (Microsoft ASP.NET MVP)
        ----------------------------------------------
        <shameless_auth or_plug>
        Professional .NET for Java Developers with C#
        ISBN:1-861007-91-4
        Professional Windows Forms
        ISBN: 1861005547
        Professional JSP 2nd Edition
        ISBN: 1861004958
        Professional JSP
        ISBN: 1861003625
        Beginning JSP Web Development
        ISBN: 1861002092
        </shameless_autho r_plug>
        ----------------------------------------------

        "Mike" <mike@nospamher e.net> wrote in message
        news:0c0d01c36d a6$33b38e70$a00 1280a@phx.gbl.. .[color=blue]
        > I have posted this before, but no one responds, so here
        > it goes again. I think my question is intimidating people
        > and I have no idea why?!? This is not a new concept. You
        > can do this with other programming languages, so why is
        > C# so different? Again, here is my baffling C# question.
        >
        > I have C# code that opens an application, but right after
        > it opens I am confronted by prompts for information
        > (i.e. "Please enter your id"). I would like to handle
        > these prompts programmaticall y with C#. Is there some C#
        > code that passes a value to a prompt and then forces
        > the "ok" button?[/color]


        Comment

        • Mike

          #5
          Re: baffling C# question

          John,

          I tried SendKeys and I was impressed. It's a bit too
          unpredictable for me, but I think it's a step in the
          right direction. At least you understand where I want to
          take this thing.
          [color=blue]
          >-----Original Message-----
          >You should be able to send keystrokes uisng the
          >System.Windows .Forms.SendKeys class, it ought to be[/color]
          capable of doing most of[color=blue]
          >what you need.
          >
          >
          >--
          >Regards
          >
          >John Timney (Microsoft ASP.NET MVP)
          >----------------------------------------------
          ><shameless_aut hor_plug>
          >Professional .NET for Java Developers with C#
          > ISBN:1-861007-91-4
          >Professional Windows Forms
          > ISBN: 1861005547
          >Professional JSP 2nd Edition
          > ISBN: 1861004958
          >Professional JSP
          > ISBN: 1861003625
          >Beginning JSP Web Development
          > ISBN: 1861002092
          ></shameless_autho r_plug>
          >----------------------------------------------
          >
          >"Mike" <mike@nospamher e.net> wrote in message
          >news:0c0d01c36 da6$33b38e70$a0 01280a@phx.gbl. ..[color=green]
          >> I have posted this before, but no one responds, so here
          >> it goes again. I think my question is intimidating[/color][/color]
          people[color=blue][color=green]
          >> and I have no idea why?!? This is not a new concept.[/color][/color]
          You[color=blue][color=green]
          >> can do this with other programming languages, so why is
          >> C# so different? Again, here is my baffling C#[/color][/color]
          question.[color=blue][color=green]
          >>
          >> I have C# code that opens an application, but right[/color][/color]
          after[color=blue][color=green]
          >> it opens I am confronted by prompts for information
          >> (i.e. "Please enter your id"). I would like to handle
          >> these prompts programmaticall y with C#. Is there some[/color][/color]
          C#[color=blue][color=green]
          >> code that passes a value to a prompt and then forces
          >> the "ok" button?[/color]
          >
          >
          >.
          >[/color]

          Comment

          • Jack Spry

            #6
            Re: baffling C# question


            "Mike" <mike@nospamher e.net> wrote in message
            news:0c0d01c36d a6$33b38e70$a00 1280a@phx.gbl.. .[color=blue]
            > I have posted this before, but no one responds, so here
            > it goes again. I think my question is intimidating people
            > and I have no idea why?!? This is not a new concept. You
            > can do this with other programming languages, so why is
            > C# so different? Again, here is my baffling C# question.
            >
            > I have C# code that opens an application, but right after
            > it opens I am confronted by prompts for information
            > (i.e. "Please enter your id"). I would like to handle
            > these prompts programmaticall y with C#. Is there some C#
            > code that passes a value to a prompt and then forces
            > the "ok" button?[/color]

            I have one simple question: Why can't you copy or modify the Access
            report?

            Perhaps there is a good reason, but it mystifies me. You seem to be making
            a mountain of a project out of a molehill of a task.

            Modifying the report is the obvious, simple, straightforward , virtually
            trivial task. Parameter queries can usually be changed in minutes to
            programatic control for providing these values. Using SendKeys, hooks,
            window messages, etc. is the most roundabout way of tackling this problem.

            I may be able to help you with either approach, but I don't want to waste
            the effort of providing the right solution to the wrong problem.


            Comment

            • Chris Hornberger

              #7
              Re: baffling C# question

              Convince us you're not building some bu)(*&# hacker tool or password
              spammer. I've seen several of your posts on this and you've answered
              the questions as to why you want to do this.

              Sorry to be so suspicious, but lately all my problems in coding have
              been 100% because of hackers and the bullshit they cause in added
              layers of extra crap security and such.

              "Mike" <mike@nospamher e.net> wrote in message news:<0c0d01c36 da6$33b38e70$a0 01280a@phx.gbl> ...[color=blue]
              > I have posted this before, but no one responds, so here
              > it goes again. I think my question is intimidating people
              > and I have no idea why?!? This is not a new concept. You
              > can do this with other programming languages, so why is
              > C# so different? Again, here is my baffling C# question.
              >
              > I have C# code that opens an application, but right after
              > it opens I am confronted by prompts for information
              > (i.e. "Please enter your id"). I would like to handle
              > these prompts programmaticall y with C#. Is there some C#
              > code that passes a value to a prompt and then forces
              > the "ok" button?[/color]

              Comment

              • Chris LaJoie

                #8
                Re: baffling C# question

                I know VB6 had a nifty SendKeys("mysec retpassword{ent er}") function. This
                function is available in C# by doing this:

                System.Windows. Forms.SendKeys. Send("mysecretp assword{enter}" );

                Chris LaJoie

                "Mike" <mike@nospamher e.net> wrote in message
                news:005d01c36e 58$d68dcae0$a60 1280a@phx.gbl.. .[color=blue]
                > Excellent question. I'm building a solution to a years-
                > old company procedure, which is "set-in-stone" (for lack
                > of better terminology). This procedure is so ingrained,
                > and the Access application is so widely distributed, that
                > to change any part of the Access portion of it is a big
                > no-no. I agree, changing the Access Report would be a
                > simple solution. But since that is not an option, I have
                > to use C#...which is really not so bad, because I am
                > learning by leaps and bounds about C# and what it is
                > capable of.
                >[color=green]
                > >-----Original Message-----
                > >
                > >"Mike" <mike@nospamher e.net> wrote in message
                > >news:0c0d01c36 da6$33b38e70$a0 01280a@phx.gbl. ..[color=darkred]
                > >> I have posted this before, but no one responds, so here
                > >> it goes again. I think my question is intimidating[/color][/color]
                > people[color=green][color=darkred]
                > >> and I have no idea why?!? This is not a new concept.[/color][/color]
                > You[color=green][color=darkred]
                > >> can do this with other programming languages, so why is
                > >> C# so different? Again, here is my baffling C#[/color][/color]
                > question.[color=green][color=darkred]
                > >>
                > >> I have C# code that opens an application, but right[/color][/color]
                > after[color=green][color=darkred]
                > >> it opens I am confronted by prompts for information
                > >> (i.e. "Please enter your id"). I would like to handle
                > >> these prompts programmaticall y with C#. Is there some[/color][/color]
                > C#[color=green][color=darkred]
                > >> code that passes a value to a prompt and then forces
                > >> the "ok" button?[/color]
                > >
                > >I have one simple question: Why can't you copy or[/color]
                > modify the Access[color=green]
                > >report?
                > >
                > >Perhaps there is a good reason, but it mystifies me.[/color]
                > You seem to be making[color=green]
                > >a mountain of a project out of a molehill of a task.
                > >
                > >Modifying the report is the obvious, simple,[/color]
                > straightforward , virtually[color=green]
                > >trivial task. Parameter queries can usually be changed[/color]
                > in minutes to[color=green]
                > >programatic control for providing these values. Using[/color]
                > SendKeys, hooks,[color=green]
                > >window messages, etc. is the most roundabout way of[/color]
                > tackling this problem.[color=green]
                > >
                > >I may be able to help you with either approach, but I[/color]
                > don't want to waste[color=green]
                > >the effort of providing the right solution to the wrong[/color]
                > problem.[color=green]
                > >
                > >
                > >.
                > >[/color][/color]


                Comment

                • Chris LaJoie

                  #9
                  Re: baffling C# question

                  I have never heard of this problem before. Could you possibly try repeating
                  the SendKeys until it does work? I am aware of a couple APIs that might be
                  of some use. I'll do some research for you.

                  Chris LaJoie

                  "Mike" <mike@nospamher e.net> wrote in message
                  news:035201c36e 5d$a73f6730$a30 1280a@phx.gbl.. .[color=blue]
                  > Chris,
                  >
                  > I like your technique! It's almost exactly what I need! I
                  > say "almost" because sendkeys is still very unreliable.
                  > Sometimes it works, and sometimes it doesn't. When it
                  > works, it works perfectly. When it doesn't work, the text
                  > that is sent sometimes truncates. Sometimes it doesn't go
                  > through at all.
                  >[color=green]
                  > >-----Original Message-----
                  > >I know VB6 had a nifty SendKeys("mysec retpassword[/color]
                  > {enter}") function. This[color=green]
                  > >function is available in C# by doing this:
                  > >
                  > >System.Windows .Forms.SendKeys .Send("mysecret password[/color]
                  > {enter}");[color=green]
                  > >
                  > >Chris LaJoie
                  > >
                  > >"Mike" <mike@nospamher e.net> wrote in message
                  > >news:005d01c36 e58$d68dcae0$a6 01280a@phx.gbl. ..[color=darkred]
                  > >> Excellent question. I'm building a solution to a years-
                  > >> old company procedure, which is "set-in-stone" (for[/color][/color]
                  > lack[color=green][color=darkred]
                  > >> of better terminology). This procedure is so ingrained,
                  > >> and the Access application is so widely distributed,[/color][/color]
                  > that[color=green][color=darkred]
                  > >> to change any part of the Access portion of it is a big
                  > >> no-no. I agree, changing the Access Report would be a
                  > >> simple solution. But since that is not an option, I[/color][/color]
                  > have[color=green][color=darkred]
                  > >> to use C#...which is really not so bad, because I am
                  > >> learning by leaps and bounds about C# and what it is
                  > >> capable of.
                  > >>
                  > >> >-----Original Message-----
                  > >> >
                  > >> >"Mike" <mike@nospamher e.net> wrote in message
                  > >> >news:0c0d01c36 da6$33b38e70$a0 01280a@phx.gbl. ..
                  > >> >> I have posted this before, but no one responds, so[/color][/color]
                  > here[color=green][color=darkred]
                  > >> >> it goes again. I think my question is intimidating
                  > >> people
                  > >> >> and I have no idea why?!? This is not a new concept.
                  > >> You
                  > >> >> can do this with other programming languages, so[/color][/color]
                  > why is[color=green][color=darkred]
                  > >> >> C# so different? Again, here is my baffling C#
                  > >> question.
                  > >> >>
                  > >> >> I have C# code that opens an application, but right
                  > >> after
                  > >> >> it opens I am confronted by prompts for information
                  > >> >> (i.e. "Please enter your id"). I would like to[/color][/color]
                  > handle[color=green][color=darkred]
                  > >> >> these prompts programmaticall y with C#. Is there[/color][/color]
                  > some[color=green][color=darkred]
                  > >> C#
                  > >> >> code that passes a value to a prompt and then forces
                  > >> >> the "ok" button?
                  > >> >
                  > >> >I have one simple question: Why can't you copy or
                  > >> modify the Access
                  > >> >report?
                  > >> >
                  > >> >Perhaps there is a good reason, but it mystifies me.
                  > >> You seem to be making
                  > >> >a mountain of a project out of a molehill of a task.
                  > >> >
                  > >> >Modifying the report is the obvious, simple,
                  > >> straightforward , virtually
                  > >> >trivial task. Parameter queries can usually be[/color][/color]
                  > changed[color=green][color=darkred]
                  > >> in minutes to
                  > >> >programatic control for providing these values. Using
                  > >> SendKeys, hooks,
                  > >> >window messages, etc. is the most roundabout way of
                  > >> tackling this problem.
                  > >> >
                  > >> >I may be able to help you with either approach, but I
                  > >> don't want to waste
                  > >> >the effort of providing the right solution to the[/color][/color]
                  > wrong[color=green][color=darkred]
                  > >> problem.
                  > >> >
                  > >> >
                  > >> >.
                  > >> >[/color]
                  > >
                  > >
                  > >.
                  > >[/color][/color]


                  Comment

                  • Chris LaJoie

                    #10
                    Re: baffling C# question

                    In looking into this I found out that most problems relating to SendKeys had
                    to do with the wrong window being in focus. If you ensure that your access
                    window (or whatever you're using) is the selected window, you should solve
                    all your problems. I found an alternative, the SendKeyboardSta te API in
                    user32.dll, which in my opinion looks like way more trouble than it's worth.
                    But if you want to research it, go for it! :)
                    good luck,

                    Chris LaJoie


                    Comment

                    • Jack Spry

                      #11
                      Re: baffling C# question


                      "Mike" <mike@nospamher e.net> wrote in message
                      news:005d01c36e 58$d68dcae0$a60 1280a@phx.gbl.. .[color=blue]
                      > Excellent question. I'm building a solution to a years-
                      > old company procedure, which is "set-in-stone" (for lack
                      > of better terminology). This procedure is so ingrained,
                      > and the Access application is so widely distributed, that
                      > to change any part of the Access portion of it is a big
                      > no-no. I agree, changing the Access Report would be a
                      > simple solution. But since that is not an option, I have
                      > to use C#...which is really not so bad, because I am
                      > learning by leaps and bounds about C# and what it is
                      > capable of.
                      >[/color]

                      Sorry for continuing to pursue this thread, even though the decision itself
                      may not be within your control, however I can't help but question the
                      fundamental choice to dismiss the most obvious solution for some half baked
                      approach.

                      While learning C# may benefit you, it doesn't directly benefit the users at
                      all.

                      Why is distributing a new version of the report is more difficult to
                      distribute than your C# solution? The new report need not replace the
                      current one, so I don't see how having an additional report listed will
                      cause any problems whatsoever. The entire process of adding the report to
                      their existing Access application can be completely automated with a
                      installation tool. You don't need to redistribute the entire Access
                      database and all that it contains: no tables, forms, or other structures
                      besides the report itself need to be sent or modified. The end result will
                      be just one more Access report listed with a name of your choosing that can
                      reflect why and how it exists. I can't see how that will be much of a
                      problem..

                      If the process is so ingrained, you're still modifying it one way or
                      another, regardless of the programming tool used or how it's distributed.
                      Somehow they're going to need to run your C# app, and I'll bet it will be
                      more difficult to learn and use than choosing a different report in Access.

                      If you've read this far into my reply, I'll make it worth your while to bear
                      with me on this point.

                      The direct solution to your problem is to not rely on Sendkeys or the focus
                      state of that window. The only reliable means is to get the windows handle
                      (hWnd) of that window and the controls used so that you can send windows
                      messages to them directly using the Win32 API. There are tools to inspect
                      the window properties of applications at runtime, and these tools use
                      published APIs to track down any window created using the standard API.
                      Therefore, this technique is complex, but well-known and understood by those
                      of us who know the Win32 API. To learn how to use this approach is a rather
                      advanced for a novice, because there's no shortcuts to learning the Win32
                      API. There are tools that can help such as Spy++ and pview (VS6), but you
                      still need to understand what's going on at the API level to make much use
                      of them.

                      Daniel Appleman's Spyworks is great product that has rolled up many of these
                      APIs into components. While this product was originally designed for VB
                      programmers, it has been updated for dotnet.

                      His site and his books contain some of the best available info for Windows
                      programming on the net.




                      Comment

                      • Chris Hornberger

                        #12
                        Re: baffling C# question

                        Hey, I only said that because I've seen you cross post this alot and
                        never answer any questions back at you, that's all.

                        "Mike" <mike@nospamher e.net> wrote in message news:<01ab01c36 e59$a7c24fa0$a4 01280a@phx.gbl> ...[color=blue]
                        > Convince you? I think not. I have a legitimate
                        > programming question regarding Access reports which I
                        > have already explained in detail through multiple posts.
                        > If you want to live in fear of my "oh-so-scary" Access
                        > application, then that's your choice.
                        >[/color]

                        Comment

                        • Drebin

                          #13
                          Re: baffling C# question

                          Mike still hasn't solved this yet??

                          I really think you are barking up the wrong tree.. Access (even with new
                          fancy bells/whistles) - is a nasty, nasty legacy app.. you are better of
                          using legacy tools.. or migrating off Access.. To try to mix the two will
                          probably end up being a mess. Whip up a VB6 app with DAO and that should get
                          you fixed up..



                          "Chris Hornberger" <chris@chornbe. com> wrote in message
                          news:53ec8913.0 308291703.b99e3 4e@posting.goog le.com...[color=blue]
                          > Hey, I only said that because I've seen you cross post this alot and
                          > never answer any questions back at you, that's all.
                          >
                          > "Mike" <mike@nospamher e.net> wrote in message[/color]
                          news:<01ab01c36 e59$a7c24fa0$a4 01280a@phx.gbl> ...[color=blue][color=green]
                          > > Convince you? I think not. I have a legitimate
                          > > programming question regarding Access reports which I
                          > > have already explained in detail through multiple posts.
                          > > If you want to live in fear of my "oh-so-scary" Access
                          > > application, then that's your choice.
                          > >[/color][/color]


                          Comment

                          Working...