I've made a little C# tool for monitoring sidebar.exe (as some know there's a strange memory leak in it, so this monitor restarts the sidebar.exe process when it reaches a limit...).
Before this I had a .bat file doing it and I was running it manually, and it worked fine. Now, I'm executing the cmd commands from C#, but the behavior is different: only 4 of the 7 gadgets appear again after "start sidebar.exe". It always happens with the program, and never when run manually.
What's the difference in running the commands as .bat or from the process? And can I fix this?
I also tried running the .bat itself from the process, same problem...
The commands are:
taskkill /im sidebar.exe /f
TIMEOUT /T 2
in .bat or System.Threading.Thread.Sleep(2000);
in program
start sidebar.exe
Update: The code of what I tried:
Option 1 - run .bat: System.Diagnostics.Process.Start(@"C:\....restart.bat");
Option 2 - run commands:
...
this.executeCmd("taskkill /im sidebar.exe /f");
System.Threading.Thread.Sleep(2000);
this.executeCmd("start sidebar.exe");
...
private void executeCmd(String command)
{
ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = psi;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
System.Console.Out.WriteLine(result);
}
Update:
I've been told it's some permissions/account/user issue, tried to solve it with no success, but I noticed that in Java this doesn't happen so I combined Java and C# for this tool (a java runnable called on startup, using a small exe which returns the usage of sidebar.exe) - works perfect. Still would appreciate an answer if anyone knows about this C# issue though.
I believe that your issue is in the environment that you are working in. More information is helpful but here is something to try.
using the System.Diagnostics namepsace, create a ProcessStartInfo object and provide the appropriate information and especially make sure the username of the logged on user is provided.
use this ProcessStartInfo object as the parameter to the Process.Start(ProcessStartInfo) call.
That should start the process under the proper user account.
Now, if you are running this as a service, you may have additional issues as services do not have access to the GUI by design services are not intended to allow for user input so the environment may be limited there as well and the sidebar may not be able to find its saved settings.
knew i should have hit refresh before clicking submit :)