Announcement

Collapse
No announcement yet.

Remote Script Requests and Help

Collapse
This topic is closed.
X
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #91
    Try this one:

    Code:
    #USING System.Diagnostics
    #USING System.Threading
    #USING System.Runtime.InteropServices
    
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);
    
    void Main( object param )
    {
      if( sh.GetContext( "Toshiba Network Camera" ) == null )
      {
        sh.SetContext( "Toshiba Network Camera", true );
        IntPtr hWnd = FindWindow(null,"Bellwoods1 (VGA) TOSHIBA Network Camera - IK-WB15A. - Windows Internet Explorer");
        if( hWnd == IntPtr.Zero )
        {
          ProcessStartInfo processStartInfo = new ProcessStartInfo();
          processStartInfo.FileName = "IEXPLORE.EXE";
          processStartInfo.Arguments = param.ToString();
          processStartInfo.WindowStyle = ProcessWindowStyle.Maximized;
          Process.Start( processStartInfo );
          Thread.Sleep( 3000 ); 
        }
        else
        {
          SetForegroundWindow( hWnd );
        }
        sh.SetContext( "Toshiba Network Camera", null );
      }
    }
    --
    stipus

    Comment


      #92
      Still struggling

      Thanks VERY MUCH for your sample script to open or focus an application on a remote computer. Unfortunately I can't get it to work properly. Even if I just use calc.exe, it will try to maximize the width on the second call, and won't bring it to the foreground.

      The application I'm trying to run is even a bit more complicated because it requires its own parameter, which is included in a shortcut that I use to run it. I can set this up with a shortcut, but the script won't be able to detect the program running because it's looking to see (i presume) if the shortcut is running, which it would not be. So it would work, but if it was already running it would bring up a second (then third, etc.) copy of the application.

      I do have a simple VBS script that I found that will at least bring an application to the foreground assuming it's not minimized and that it's already running. Worst case, I can try to ensure that the application is always running and not minimized, and this will always bring it to the foreground:

      Option Explicit
      Const Title = "NetVu ObserVer"
      Dim Wsh
      Set Wsh = WScript.CreateObject("WScript.Shell")
      Wsh.AppActivate Title

      The problem is that I can't get the script client to recognize it since it's a .vbs file. Can you tell me what I need to to in order to be able to execute this script?

      Thanks again.

      Randy

      Comment


        #93
        Run or switch to an IE tab

        I didn't have any luck running an application from a script (I'm still hoping for your input), but it turns out that I can also view my cameras via an IE tab. So I tried running the above script (the one submitted by rsisson and revised by stipus), replacing the Panasonic info with the description from my appropriate browser tab ("Digital Sprite 2 - Dedicated Micros - Internet Explorer").

        I had to disable UAC and change the speaker client "scripts" directory attribute in order to allow it to write a temp file (noted in case others have this same problem,) but once I got the script running, it simply brings up a new instance of IE and the home page tab (even though I already had IE running and the tab I was hoping to focus on was loaded but not the one that had the focus.)

        Do I need to pass it a parameter? It seemed like the description was hard-coded into the script...

        Thanks.

        Randy

        Comment


          #94
          I tested the script with notepad.exe and it worked well...
          I just tested with calc.exe .. and you are right: it doesn't work. I still don't understand why.

          If you want to add program arguments, you can add a line at the end of the script processStartInfo.Arguments = "program arguments here";

          Code:
              else
              {
                 ProcessStartInfo processStartInfo = new ProcessStartInfo();
                 processStartInfo.FileName = param.ToString();
          [B]       processStartInfo.Arguments = "";[/B]
                 Process.Start( processStartInfo ); 
              }
          I'm still trying to get calc.exe brought to foreground...
          --
          stipus

          Comment


            #95
            I have been trying your method with calc.exe

            Code:
            Option Explicit
            Const Title = "NetVu ObserVer"
            Dim Wsh
            Set Wsh = WScript.CreateObject("WScript.Shell")
            Wsh.AppActivate Title
            ... and this also didn't work

            I'm getting the same behavior as my method: The second time I get the calculator flashing in the Start Menu bar, but it's not brought to foreground...
            --
            stipus

            Comment


              #96
              This new script works well on my computer, and brings any application (including calc.exe) to the foreground, even if minimized.
              Attached Files
              --
              stipus

              Comment


                #97
                New version of activateapp.cs

                Thanks for the revision to activateapp.cs, Stipus. I'm still having trouble, probably because the application I'm running seems to be triggering a secondary application (although there is only one .exe.) The filename is NetVu ObserVer.exe, and the description in the upper-left corner of the application when it's running is also "NetVu ObserVer." However when I run it (using a shortcut, in order to pass it the parameters it needs) it displays a window called "Launcher" and *then* a new window called "NetVu ObserVer", and then Launcher goes away and leaves NetVu ObserVer running.

                It isn't very important to run the program if it isn't already running, because I normally have it running 24x7 anyway. However I do need a way to restore it if it has been minimized, and push it to the foreground.

                I know a little VB but I've never used any form of c programming and I'm not familiar with how to use the Windows environment in code, so it's a bit of a challenge for me to figure out how your code is working. Can you advise how I might be able to simply hard-code the process name right into the script file, and not even bother passing the name of the program or parameters? How can I determine the name that your script is looking for (i.e. the name of the application that is running), and how to insert it into your code?

                If I run Task Manager, the application list simply shows "NetVu ObserVer" for that program. Can I simply plug that into your script at some point?

                Thanks again for going over the top to help me ;-)

                Randy

                Comment


                  #98
                  You need to find the right process name in the process tab of the task manager.
                  --
                  stipus

                  Comment


                    #99
                    Run or switch to an IE tab

                    I've been trying to run the script that runs IE or switches to the appropriate IE tab if it's already open. I can get it to open a new instance of IE and load the correct page, but if IE is already open, even if the current tab is already set to the one I want, I can't get it to work -- it always wants to open a new instance of IE, never recognizing that IE is already open, whether the tab I want has been loaded or not, or whether it is the selected tab or not.

                    Can someone give me a clue as to why the script is not detecting that IE is already running and that there is already a tab (may not be the selected tab) that has the URL I'm looking for?

                    Here's what I've got:

                    Remote computer: *
                    Remote script: remote_digitalsprite2.cs
                    Parameter: http://192.168.1.179/webpages/live.shtml

                    In the script itself, I have tried all of the following:

                    IntPtr hWnd = FindWindow(null,"Digital Sprite 2 - Dedicated Micros - Windows Internet Explorer");

                    IntPtr hWnd = FindWindow(null,"Digital Sprite 2");

                    IntPtr hWnd = FindWindow(null,"http://192.168.1.179/webpages/live.shtml - Windows Internet Explorer");

                    Suggestions appreciated. Thanks.

                    Randy

                    Comment


                      Originally posted by stipus View Post
                      You need to find the right process name in the process tab of the task manager.
                      The Task Manager *application* description is simply "NetVu ObserVer". On the Process tab, it lists only .exe files, and the only .exe file in the program directory for that application is NetVu ObserVer.exe.

                      There are a lot of processes in the Processes tab, but none of them are obviously associated with this program. When I run the application, the only additional Process is called "javaw.exe" Java(TM) Platform SE binary.

                      Is that helpful?

                      Randy

                      Comment


                        Want to send keystrokes to another program not focused. Can this be done with script connector? Its' for iTunes.
                        oops! sent you an pm and had not submit the reply

                        Comment


                          Using Script Connector to bring up an IE tab

                          Can Stipus or anybody offer any insight as to why I can't get my script working, per my message below?

                          Thanks!

                          Originally posted by rpeck View Post
                          I've been trying to run the script that runs IE or switches to the appropriate IE tab if it's already open. I can get it to open a new instance of IE and load the correct page, but if IE is already open, even if the current tab is already set to the one I want, I can't get it to work -- it always wants to open a new instance of IE, never recognizing that IE is already open, whether the tab I want has been loaded or not, or whether it is the selected tab or not.

                          Can someone give me a clue as to why the script is not detecting that IE is already running and that there is already a tab (may not be the selected tab) that has the URL I'm looking for?

                          Here's what I've got:

                          Remote computer: *
                          Remote script: remote_digitalsprite2.cs
                          Parameter: http://192.168.1.179/webpages/live.shtml

                          In the script itself, I have tried all of the following:

                          IntPtr hWnd = FindWindow(null,"Digital Sprite 2 - Dedicated Micros - Windows Internet Explorer");

                          IntPtr hWnd = FindWindow(null,"Digital Sprite 2");

                          IntPtr hWnd = FindWindow(null,"http://192.168.1.179/webpages/live.shtml - Windows Internet Explorer");

                          Suggestions appreciated. Thanks.

                          Randy

                          Comment


                            Running an application using Script Connector

                            Likewise, can Stipus or anyone offer suggestions on how I can get the script to recognize that my application is already running, and switch to it (my question is repeated below)?

                            Or, can anyone at least advise how I can get the following script (which runs fine stand-alone on the client) to work with Script Connector:

                            Option Explicit
                            Const Title = "NetVu ObserVer"
                            Dim Wsh
                            Set Wsh = WScript.CreateObject("WScript.Shell")
                            Wsh.AppActivate Title

                            Thanks.

                            Randy

                            Originally posted by rpeck View Post
                            The Task Manager *application* description is simply "NetVu ObserVer". On the Process tab, it lists only .exe files, and the only .exe file in the program directory for that application is NetVu ObserVer.exe.

                            There are a lot of processes in the Processes tab, but none of them are obviously associated with this program. When I run the application, the only additional Process is called "javaw.exe" Java(TM) Platform SE binary.

                            Is that helpful?

                            Randy

                            Comment


                              Here is another script: remote_activatewindow.cs

                              Set the script parameter to the Window name you want to activate.

                              I tested with a few apps including calc.exe (script param="Calculatrice" here in France) and it worked well.
                              Attached Files
                              --
                              stipus

                              Comment


                                Originally posted by lunkan View Post
                                Want to send keystrokes to another program not focused. Can this be done with script connector? Its' for iTunes.
                                oops! sent you an pm and had not submit the reply
                                I think it can be done by combining one of the scripts that activates a window and the script to send keystrokes.

                                Another solution would be to use the FindWindow() API to find the right window, then the PostMessage() API to post WM_KEYDOWN,WM_KEYUP and/or WM_CHAR messages. This has a good chance to work.
                                --
                                stipus

                                Comment

                                Working...
                                X