Wednesday, December 17, 2014

Windows 8 apps opening problem

On my work PC i had this issue, domain account on windows 8, and whenever i tried to open any of windows 8 apps, it is opened and disappears and the window is not displayed.
When i searched i found lots of articles taking about windows apps issues, but all didn't help. I found helpful articles when i searched with the error i found in event viewer like:


Activation of app windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel failed with error: This app does not support the contract specified or is not installed. See the Microsoft-Windows-TWinUI/Operational log for additional information.

I found the solution in couple of articles

I can't open any Windows 8 apps including PC Settings and Store
Fix Windows 8.1 Cannot Launch “PC Settings” or “Store” Problem

Running the below commands solved the problem

powershell -ExecutionPolicy Unrestricted Add-AppxPackage -DisableDevelopmentMode -Register $Env:SystemRoot\camera\AppxManifest.xml
powershell -ExecutionPolicy Unrestricted Add-AppxPackage -DisableDevelopmentMode -Register $Env:SystemRoot\FileManager\AppxManifest.xml
powershell -ExecutionPolicy Unrestricted Add-AppxPackage -DisableDevelopmentMode -Register $Env:SystemRoot\ImmersiveControlPanel\AppxManifest.xml

Monday, October 20, 2014

Enabling remote desktop on remote computer

I went home and forgot to enable remote desktop on my PC at my office, luckily i found couple of articles that is talking about enabling remote desktop remotely.

I followed the steps from  here and did a restart for the remote machine, but it didn't work, then i figured that since i did it through registry, firewall rules wasn't updated to allow it, while if i enabled remote desktop connections through the UI, it is updated automatically.

I found another article that has the same steps plus updating the firewall to enable remote desktop connections with a command line that is executed remotely. Another article for opening the firewall for remote desktop connections from command line.

The only thing that i have done extra is that i started the elevated command prompt for "psexec", the normal one didn't do the job.

Brief of the steps:
1- From the registry, connect to the remote computer
2- Change the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\fDenyTSConnections from 1 to 0
3- Restart the remote machine by shutdown -m \\MachineName -r
4- Update the firewall rules on the remote machine by downloading psexec and running the below from elevated command prompt
psexec \\remote_machine_name cmd
Then after it connects
netsh advfirewall firewall set rule group=”remote desktop” new enable=Yes

Thursday, June 26, 2014

.NET C#: Running command line in CMD and waiting for it to finish

I had a script that i should call with command line interface, then other tasks that should be done after that.
I used the Process and ProcessStartInfo as below, but the problem i had is that the script was taking some time, and the program execution was failing after that since the script is not finished yet.

            using (Process process = new Process())
            {
                var startInfo = new ProcessStartInfo("cmd")
                {
                    RedirectStandardInput = true,
                    RedirectStandardOutput = true,
                    WindowStyle = ProcessWindowStyle.Normal,
                    UseShellExecute = false,
                    CreateNoWindow = false
                };

                process.StartInfo = startInfo;
                process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
                process.Start();
                process.StandardInput.Write("script"+ process.StandardInput.NewLine);
                process.Close();
            }

I wanted to make sure that the program execution waits till the script finishes.So instead of using Close method, i added WaitForExit, and i am manually sending exit command to the command line after the script finishes, like below

            using (Process process = new Process())
            {
                var startInfo = new ProcessStartInfo("cmd")
                {
                    RedirectStandardInput = true,
                    RedirectStandardOutput = true,
                    WindowStyle = ProcessWindowStyle.Normal,
                    UseShellExecute = false,
                    CreateNoWindow = false
                };

                process.StartInfo = startInfo;
                process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
                process.Start();
                process.StandardInput.Write("script"+ process.StandardInput.NewLine);
                process.StandardInput.Write("exit" + process.StandardInput.NewLine);
                process.WaitForExit();
            }

This worked for me and the program execution waited till the script finishes.

Wednesday, June 18, 2014

Clicking problems with IE and Selenium

We were facing couple of problems with selenium tests running on IE, when running the tests locally, we don't have these issues. After adding more logs to the code, i found that sometimes it is failing after sending the click event in different steps. 
Looking online for similar issue, i found that there are clicking issues with IE, as sometimes the element being clicked on will receive the focus, but the click will not be processed by the element.
https://code.google.com/p/selenium/wiki/InternetExplorerDriver#Browser_Focus

To workaround this, i am setting the focus manually to the browser using the below line of code

Driver.SwitchTo().Window(Driver.CurrentWindowHandle);