How to restrict icon handler to be accessed by a particular process? - com

I have a icon handler for my custom file. How I can restrict icon handler functionality so that it can be called by explorer.exe threads only?

Well, you could use GetModuleFileName(NULL) to find out which EXE your handler is loaded into. You could do that in a COM method (and return, say, E_FAIL if you think are in a wrong process), or in DllMain so that your handler fails to even load.
However, it's not clear why you would want to do this. For example, an icon handler is used by the standard Open File dialog in any application; do you not want your icon to appear there?
If you envision this as some kind of a security measure, then it won't work very well. A determined attacker would write their own shell extension, get loaded into Explorer, and access your handler from there.

Related

Cannot click on specified element on UI-Windows Tree using G1ANT Robot

I'm trying to use UI addon command-click. After looking for an element in windows tree I decided to use that tool to choose a specific button, which opens in the dialog window on my desktop application. Unfortunately, it wasn't working in the main script -> sometimes it clicked, but not on the button itself, it chose the point outside of the dialog box. The tricky part is that line worked, but in different robot file, I placed only one line, exactly the same and it used to work. Today none of the above works...
The error it's giving me sounds like this: "Access denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)" do somebody knows how to make it work properly?
I tried switching on/off addons, focusing on different windows, different delays, changing scaling from windows side, etc.
The line I'm using: ui.click wpath "path to element from UI tree"
Also, res. of the screen is 1920x1080p
I can use image recognition on that part of my script, but if it's in the UI windows tree it should work correctly right?
The path could change, check whether you use any properties that could be dynamic (like #id). Consider using keyboard command if the button is focusable or has assigned a keyboard shortcut.

VB.Net What Event is Triggered When Double-Clicking to Open Custom File?

I have created a custom file type that is recognized by my application, and I would like to know what event is triggered when I open my application by double-clicking a file of this type. I have placed breakpoints at the beginning of handlers for Form.Shown and Form.Load, as well as at the beginning of the form's constructor, but the application never hits the breakpoints.
If you're opening the application by double-clicking on the file in your computer's filesystem the debugger built in to Visual Studio won't be attached to the application's process and so won't break at your breakpoints. You can attach the debugger to a running process, but what you're talking about happens fairly quickly, so you will almost certainly not be able to attach to the process fast enough to set your breakpoints and catch the execution as it passes them.
Ultimately, the events triggered when you open your application via a file association is no different to opening the application by running its executable file.
For using that file :
Just get your file from commandline args and process it on which event you want. My.Application.CommandLineArgs
After this if you want to debug:
You can put that arguments inside Properties-Debug- Start Options -Commandline arguments (argument will be your file)
and put breakpoint on the event where you were processing that file
Happy debuggings
If you're creating your program as a Single Instance Application, then you'll receive the Startup event for your first instance, and the StartupNextInstance event for each subsequent invocation.
Each of these events hangs off of My.Application and provides the command line parameters that were passed to each invocation.
If you're not using a Single Instance Application, the Startup event is still available.

how to click on WebArea from QTP ?

In My test I want to click on object of Type WebArea which opens a webelement popup includes some fields that i need to test.
the problem that the popup not open after I click on WebArea object through the code.
the code I use as below.
Browser("WW").page("assessment").WebArea("areaassessment").Click
nothing hapens after the above line excuted.
Look into the HTML of the WebArea and see what action is triggering the popup. Normally it has something like onclick='showPopup();', but in other cases it is onmousedown or onmouseup.
If this is the case, you have to setup QTP accordingly. There are multiple roads to walk here, one is to see how you advanced web settings are configured. Go to Tools>Options>Web>Advanced and look in the Run Settings.
Setting the Replay Type to Event will replay your scripts by events (by default mousedown, mouseup and then mouseclick) or by mouse (You'll see your mouse pointer moving in this mode, QTP will replay by sending WM_* messages through the Windows api for movement to the correct screenlocation and triggering the click).
Allthough it replays a bit faster, if Run only click is checked, it is better to uncheck this to trigger all events / messages.
Events can also be fired by the FireEvent method:
Browser("WW").page("assessment").WebArea("areaassessment").FireEvent("onclick")
or through the object native methods:
call Browser("WW").page("assessment").WebArea("areaassessment").Object.click()
call Browser("WW").page("assessment").WebArea("areaassessment").Object.FireEvent("onclick")
As #AutomateChaos said there is probably an event that QTP isn't simulating, one way to work around this is to do as #AutomateChaos suggests and simulate the needed event. A simpler way is to change to device replay (as I described here and here).

How to emulate mouse clicking/mouse moving/key typing in the global context?

Emulate means to invoke these events programatically.
Global context means that these event invocations should affect the whole desktop (sort of global environment) rather than the application which produces them. Moreover, the application itself should have no windows - it has to simply execute in background and produce these events due to some logic. In other words, if, for example, this application puts mouse in "global" arbitrary position and invokes a double click event and there is an icon of some other application under the cursor then this "other" application should start.
Which library can I use to achieve it?
Note: I don't specify OS since I hope that the library is supposed to do it in a cross-platform way. If that's not possible then I will be fine with the Windows only solution.
I found out that Java's java.awt.Robot has all requested features.

How can I navigate to different webpages in the same MSIE window in VB.NET

I have code that opens a new window but I want to be able to edit the same one.
System.Diagnostics.Process.Start("iexplore.exe", "http://www.live.com")
I'm not sure exactly but a good pointer to start off might be to get the handle of the window you're interested in:
http://www.pocketpcdn.com/articles/dotnetcf_hwnd.html
And then separately investigate what interop messages you can send to IE to change the URL in tab X
In order of increasing difficulty and increased control/power:
Send input text to your IE process. Alt-D to focus on the navigation bar, then the URL, then ENTER.
Use MSAA to find the navigation bar and send it text, as above.
Use MSAA to get IHTMLDocument access to the browser, and then programmatically drive the browser with that, and the related interfaces.
I don't know your exact scenario, but if you can host your own instance of MSHTML, or a WebBrowser control, it will make it a lot easier to get the interfaces and do the manipulations mentioned in #3 above; doing that stuff cross-process is fraught with peril.
I just did a web search and turned up a WatiN tool that apparently wraps a lot of this work; perhaps it would be useful for you.
If you are using 2008 there is a feature where you could create a second form and then add a Webbrowser control
the page could then be called by
myForm.show
The page could then be changed with the
Webbrowser1.Url = New Uri("http://www.google.com")
Use the following code:
System.Diagnostics.Process.Start("http://www.live.com")
That is: do not invoke iexplore.exe directly – just let the system figure out which default browser to open.
This may yield two behaviours:
Either it opens a new tab in an existing Internet Explorer window,
or it creates a new window.
The important point is that this depends on a preference that can be controlled within the Internet Explorer application. If a new window opens, then this is the setting chosen by the user – do not try to override it: overriding the user’s preferences is considered bad manners.
If the users don’t want a new window opened, they can simply change that in their Internet Explorer preferences.