cefsharp.browsersubprocess - how to properly kill it - cefsharp

At work, our app is starting cefsharp.browsersubprocess.
I'm integrating our app with squirrel.windows - the autoupdate framework.
After an update, our app runs a squirrel method which starts up another squirrel process (update.exe), then does environment.exit on our app. (then, update.exe will wait for our app to exit, then will start the newer version of our app).
What happens is that libcef throws an error to the event manager at the point (4000001f), I guess because we killed its father (our app) but didn't kill cefsharp.browsersubprocess.
If my theory is correct (would love to get a confirmation on that), I plan on modifying squirrel's method by getting a list of child processes of our app, then killing them (it's gonna be only cefsharp.browsersubprocess) before doing environment.exit on our app.
How should I properly kill it? by process.Kill? by process.CloseMainWindow?
Thank!

It works great for me.
internal static void AppRestart()
{
ProcessStartInfo Info = new ProcessStartInfo();
Info.Arguments = "/C choice /C Y /N /D Y /T 1 & START \"\" \"" +
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
"\\..\\" + System.IO.Path.GetFileName(Assembly.GetExecutingAssembly().Location) + "\"";
Info.WindowStyle = ProcessWindowStyle.Hidden;
Info.CreateNoWindow = true;
Info.FileName = "cmd.exe";
Process.Start(Info);
Process.GetCurrentProcess().Kill();
}

Related

JAVA_HOME is lost in script on remote unix machine

I have a script (script1.sh) in a unix machine that calls a other script (script2.sh) in other unix remote machine:
ssh user#machine /opt/.../script2.sh param1 param2
There is a trust relationship between both machines.
If I run the script2, it works correctly, but if I run the script1, it calls script2 but JAVA_HOME of script2 is lost. I know that I can fix by "set JAVA_HOME" in script2 but I prefer other solution that I don´t have to put the specific path of JAVA_HOME in each scripts that is called by script1 (script2, script3,...)
Any idea?
Regards.
I didn´t find the solution so I tried other way. The other way is thought Java.
script1 calls a Java Application that is in the same machine. This Java Application connect with the other machine and calls script2 and catchs the response. The code would be:
//With Try catchs
//Create connection
JSch jSSH = new JSch();
Session session = jSSH.getSession(user, server, port);
UserInfo ui = new SessionUser(password, null);//SessionUser implements UserInfo
session.setUserInfo(ui);
session.setPassword(password);
session.connect();
//Create channel:
Channel channel = session.openChannel("shell");
//Configure inputs and outputs of channel:
OutputStream inputstream_for_the_channel = channel.getOutputStream();
PrintStream commander = new PrintStream(inputstream_for_the_channel, true);
channel.setOutputStream(null);
channel.connect(100);
//Command to execute
commander.println("cd /.../scriptFolder; ./script2.sh param1 param2; exit");
commander.flush();
//System.out.println(channel.getExitStatus());
InputStream outputstream_from_the_channel = channel.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(outputstream_from_the_channel));
String line = null;
//Catch and print the response with a StringBuilder
//close connection
channel.disconnect();
session.disconnect();

Dynamics AX 2012 RegConfig does not work

I'm currently developping a failover service for an environment using Dynamics AX and 2 mirrored SQL servers, and I have some issues getting AX to work the way I expect it to.
I have developped a service which does the following :
- try to connect to the SQL servers instances
- start Dynamics AX using the reachable SQL server.
To do this, I have created 2 AX configuration files (.axc), each one pointing to a SQL server.
But when I try to start the service, no mater which way I use, AX always start using the configuration that is set using the AX server configuration tool.
Here are the command I've tried to start the AX service :
sc start AOS60$01 -regConfig=Config1
net start AOS60$01 /"-regConfig=Config1"
The service always start successfully, but doesn't care about the regConfig parameter.
As anybody an idea about how to solve this issue?
Regards,
Thomas T.
After looking for a while after a way to start the service with the -regConfig parameter, I finally gave up and developped a method which directly edit the Registry key holding the startup configuration value.
private void UpdateRegistry(string parameter)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\Dynamics Server\\6.0\\01", true);
key.SetValue("Current", parameter, RegistryValueKind.String);
key.Close();
}
public void StartLocalServiceWithCLI(string serviceToStart, string parameter)
{
try
{
UpdateRegistry(parameter);
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format("/C sc start {0} ", serviceToStart);
process.StartInfo = startInfo;
process.Start();
logger.WriteInfo(string.Format("Process {0} starting, parameters [{1}]", serviceToStart, parameter));
}
catch (Exception e)
{
logger.WriteError(string.Format("Error starting process {0}, parameters [{1}]\nError details :{2}", serviceToStart, parameter, e.Message));
}
}

How to kill command line server for IE server in webdriver

Please guide me how to kill instances of IE driver . After i run test and on its completion browser is getting quit since i have used driver.quit().But found that instances are still up while cross checking in the task manager.
skelton of code:
driver=new InternetExplorerDriver(); //calling IE driver
testRun(); // run my test
driver.quit();
Thanks in advance
I've a method for you,
public void ieKiller() throws Exception
{
final String KILL = "taskkill /IM ";
String processName = "IEDriverServer.exe"; //IE process
Runtime.getRuntime().exec(KILL + processName);
Wait(3000); //Allow OS to kill the process
}
source

