Thursday, October 27, 2011

winscp.exe COPIES FILES FROM UNIX TO WINDOWS

 

set LOGINAS=username:password@host

 

set SOURCE_PATH=/local/home

set DEST_PATH=d:\Test\

set SCRIPT_FILE=script.txt

 

set _Date=%date%

 

If "%_Date%A" LSS "A" (Set _NumTok=1-3) Else (Set _NumTok=2-4)

:: Default Delimiter of TAB and Space are used

For /F "TOKENS=2*" %%A In ('REG QUERY "HKCU\Control Panel\International" /v iDate') Do Set _iDate=%%B

For /F "TOKENS=2*" %%A In ('REG QUERY "HKCU\Control Panel\International" /v sDate') Do Set _sDate=%%B

IF %_iDate%==0 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%D%%B%%C

IF %_iDate%==1 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%D%%C%%B

IF %_iDate%==2 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%B%%C%%D

Set _Today=%_fdate:~0,4%%_fdate:~4,2%%_fdate:~6,2%

 

set COPYFILE_1_PATRN=A1_TEST_%_Today%.txt

set COPYFILE_2_PATRN=B1_TEST_%_Today%.txt

 

Echo option batch abort>>%SCRIPT_FILE%

Echo option confirm off>>%SCRIPT_FILE%

Echo open %LOGINAS%>>%SCRIPT_FILE%

Echo cd %SOURCE_PATH%>>%SCRIPT_FILE%

Echo option transfer binary>>%SCRIPT_FILE%

Echo get %COPYFILE_1_PATRN% %DEST_PATH%>>%SCRIPT_FILE%

Echo get %COPYFILE_2_PATRN% %DEST_PATH%>>%SCRIPT_FILE%

Echo close>>%SCRIPT_FILE%

Echo exit>>%SCRIPT_FILE%

 

 

"C:\Program Files\WinSCP\winscp.exe" /console /script=%SCRIPT_FILE%

DEL %SCRIPT_FILE%

PAUSE

 

 

Tuesday, September 27, 2011

value from the enum ?

Question:

      Is there any way that I can access the assigned value from the enum?

 

                Eg: When my item is Red then I want get the corresponding value That’s ‘R’. Is that possible?

public enum Color

      {

          Red = 'R',

          Blue = 'B',

          Green ='G',

          Yellow ='Y',

          White = 'W'

      }

 

Answer:

 

Yes by this way –

 

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine((char)Color.Red);

        }

    }

 

    public enum Color

      {

          Red = 'R',

          Blue = 'B',

          Green ='G',

          Yellow ='Y',

          White = 'W'

      }

 

Friday, September 23, 2011

Tracking CPU and Memory usage per process

Just type perfmon into Start > Run and press enter. When the Performance window is open, click on the + sign to add new counters to the graph. The counters are different aspects of how your PC works and are grouped by similarity into groups called "Performance Object".

 

For your questions, you can choose the "Process", "Memory" and "Processor" performance objects. You then can see these counters in real time

 

You can also specify the utility to save the performance data for your inspection later. To do this, select "Performance Logs and Alerts" in the left-hand panel. (It's right under the System Monitor console which provides us with the above mentioned counters. If it is not there, click "File" > "Add/remove snap-in", click Add and select "Performance Logs and Alerts" in the list".) From the "Performance Logs and Alerts", create a new monitoring configuration under "Counter Logs". Then you can add the counters, specify the sampling rate, the log format (binary or plain text) and log location.

 

 

For more information follow this link.

 

http://stackoverflow.com/questions/69332/tracking-cpu-and-memory-usage-per-process

Wednesday, August 10, 2011

Spool in unix

Login to oracle

Sqlplus user/pwd@database

 

Spool filename.txt

Select * from dual;

Spool off

 

 

Saturday, July 9, 2011

Deligates small note.

Delegates in C# are objects which points towards a function which matches its signature. Delegates are reference type used to encapsulate a method with a specific signature. Delegates are similar to function pointers in C++; however, delegates are type-safe and secure.
Here are some features of delegates:

A delegate represents a class.
A delegate is type-safe.
We can use delegates both for static and instance methods
We can combine multiple delegates into a single delegate.
Delegates are often used in event-based programming, such as publish/subscribe.
We can use delegates in asynchronous-style programming.
We can define delegates inside or outside of classes.
Syntax of using delegates

//Declaring delegate
delegate void SampleDelegate(string message);

// declare method with same signature:
static void SampleDelegateMethod(string message) { Console.WriteLine(message); }

// create delegate object
SampleDelegate d1 = SampleDelegateMethod;

// Invoke method with delegate
d1("my program");

Monday, June 20, 2011

How to install a Windows service using command line ?

How to install a Windows service using command line ?

1>> Make a build of the service project then go to bin directory and copy required build files from either of the directory Release / Debug.
2>> Service will be in .exe file. This should be installed now, by using a command line   as below –

Copy blow one to bat file , name it as install.bat.

c:
cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
InstallUtil.exe "E:\test\testservice.exe"
pause


Run install.bat to install the service.

3> To uninstall there are two ways –
               a)
c:
cd c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
InstallUtil.exe –u "E:\test\testservice.exe"
pause

b)
sc delete <serviceName>
pause

               Some time using point number 3.a  , it is required to restart the windows machine so better to use the point 3.b.



Note- if you struck with the service which is already installed then you can kill that process , either using command line or ctrl+Alt+del select service and kill the process.

Friday, June 17, 2011

How to remove item from a List in a Loop ?

It is not an easy task of removing an item from the list in the loop. By just doing the loop and removing the item we can encounter much complications.

So better way is to loop the list from bottom -> up and remove the item based on the condition.

Sample code piece -



using System;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            List<string> ls = new List<string>();

            ls.Add("a");
            ls.Add("b");
            ls.Add("c");
            ls.Add("d");
            ls.Add("e");

            for (int i = ls.Count - 1; i >= 0; i--)
            {


                if (ls[i] == "d")
                {
                    Console.WriteLine("del:" + ls[i].ToString());
                    ls.RemoveAt(i);
                }

            }

            for (int i = 0; i < ls.Count; i++)
            {
                Console.WriteLine(ls[i].ToString());
            }

        }
    }
}

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code