Developing an application to restart another application [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I need to write an application which will be installed inside a windows7 embedded enterprise O/S. This applications job is to restart another application at a pre-configured time each day. Can you please tell me which API's do i need to refer for this purpose? Do i need to depend on the windows scheduler for this task? Is it possible to configure the scheduler from win32 code?
Is there any application which does this job already exist in the market?
Thanks,
John.

I would use a Task Scheduler which is good documented and has many examples.
Take a look at Time Trigger Example:
This C++ example shows how to create a task that is scheduled to
execute Notepad at a specified time. The task contains a time-based
trigger that specifies a start boundary and an end boundary for the
task. The task also contains an action that specifies the task to
execute Notepad. The task is registered using an interactive logon
type, which means the task runs under the security context of the user
who runs the application. The task also contains idle settings, which
specifies how Task Scheduler performs tasks when the computer is in an
idle condition.

You can do this from a batch file.
First, prepare a script, e.g. "restart.bat" to kill the process and restart it, killing can be done by taskkill, restarting should be done by start to not block current script.
Then create setup batch file to add "restart.bat" to task scheduler

You can get (or specify as a string) the PID from EnumProcesses, kill the process using TerminateProcess() and then later you can create process by OpenProcess() function from Win32.
Another approach is that you can also use ShellExecute() or system to executed commandline commands directely from a Visual C++ program, and pass a command as:
taskkill /F /T /IM MyProcess.exe
later simply open the application using ShellExecute or system.

Related

Is it possible to hook to WinLogon proc when logon to window? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I need to develop a dll which will be called whenever somebody logon to window.
This dll will hook to the WinLogon proc and do something, the WinLogon process will be suspended until the dll done their work.
I tried to take around stackoverflow as well as msdn but I can't find the relevant article.
Is there anyone here can give me some related article or suggestion?
Thank you all in advance!
In Windows 2000,Windows XP and Windows Server 2003, you could use Winlogon Notification Package. But in Windows Vista and later, Winlogon notification packages are no longer supported, see Winlogon Notification Packages Removed: Impact on Windows Vista Planning and Deployment.
You can use the alternative solutions listed in the document to hook the logon event. It should be noted that Service Control Manager (SCM) Notifications and System Event Notification Service (SENS) are usually asynchronous, and Group Policy Scripts are also asynchronous by default to improve system boot and login performance.
However, there is a Group Policy option to have scripts executed synchronously(Computer Configuration\Administrative Templates\System\Scripts\Run startup scripts synchronously).
Please note that this is not a recommended configuration and should only be used if no other methods are available. You must also extensively test the script to ensure that it does not cause any system performance problems.

Running program as regular user from an elevated process [duplicate]

Is there some way to launch a process in non-elevated way from an elevated one. My setup is launched elevated and when it finalizes, it will just launch the main application. Because the setup is elevated, the main process will be elevated as well which is not desirable. What is the best solution to this?
That's a problem, Vista/Win7 don't appear to have an API to obtain the unprivileged user token you need to call CreateProcessAsUser(). The only solutions I've found involve using the task scheduler to launch the program. That doesn't strike me as very practical.
An easy solution that jumps to mind is to use a small non-elevated helper process. It can in turn launch the elevated setup process and wait for a confirmation from that one to launch the non-elevated one. The handshake is simple enough to do this with a named mutex.
The only way to do this without hacks is to have two processes (Can be implemented in the same .exe)
Instance A starts Instance B with ShellExecute and the runas verb.
B does the installing, when its time to start your app on the "finish page", it uses some form of inter processes communication (RPC, shared memory+events etc) with A telling it to start a process on its behalf.
This seems like a nice way to do it, provided you don't care about situations where the Shell is not running (e.g. possibly some Terminal Services application-only setups, perhaps, though I'm not sure):
http://brandonlive.com/2008/04/27/getting-the-shell-to-run-an-application-for-you-part-2-how/
It gets an interface to Explorer.exe, which should be running in the user's normal context, and asks Explorer to execute a command in its behalf. This is done just using simple, documented COM interfaces and without having to mess around with process tokens or code/DLL injection.

Simple online game servers monitor

I want to make a tool that runs on win32 to monitor our online game servers. The servers actually are .exe files. I need to know whether they have crashed so I can restart them. Therefore, the tool will have 2 main features:
Frequently check a list of the server programs to see whether they are running or not
Reopen the executable of any server that has crashed
Does anyone have any idea or knows an API to start with?
If you're in Win32, you can start out with C# using System.Diagnostics
using System.Diagnostics;
Then get a process list:
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
And from there it's up to you what you want to do with the info.
Game servers should produce logs. You should make a service / cron job to monitor the logs. Depends on the contents of logs, your service should act respective actions, e.g. restart service, trigger alarms, etc.
I realize that this is not exactly what you asked for, but what about doing the monitoring with a fully-fledged monitoring tool such as Nagios? You would of course have to "teach" the monitoring tool about the processes that shall be monitored but you would also profit from its more advanced functions. In the case of Nagios, for example, these would comprise automatic e-mail notifications, an online dashboard of process status, notifications via SMS etc.
You should start the game servers using CreateProcess or similar in the win32 api.
You will get back a process handle in the lpProcessInformation parameter.
You can use WaitForSingleObject to WaitForMultipleObjects to wait until that handle is notified which will happen when the process terminates for any reason.

Scheduled task for C++ EXE not working [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I've bought a VPS, but it has been restarting on occasion. The server is meant to be running my game server 24/7, but when it restarts obviously the game goes down too.
I'm trying to setup a scheduled task to run the C++ game server EXE on start up, but it isn't working. I've already set a scheduled task to run WAMP so I know that the scheduled tasks actually work, but for the C++ EXE it just isn't.
I've even compiled a very simple program that just waits for user input before closing, and set this as a scheduled task. When I restart the server, this program doesn't even run.
Any ideas? Is this a problem specific to running an executable like this?
It's also strange, on the scheduled task manager it says the program is running, but no console is on screen...
OS: Windows Server 2003
Since you are using Windows Server 2003, check out here to allow services to interact with desktop.

Auto pilot mode of application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hey Guys I am working on Gateway Simulator.
here gateway simulator is connected with the camera.gateway respond when user sends command.
command can be like streaming video or status of the sensor associated battery information etc.There is data center also which will forward the user request to gateway.
There some information which gateway also send to the user or data center with out any request from the user or data center.like battery status down,sensor remove etc etc.
Since this simulator will be used by the developer/QA team to simulate the gateway.they want it it to run in auto pilot mode/pre-scripted instructions mode as well.
I wanted some input from you guys o this.I wanted to know some the widely used approach to address this issue.
any link/suggestion would be fine.This gateway simulator needs to be written ic++ for both linux and windows paltform.
It depends on how (network, console, GUI, ...) the user is sending commands. If it's network or console, writing a script that will feed the command should not be too hard in any language, but there is a tool called expect, built on top of tcl, that's specifically designed for this task. Alternatively if you know perl or python and don't want to learn tcl, you can use the perl Expect module or python pexpect package (windows version).
If the commands are given through a GUI, there is some tooling to automate even that in LDTP. It should work with Gtk+ GUI and I am not sure how far it is with Qt (or whether KDE has something similar).