Search Chirayu Software Solutions Blog

Wednesday, April 30, 2014

Method for changing settings of a Windows Service

  1. /// <summary>
  2. /// method for setting the value of a Windows Service:
  3. /// 2 => Automatic
  4. /// 3 => Manual
  5. /// 4 => Disabled
  6. /// </summary>
  7. /// <param name="serviceName">service we're looking for</param>
  8. /// <param name="value">integer value to set the Start key to</param>
  9. /// <returns></returns>
  10. public bool SetWindowsServiceStatus(string serviceName,int value)
  11. {
  12. try
  13. {
  14. //open the registry key for the specified Windows Service
  15. Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(string.Format(@"SYSTEM\CurrentControlSet\Services\{0}", serviceName), true);
  16. //if exists then set the value to the desired value
  17. if (key != null)
  18. {
  19. /*now set the value of the Start value:
  20. * 2 => Automatic
  21. * 3 => Manual
  22. * 4 => Disabled
  23. * */
  24. key.SetValue("Start", value);
  25. return true;
  26. }
  27. else
  28. {
  29. //not found, so service isnt available or isntalled
  30. throw new Exception(string.Format("The Windows Service {0} could not be located or does not exist", serviceName));
  31. }
  32. }
  33. catch (Exception ex)
  34. {
  35. MessageBox.Show(ex.Message);
  36. return false;
  37. }
  38. }

Friday, April 25, 2014

LSP problem fix

To List current installed LSP

netsh winsock show catalog

To reset LSP

netsh winsock reset 

Tuesday, April 22, 2014

Tips for optimizing c# code

1) Capacity

For collections, you can use an optional capacity argument to influence the initial buffer sizes. It is best to pass a reasonable parameter when creating a Dictionary or List. This avoids many allocations when adding elements.


2) Lookup tables

While switch statements or hashtables can provide good performance, using a lookup table is frequently the optimal choice. Instead of testing each character using logic to lowercase, you can translate it through a lookup table.

3) Do not use clear in dictionary or list

4) Use String.Compare instead of =’s

When doing a case-insensitive compare, the String.Compare function provides far greater performance than using the equals operator and two case modifying functions.
Slow
bool match = s1.ToLower() == s2.ToLower();

Fast
bool match = (string.Compare(s1, s2, true) == 0);

5. Use string.Empty

This is not so much a performance improvement as it is a readability improvement, but it still counts as code optimization. Try to replace lines like:

if (str == "")
with:

if (str == string.Empty)

Saturday, April 19, 2014

Make Mozilla Run Fast and without Advertisements / Adware

For Firefox, one of these:
  • firefox -safe-mode
  • "C:\Program Files\Mozilla Firefox\firefox.exe" -safe-mode
  • "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -safe-mode

Thursday, April 10, 2014

Change RDP ( Terminal Server ) default listening Port

Change the value in registry at following location :

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp\PortNumber