I have a situation which would be easily solved if we were using android as originally designed (and partially coded). Unfortunately, we're going the MS C++ on Windows Enterprise route because of some vital legacy applications. Basically we're coding a launcher that needs to start an application and when that application is closed, the user is brought back to the previous application (the one that launched the 2nd application). I hope that makes sense.
I know this can be done because I vaguely recall an application I used in college for taking exams did something like this, but when I do a search all I get are android solutions. Any help or links to libraries to look at will be wonderful.
there are may ways here are 2 most obvious:
most easy and safe way is that launched application send message to launcher that it is closing
but you need to add code to that application
you can use windows messaging or mailbox or semaphores or whatever else.
launcher periodically checks if there is active window handle of the right class/type/GUID.
if not then pop up the restore/maximize or visibility and set focus to it self.
you need to know what class is that app of yours
of course if there are more apps of the same class/id/type/GUID this way you cannot know which one is which
Related
I am making an app for my cousin that blocks apps at certain times of the day. I am trying to setup an easy gui based approach to block apps that is intuitive and easy to use. I get all of the apps from the start menu folders, then get their corresponding executables, and then put them in a grid list so that from the apps user interface, the user can add app and remove applications easily.
Unfortunately, some apps aren’t quite so easy… If an app has an updater app for it, most often, the shortcut in the start menu will refer the the updater app, then the updater will check for updates, apply updates, then run the program. But with my system, it would automatically pick up the updater program as the blocked app, not the actual app. That’s why I want to be able to see what program started another program. Then I can see if a program was started by the updater, then I will know that it is part of the app too, and I should block that app aswell.
I am pretty sure that this is possible, but I don’t know how to do this in rust. This forum says it should be possible: https://superuser.com/questions/541210/find-what-process-started-another-process.
The sysinfo crate should be helpful here - if you know the name of the app you want to block, you can use the list of all processes to find the process you want to block and find its parent process. You may have to repeat this traversal a few times to find the original launching process, but be wary about what process are blocking - you may find your way back to an OS/root process which you definitely don't want to block.
OK, it might be a problem with my system but I'm having a very difficult time getting Windows 7 to recognize my custom exe as the default handler of the mailto protocol.
First, I've seen this:
Register Windows program with the mailto protocol programmatically
Next, I've seen these:
How to Register an Internet Browser or Email Client With the Windows Start Menu
Registering an Application to a URL Protocol
I've added what seemed the appropriate registry entries but I still get Windows Live Mail coming up every time I click a mailto link (whether in a browser or via the Run window). I've set the registry entries for all users and for the current user, still it doesn't work.
When I go to the 'default programs' app and scroll down to the mailto protocol, I only see Outlook and Windows Live Mail listed. My custom app doesn't even appear.
I figure that it's either something special with Windows 7 or it's something with my computer.
My custom app is a WinForms .Net app but I don't think that matters.
Any ideas are greatly welcome.
The way described in the answer which you referenced in your question seems correct way for Windows 7 as for other operation systems.
I suppose that you use 64-bit version of Windows 7 and your program is 32-bit application. So if your application write in the HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\shell\open\command key it modifies only the key HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\mailto\shell\open\command used for 32-bit applications. You can read more about registry virtualisation here and here.
If it's your case you can call directly native Win32 API RegOpenKeyEx with the KEY_WOW64_64KEY flag which will be ignored on 32-bit operation system.
Though a pretty late answer, what worked out for me is this: On regedit, this supersedes the registry keys mentioned in other answers:
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\URLAssociations\MAILTO\Userchoice
Have a look at this page:
Default Mailto Registry
How can I add a custom url handler on Windows. Like iTunes itms:// Related but not.
This seems like a very high-nerd-level context to a fairly common problem. As a nerd, I'm swept up by the discourse on 64 vs x86 and the pseudo-universal binary aspects of .net. But the tech support troubleshooter in me can't help but think that the core problem needs to be made plain and addressed systematically...
So your real problem, regardless of the mail client (as you said yourself), and regardless of your CPU, is that you can't get your mail client to be the default protocol handler for mailto. Or to make it really simple, you can't get the program you like to be the default program.
I'm inclined to think that the 64/86 aspects of the problem are not relevant. They are interesting, and possibly having some effect, but if the program is running just fine (no issues with the code in that architecture, etc), and if it does email just fine (emails get send and received, all SMTP and IMAP all the way), then I doubt the OS is plotting to keep the client from taking over as the leader of the porch dogs.
If anything, I would say that the client had self-esteem issues and is afraid to be the mailto protocol handler. Most clients can't resist asking if the should be the primary and if you say yes, they pass the word along to the other apps and to the registry. They make sure everyone knows they are the new Mailbox king in the house.
So, what I would try first (basic troubleshooting): install another mail client and see if it has the same issue. If it does, your OS is a bully and you'll want to explore such routes.
But if this other client can get into the default programs club and be made the mailto handler, then the problem is with your app. It's a big wimp that doesn't know how to properly assert himself.
But like so many underdogs waiting for a cool kid to take them under their wing (and by wing, I mean Thunderbird. Don't bother with any other client), your app can stand on the shoulders of the working third-party client.
We have to assume that Thunderbird did at least one and possibly two things that your app didn't do. The first was getting it's name tied to the protocol in the registry. Go poke around and see if you can find his name and how it's associated to the mailto protocol. Chances are good that you can swap out his name for yours, or at the very least try to pin the protocol to you as well.
The second thing that T-Bird may have done was get himself in the "Default Programs" list (a feature of 7 that I didn't really like, because it had a cool concept behind it -- ie, let's group apps together up front rather than wait and see every time if one of them can do a similar job. But Windows screwed that good time (big surprise) by acting like the overprotective parent it always is, and showing up at the kids' party and saying "I think these two should be in this group, don't you?"
Well, my hope is that by getting access to the mailto by borrowing it from Thunderbird, that you'll be welcomed into the default programs club, but if you aren't and you are still the mailto handler, I'd write it off, at least gloat about it for a week or two, before trying to tackle that issue.
Now, if Thunderbird can't get mailto control, I'm very inclined to think that Windows 7 as actually put in to place some sort of strange caste system, where the application and it's installer (eg user) must some how prove their worthiness to be in the group by figuring out what the big secret is.
Oh, and if all else fails, try restarting in Safe Mode with no networking, install your client in that environment, and starting it up. See if you can't make it the default while the others are in suspended animation. Do a test run (with no network, obviously) by writing a basic HTML page with a mailto and see if clicking on it opens your client.
THen cross your fingers when you start back up in normal mode.
Let me know if any of the above proved the least bit helpful.
I have run into a case where a Windows Form application is being run regularly via a scheduled task on a Windows Server 2003 box. The GUI is, obviously, not being used to take in any user input, so it is at best pointless. But is it also dangerous? Could it cause anything to go pop on the box?
It should not really harm.
You may want to create a standard shortcut to the application then in "properties" select the "Run" -> "Minimized" option.
Don't forget to point the task sceduler to execute the new shortcut rather than the direct application.
The GUI is, obviously, not being used
to take in any user input, so it is at
best pointless.
Just because it doesn't take input doesn't mean it does nothing. While the GUI part of it is probably pointless, the application execution itself may not be.
A Windows Form application being run regularly is the same as any other process being run regularly, and it may have been for whatever reason that the developer of the app wanted a GUI to appear while it was doing its thing or may have had plans to allow users to interrupt the running process through the GUI.
The developer may even be using a GUI control for application execution. A "good" example of this would be using a web rendering control for its DOM processing capabilities.
Could it cause anything to go pop on
the box?
If it doesn't correctly dispose of any resources it uses then yes.
I wouldn't imagine GUI apps are any more notorious than console apps for this, but the fact that someone perhaps unnecessarily used a GUI app (maybe they had only been introduced to WinForms projects) is a strong indicator to check the code and make sure all appropriate resources are being disposed of correctly (think 'using' blocks).
We're starting a new custom project right now from a client and one of the requirements is the process cannot be terminated unless the system is shutting down, restarting, or logging-off.
This application monitors the USB interface. We will be using WMI to query the device periodically.
The client want's to run the application on Windows XP Operating System and doesn't like installing .NET. So we targeted Visual Basic 6 as our language.
My main concern is this application cannot be terminated. Our Project Adviser talks about Anti-virus and yes, some of the anti virus cannot be terminated. I was thinking how to do the same in Visual Basic 6. I know there will be API involved on the project but where should I go? so API is ok with me.
I saw some articles that converts the EXE to a SERVICE, create Windows Service in Visual Basic 6, etc.
So please .. share your thoughts.
If you want to be evil, you can call the (officially) undocumented RtlSetProcessIsCritical NTDLL function. This will immediately BSOD the machine if your process is terminated.
You cannot create a process that cannot be terminated without some sort of kernel-mode hooking, which involves writing a driver. You might want to look into Rootkits: subverting the Windows kernel if you're interested in that. However, even with kernel-mode hooking there are still numerous ways to terminate processes. The alternative is to use user-mode hooking, easily bypassed but enough for very simple projects.
The solution you want to use will depend on how far you want to go with the termination protection. And even if you do succeed in preventing process termination, there may be ways of preventing your application from working properly - e.g. killing the WMI service.
I think you want to look at writing an NT Service.
More info here: http://www.montgomerysoftware.com/CreatinganNTServiceinVisualBasic6/tabid/161/language/en-US/Default.aspxlink text
It's really frustrating coding in VB6 right now specially I dumped my head in C# for 2 years though I coded in VB6 for 5 years..
Moving back is a pain as if I am starting a new programming language.
To be honest, you are trying to do something in VB6 that it really isn't that great at.
When you say 'cannot be terminated' - what do you mean by that? There are several levels there:
a) App shows a window but the user cannot close it with the X button, or it does not show one
b) App shows no windows or maybe sits in task tray
c) App shows no windows and cannot be shut down from the Applications tab of task manager
d) App cannot be shut down from the process list of task manager
(a) and (b) are probably easiest to do in straight VB. (c) is still possible, but getting uglier. (d) gets you into hack territory and would almost certainly be frownd upon if you did manage it.
If you really need to stop users closing then you can probably hack it to a greater or lesser degree, but the real answer is as the others have said - a system service (this is exactly the srt of thing they were intended for). However that is one thing that VB6 isn't good at so the best solution to your problem is c#.
Is it possible to create an "application group" which would run under one window, but in separate processes, like in Chrome browser? I'd like to divide one application into multiple parts, so that one crashing or jamming process cannot take down others, but still keep the look and feel as close to original system as possible.
I know the Chrome source is available, but is there anything even half ready made for Delphi?
I guess basically you would create multiple processes each of which creates a window/form. One of the processes has the master window in which every child window is embedded. That is as simple as calling SetParent. The windows in different processes would talk to each other using an IPC (Inter Process Communication) mechanism like named pipes or window messages.
See this question for an embedding example of using SetParent in Delphi. See this question for an example of using named pipes in Delphi.
Have a look at the Delphi code of HeidiSQL. It's a great open source MySQL client that implements this mechanism.
Read this newsitem that was posted when Chrome was released:
"Google playing catch-up with HeidiSQL?"
:-)
(source: heidisql.com)
Have a look at : http://blogs.microsoft.co.il/blogs/maxim/archive/2008/09/23/curiosity-killed-the-programmer-multiprocess-browser.aspx . The source of the app is in CSharp. I'm sure you can adapt it to Delphi.
Harriv, you can use a scheme based on plugins. where you have a main application and this dynamically load news functionality. There are several libraries available here I leave some.
(source: wikimedia.org)
Frameworks
TMS Plugin Framework
TJvPluginManager from JVCL
Delphi Plugin Framework
Hydra
Tutorials
Implementing Plug-Ins for Your Delphi Applications
How to make a Plugin for Your Application (Source Code)
Bye.
You can separate your application logic and execute it in several threads. That way, if one part of your application logic hangs up, you still have a responsive application. But you won't be able to put the GUI in multiple threads. The VCL requires you to execute all GUI related stuff in the main thread.
I am not sure about how Delphi operates but the standard procedure for multiprocess programming is forking.
You fork a new process with whatever code you want. Pass information to the forked process and let it run doing whatever it wants.
Can't explain multiprocess programming in one thread response. But look it up.