I am creating wpf application using visual studio 2010 specifically for windows 7 operating system.
Now I want my wpf app to start when ever computer starts. I googled it and wrote service but couldn't succeeded what I need. I do not know how to use that service properly or how to make one installer of both service project and wpf project ( I am new to wpf dev).
this is the code I found on msdn forum but do not know if I am using it right way - I think I am not giving right path of exe file
protected override void OnStart(string[] args)
{
ProcessStartInfo info = new ProcessStartInfo(#"C:\Users\Zeshan\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\TaskManagerPro");
info.CreateNoWindow = false;
Process p = new Process();
p.StartInfo = info;
p.Start();
}
Please guide me to the right direction and if possible kindly share some source code and also guide what is the best way to create installer.
Try this solution from this answer: https://stackoverflow.com/a/5527457/2696641
Modifying a current user registry items do not require admin access.
Add you value to HKCU\Software\Microsoft\Windows\CurrentVersion\Run.
Related
I have a custom application running as a the shell (Windows 10 Enterprise) for a particular user - i.e. the user boots straight into this application.
However, I want to be able to provide access to the WiFi settings form. I have read that the way to do this is something like
Process.Start("ms-settings:network-wifi");
or
Process.Start("ms-availablenetworks:");
However, as far as I can tell, that relies on explorer running as the shell.
I've tried...
Process proc = new Process();
proc.StartInfo.FileName = #"c:\windows\explorer.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Arguments = "ms-availablenetworks:";
proc.Start();
All of the above work fine if I run in a normal environment, i.e. with explorer as the shell.
But for this user (with my custom shell application), I get an instance of explorer.exe running and displaying an error, Class not registered
I have also come across using LaunchUriAsync() but I don't think that would help me here, besides it's only available for Windows Store applications for what I've read, which this is not.
Well I managed to get this working
First start explorer on its own, then a second Process.Start() to run the settings page.
Unfortunately, when explorer.exe runs, it displays the taskbar which I don't want. (I had previously assumed I'd be able to hide it with a group policy setting or something but this doesn't appear to be the case).
But I suppose that's another question...
I need to launch or run an windows exe file from a OEM in Win store App.
can below be used? I try but have error but why since diagnostic is in the framework
using System.Diagnostics;
Process myProcess = new Process();
try
{
myProcess.StartInfo.UseShellExecute = false;
// here I point to the OEM windows exe file
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
-- Update
# Michal :
Thank you. This method works using URI.
One problem :
the WinRT app goes into background after launching. How to make the winRT app not going background?
Is there any other way? I need to integrate the Exe from the OEM into Win Store App.
Note:
I want to know is this can be done or I am doing something which is not allowed?
If I didnot make my case clearer, please tell me what I miss.
I tried it but it did not work. So my solution should be using similar approach like Diagnostic but what it can be?
Recycling bits from https://social.msdn.microsoft.com/Forums/windowsapps/en-US/0a822355-909f-44b4-9c79-cb986087fe27/after-launching-or-activate-an-app-the-main-app-goes-into-background?forum=winappswithcsharp
This is expected behavior and there's no good way around it. Launching a file or protocol switches to the default handler with no expectation of return.
Launching an app via protocol like this a hack in the first place. Since you are a side-loaded app look into writing a Brokered Windows Runtime Component to allow proper use of desktop API and communication with a desktop back-end.
See the Brokered Windows Runtime Component docs at http://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx
I am creating a complex service on Windows 7, which starts off by loading an .exe application. The only way to achieve this was to enable to "Interactive Services Detection" service in services.msc.
As a test application, I added the following code which simply opens the system calculator. It works, however not as intended. I first get the following message when starting the service:
When clicking "View this message", it loads the calculator as it is supposed to, but opens a blue full screen mode, and contains the calculator within it.
My question is basically the following: How can I make the application display automatically, and not have to prompt the user to "view the message", and more importantly, how can I get the application to display normally, rather than in this "interactive services detection" sandbox?
This is the code of my sample service:
public partial class OpenCalculator : ServiceBase
{
public Process process;
public OpenCalculator()
{
this.ServiceName = "Open Calculator";
InitializeComponent();
}
protected override void OnStart(string[] args)
{
start_calc();
}
protected override void OnStop()
{
process.Kill();
}
protected void start_calc()
{
try
{
process = new Process();
process.StartInfo.FileName = #"C:\Windows\system32\calc.exe";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.ErrorDialog = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start();
using (StreamWriter writer = File.AppendText("C:\\Users\\scaruana\\Desktop\\test.txt"))
{
writer.WriteLine(process);
}
}
catch (Exception ex)
{
using (StreamWriter writer = File.AppendText("C:\\Users\\scaruana\\Desktop\\test.txt"))
{
writer.WriteLine(ex.Message);
}
}
}
}
Services run in session 0, whose desktop you cannot see. Interactive desktops are hosted in other sessions. So, for instance, the first interactive logon runs in session 1. This means that services cannot directly show UI on an interactive desktop.
In older versions of Windows (XP and earlier), the first interactive logon shared session 0 with services. And so when you enabled the allow service to interact with desktop option in the service control manager, the service could show UI on an interactive desktop. However, all that ended with Vista because it was a security risk.
So, you need to start a new process and specifically force it onto the desktop of an logged in interactive user. That is not easy to do. This MSDN blog article covers your options: Launching an interactive process from Windows Service in Windows Vista and later.
Now, that's how you go about starting a new process from a service, and putting the new process onto an interactive desktop. But that is almost certainly the wrong way to solve your problem. As you can see by reading the linked article, doing it that way is complex. The standard solution to your problem is to run an interactive process on the logged in user's desktop. This remains hidden until your service needs to show UI. The service then communicates with the desktop app using your preferred IPC mechanism, and then the desktop app shows the UI.
This question has been the cause of great frustration, and I have finally solved my problem. Yes, I have managed to make a service load a GUI application, even though everyone says that it is impossible. There is a warning though - the "fix" can be considered as exploiting a loophole in Windows, as the code which I used basically passes the Vista and Windows 7 UAC. Essentially, the application is always executed with full rights and bypasses the UAC.
If anyone has this same problem, what you need to do is iterate through a list of logged in users on the PC, and choose to open the UI application in this session (which has the user's desktop), rather than in session 0 where the service is supposed to be running (and which does not have a desktop).
For some people, this might not be a solution as it is not secure. But in my case, security is not a main concern, and I just needed it to work (had to be a service by force).
Hope this helps anyone who has the same problem that I had.
I need to start an application from another application. It looks like I have to use the shell to do it (since I need to be able to close the launcher), but I also would like to downgrade the rights given to the launching application.
Is this possible? The launcher must run as administrator, but I'd like to have the launching application run as user.
this is how I currently run the process:
Process process = new Process();
process.StartInfo = new ProcessStartInfo();
process.StartInfo.FileName = name;
process.Start();
Forgive me I forgot to add a couple of details:
I need to run it in .net 3.5 on mono
I'd prefer to not use native code
I need to run the launcher application in admin mode
This seems to be have discussed before, check this out: How do you de-elevate privileges for a child process
Looks like an UAC elevation is strictly one-way, so the solutions are a bit gnarly, i.e. code injection into explorer and stuff like that.
http://www.codeproject.com/Articles/18946/High-elevation-can-be-bad-for-your-application-How
Eventually I decided to create a bootstrapper that could run the launcher as administrator, but then the application as normal user. Once the launcher is done it goes back to the bootstrap executable which launches the application.
i want to run an application made in c# winform through service.i have done the code but the application does not get started even service successfully gets started and no exception is thrown.
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("starting Kb");
try
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = #"C:\Program Files (x86)\Invisual E. Inc\KeyboardSetup\keyboard.exe";//Exe Path
myProcess.StartInfo.CreateNoWindow = false;
myProcess.EnableRaisingEvents = true;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
myProcess.Start();
ProcessWindowStyle ws = myProcess.StartInfo.WindowStyle;
if (ws == ProcessWindowStyle.Hidden)
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
eventLog1.WriteEntry("started");
}
catch (Exception c)
{
eventLog1.WriteEntry(c.Message);
}
}
Log file does not show any exceptions.
Purpose is to start the application at the welcome screen of window so that user can use custom made keyboard .
What operating system? From Vista and beyond you cannot create GUI from services (it's a security flaw and ugly...) There is a user 0 session that shows gui started by services from vista onwards.
Why not create a registry entry and/or startup entry for your app to start when the user who installed your app logs in? Or follow the info here about implementing an interactive service.
A service normally runs under a user other than the logged in user therefore the service doesn't have a desktop available to display any windows form, hence the reason t isn't being displayed.
I think you will need to find another way as although a winforms app can start a service I dont believe it can be done the other way around.
Regards
AJ