I am trying to send keystrokes (TAB) a couple of times within an external window from a vb.net program.
How can I select/activate the window (for example, how would I do it if it's a Word document/ I am actually looking into something a tad more difficult i.e. from SAP, but I will extrapolate from a simpler approach)?
How do I send the TAB key to (or any other key, like an ENTER)?
Extending the first question, how can I select a window that just opened (like a pop-up)?
I have tried using HWND processes but I am getting confused as to which id or parameter to use, etc.
Related
I want to restrict Excel sheet to open only within my organization's network. If my system is connected with company's internet, only then it should get open. If the system is not connected to internet or connected with outside network, it should not get open.
I am using Macro for this. I have used the below code so far, found this on another answer on Stack Overflow. This code is giving same value for a system in different connected network. This will work only if the system is different. but not for different networks.
Option Explicit
Enum COMPUTER_NAME_FORMAT
ComputerNameNetBIOS
ComputerNameDnsHostname
ComputerNameDnsDomain
ComputerNameDnsFullyQualified
ComputerNamePhysicalNetBIOS
ComputerNamePhysicalDnsHostname
ComputerNamePhysicalDnsDomain
ComputerNamePhysicalDnsFullyQualified
End Enum
Declare Function GetComputerNameEx Lib "kernel32" Alias "GetComputerNameExA"
( _
ByVal NameType As COMPUTER_NAME_FORMAT, _
ByVal lpBuffer As String, _
ByRef lpnSize As Long) As Long
Sub test()
Dim buffer As String
Dim size As Long
size = 255
buffer = Space(size)
GetComputerNameEx ComputerNameDnsFullyQualified, buffer, size
Debug.Print Left$(buffer, size)
End Sub
I'll respond even though there was no actual question in your post, and it will probably get closed unless you edit it to add information about a specific programming-related issue, along with examples, detail of what you've tried, and an actual question. (See this and this and this.)
The short answer is:
IT'S NOT POSSIBLE.
Anyone who really wants to access your workbook (or any other Office document) can do a quick Google Search to bypass any security "features" you add.
AUTO_OPEN macros and On Open events can be easily bypassed by holding Shift while opening, or distrusting macros in their Trust Centre. (Here is the first result of a Google search on the topic.)
Passwords can be cracked within minutes using freeware utilities or manually with only a few steps. (See my answer here.)
If the people you are concerned about are not computer-savvy, I suppose you could have the workbook silently notify you of where it's being opened (for example, the IP address or computer name)) but, once again, these could be faked or bypassed altogether.
Assuming the issue is concerns over employees using the workbook (or the data it contains) for "unapproved purposes", the ideal solution would be to either start trusting your staff, or if that's not possible, you need to fire them and find people you do trust.
Edit: Bypassing Workbook_Open
Here's an example of a workbook with a Workbook_Open event, first opened normally, then bypassed by opening the workbook a slightly different way:
Edit: Prevent Any Code From Running
As a developer, I often keep my macro security settings reduced or off. However, a default installation has security turned on, and even if it was disabled, it's not hard to re-enable security in:
File ➡Options ➡Trust Centre
You can't force code to run or bypass security programmatically.
Anything you think you can do or find or do to force code to execute without the user's consent will not work, and at the very least will have a workaround.
Why?
Compare it to Virus Scanner software.
Imagine what would happen if code was able to disable your Virus Scanner? That would make all Virus Scanners absolutely useless, forever. If it were possible, virus creators would be doing it routinely.
The same goes for VBA Macro security options: If it could be bypassed programmatically, the "options" wouldn't have any point and wouldn't even be included. It's not a matter of convenience; it's a matter of security.
How can I communicate between VB.net and GlovePIE?
I know that you can send OSC (Open Sound Control-It isn't just for sound) data in GlovePIE so if you could send/receive data in VB.net without any libraries that would work but I cannot find any resources.
Please post any code that you can.
EDIT: All I want is a basic way to communicate between GlovePIE and VB.net and I found that you could send OSC data in GlovePIE but you cannot in VB.net I would accept any help that I can get. If you have a better method, feel free to tell me. I am using this guide to send the data.
After lots of creative thinking, and hours wasted, I finally came up with an idea. (Thanks to spajce for helping me realize there is no perfect solution, and I had to think outside of the box to make this work.) This is what I am going to do. (I have not written the code yet, but I will try to submit it as soon as I write it.)
How I am going to set it up:
I will have a form in VB.net that will send data to the COM port. It's GUI will have the user select the COM port and have a button to connect.
In my GlovePIE script, I will have it automatically hide itself.
For data transfer to VB.net:
GlovePIE will tell if the form is selected using the Window.Title property. If it is, it will emulate a key press. The form will be looking for the keypress.
For Data Transfer to GlovePIE:
The form will change the Me.text property to something that has happened. For exaple, I'm building a robot and if the ping sensor senses something, my Aduino will send the data over serial, to VB.net, which will change the title to "Robot Connect-OBJECT DETECTED" GlovePIE will know the multiple names the form might be, and when searching to see if it is active, it can tell if something has been detected. VB.net will change the title back to "Robot Connect" after GlovePIE signals it has recived the signal.
There will be some bugs, but VB.net is smart enough to tell if another window is the active one. If you are browsing this question, you may have to adapt this. I will have to put a couple of safety features to prevent the robot from not stopping when the VB.net window loses focus.
Thanks to anbody who tried to help.
What i'm trying to do, is a simple program where i have 2 textboxes, and a button.(there is more but no need to say for resolving my problem)
When i write text in the 1st textbox and click the button, it will be written in the 2nd textbox. Everything is ok here.
Now, when i run this program more than once, i want the text to be written in the 2nd textbox of the others programs.
Sorry for the bad explaination i gave you before, hope it's better :)
OLD DESCRIPTION
i'm actually trying to make a program that works pretty much like a
messenger (basically 2 textboxes, 1 to send, 1 to view, and a button
to send) and i can't figure out how to link the program with itself
(copies). I want it to be able to read the textboxes contained
in the other copies and i don't want it to be 1 program with 2 forms,
but 1 single form, running severeal times (2 or more) How can i
do that? /!\ NOTE : It will be on a single computer, just like 2
forms!
I am assuming you are doing this in WinForms and only running one executable.
Sounds like you you want to create a single instance of a class that is shared between several forms. It should raise an event when the values change. After you create each instance of your form you pass in the class. In the form you would declare it With Events. When one form updates the class it would raise an event notifying the other forms to refresh themselves.
If you are familiar with WPF and MVVM this sort of design would be a little cleaner, but that takes some time to get up to speed on.
This design would not be appropriate if you want to run seperate applications and communicate between them.
You will have to do some kind of IPC, respectively remoting.
You could use:
anonymous pipes
named pipes
UDP
TCP
WCF (would be overkill IMHO)
windows messaging (would be the easiest way)
I’m trying to patch an application that resizes windows using the accessibility API.
I need to maintain a dictionary with the previous sizes of windows. The key needs to identify the currently active window. At the moment, this active window is retrieved via NSAccessibilityFocusedWindowAttribute upon the press of a hotkey.
However, every time this method is called, the returned AXUIElementRef which identifies the window is different! This of course means that I cannot use it as a dictionary key – the dictionary won’t find the corresponding entry.
The following code reproduces the problem:
-(IBAction)testWindowIdentification:(id)sender{
AXUIElementRef focusedApp;
AXUIElementRef focusedWindow;
AXUIElementCopyAttributeValue(_systemWideElement,
(CFStringRef) kAXFocusedApplicationAttribute,
(CFTypeRef*) &focusedApp);
AXUIElementCopyAttributeValue((AXUIElementRef) focusedApp,
(CFStringRef) NSAccessibilityFocusedWindowAttribute,
(CFTypeRef*) &focusedWindow);
CFShow(focusedWindow);
}
_systemWideElement has been initialised in the init method using a call to AXUIElementCreateSystemWide().
The CFShow statement clearly shows different IDs every time the method is called (even though the same window is active), which is useless for me:
<AXUIElement 0x47e850> {pid=42463}
<AXUIElement 0x47e890> {pid=42463}
<AXUIElement 0x47e2c0> {pid=42463}
…
The documentation on AXUIElement shows no method that retrieves a unique attribute for the UI element, and neither does that of the NSAccessibility protocol.
The unique PID is not enough for me, since a process can have multiple windows.
How can I retrieve some unique identifier of the active window in Cocoa?
(By the way, the real code is checking the return codes in the above calls; there is no error, the calls succeed.)
Rob Keniger has the right strategy with his answer here. The only thing missing from this answer (and indeed, the reason for the bounty placement) is a workable implementation that takes the current active window and translates it into a unique key suitable for indexing in the context of the current working application.
Rob's solution sketches this out through use of the CGWindowID given in the context of Quartz Window Services. It is, of course, strongly implied that this window reference is only useful for your current application.
Getting this window reference is tricky, because no strong guarantees exist between the Accessibility API and Quartz Window Services. However, you can work around this in the following ways:
Use extern "C" AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out);, as documented here. This isn't guaranteed to work, but it works as a ground-floor test to get things started if it works in your version of OSX.
Get the CGWindowID directly, using, for example, HIWindowGetCGWindowID(). More details about selecting the active window and extracting the ID can be found in the reference manual for the Carbon Window Manager (warning: large PDF).
Catalog your CGWindowID set using something like CGWindowListCreateDescriptionFromArray, exactly as Rob suggested. The goal here is then to find some scheme for bridging the Accessibility API and Quartz, but this is conceivable by utilizing, for example, a callback bound to the context of your current active window. I honestly don't know an optimal example of this that's properly future-proofed, however.
Of the options, I recommend going with 2. for your current needs, if you're unable to create some other decorator for your windows to uniquely identify them. It's currently defined in the legacy code base, but it will do what you desire.
Best of luck with your application.
I think you might be able to use the Quartz Window Services functions, specifically CGWindowListCreateDescriptionFromArray to enumerate the currently active windows in a particular app.
This call is lower-level than AppKit and isn't going to tell you which is the active window, but it will give you window IDs that are unique for the current user session. It's not a great solution, but you could compare the window bounds information with what you receive from the accessibility APIs to associate windows with their real IDs.
My application needs up to 3 simultaneous download connections. I am currently using a (slightly altered) CWebClient class provided in the Carbide UI framework, however using multiple instances of this for each connection prompts me multiple types to "select access point"
An RSocketServ and an RConnection object exist in the class, these appear to be the things that open the access point. Would it be a good enough solution to make these static objects (singleton) so the access point is only called once?
Any one have any experience/thoughts?
Thanks!
Just in case you wonder, I am using S60 3rd ed. FP2 v1.1
RConnection should be the class that triggers the access point selection dialog.
If you write your own code, get one instance of RSocketServ and 3 instances of RSocket. That should be enough. The access point selection dialog will only occur when the connection is established, which will happen only once until you hit a non-coverage area or your downloads time out.
The other way is to suppress "Select Access Point" dialog. You can do it by using CIntConnectionInitiator to establish a connection. Although this class isn't documented there is a bunch of examples on forum.nokia.com.
Roll your own accesspoint (AP) selector and store the AP ID .
Then use TCommDbConnPref to set AP ID and suppress the dialog.