Code working in local environment, but didn't work when hosted on iis

Requiremnet--on click of a button, a site will be created on iis.I am passing a name,that will become the name of the site on iis
I created a powershell script to do this.Using process.start, i want to open a powershell.exe and want to execute my code inside it.
Code...
System.Diagnostics.Process proc = new System.Diagnostics.Process();
Char[] chr = Password.ToCharArray();
System.Security.SecureString pwd = new System.Security.SecureString();
foreach (char c in chr)
{
pwd.AppendChar(c);
}
proc.StartInfo.FileName = "powershell.exe";
//proc.StartInfo.Arguments = powershellScriptCode; //It contains powershell script to create a new website in iis
proc.StartInfo.UserName = UserName; //Comes from config file
proc.StartInfo.Password = pwd; //Comes from config file
proc.StartInfo.Domain = Domain; //Comes from config file
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
bool result = proc.Start();
when i run this code in local environment,it run sucessfully and creates a website, but when i run this code on IIS(After hosting), it is not able to create a site on IIS.so what type of permissions i required.
You need to change the identitiy in the Application Pool. Go to IIS Manager -> Application Pools -> Advanced Settings -> Process Model -> Identity. Change it to "Local system" and try again (but remember to change it back unless you know what you are doing, security-wise; if it works, create a user account with just the required permissions).

Powershell start-job, wait-job, host thread never exits when run from ASP.NET IIS

I am currently trying to build a threaded cleanup script with powershell, initiated from an IIS.
I have made a threaded "Kill process by owner" using powershell remoting, running from the same list of servers as my cleanup script, and that works no problem.
$jobs = #()
foreach ($comp in $comps) {
$jobs += start-job -FilePath ("CleanupJob.ps1") -ArgumentList $comp, $username
Write-Host "Started Job on: $comp"
}
foreach($job in $jobs)
{
$job | wait-job | out-null
receive-job $job.ID
}
Remove-Job -State Completed
When i run my script from the powershell console, the whole thing runs perfectly, main thread starts 28 new processes, which start a remoting connection to each server, and waits for all the jobs to finish. When they are finished, i get my output and the host thread exists. All running as planned.
Not so when I run it from my asp.net application, i get ""Started Job on: $comp"" for each of my 28 servers, but only a result from the first 14, and then the host thread just sits there. (untill i kill it with fire, and my output is returned to the asp.net webpage)
I have no way to see what happens in the script when i run it from the asp.net page.All i can see is cpu/ram usage drop to the same levels as when i run it from the PSconsole, but my main thread never closes. So I do believe the script works as supposed, but my webpage hangs untill the main thread closes(which it never does, as stated).
This is how I call my script (not the pretty .net <3 powershell way:)
public string RunProgramme(string scriptpath, string arguments)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"powershell.exe";
startInfo.Arguments = "& \'"+scriptpath+"\' "+ arguments;
//return startInfo.Arguments;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
string errors = process.StandardError.ReadToEnd();
return output;
}
The mystery deepens, added this line to my threaded jobs
Invoke-Command -Session $session -ScriptBlock {param($path) net send mymachine $path} -Args $msg
And when i run my script from the IIS, i receive message from each machine.
Just as my ram usage shows, all the jobs are run, but the output isnt returned properly, and my host thread just sits there...waiting...
As a note, you've got some unnecessary stuff going on.
foreach ($comp in $comps) {
start-job -FilePath ("CleanupJob.ps1") -ArgumentList $comp, $username
Write-Verbose "Started Job on: $comp"
}
Get-Job | Wait-Job | Out-Null
Remove-Job -State Completed
PowerShell already constructs a job list; there's no need to do so in a $jobs variable, and no need to enumerate them to do the wait.
Of course, you may use $jobs for something else in your code - but just wanted to make sure other folks see this alternative.
I found the solution. It's a deadlock caused by calling
string output = process.StandardOutput.ReadToEnd();
string errors = process.StandardError.ReadToEnd();
Right after each other.
Instead i followed http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandarderror.aspx#Y95 and did this instead:
public string RunProgramme(string scriptpath, string arguments)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"powershell.exe";
startInfo.Arguments = "& \'"+scriptpath+"\' "+ arguments;
startInfo.ErrorDialog = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.BeginErrorReadLine();
//Use BeginErrorReadLine on one of the streams to avoid the deadlock
//(i didnt need my error stream, but I did need to filter the errors from my output, so i did this)
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit(1000 * 60);
return output;
}
No more hanging :)
you could use something like this to see the commands and the output...
$logfile = "C:\Documents and Settings\username\My Documents\WindowsPowerShell\logs\$(Get-Date -uformat "%Y%m%d - %H%M%S").log"
Start-Transcript -Path $logfile
I'm interested to know how you're calling it from ASP.Net as well?

Resources