Showing posts with label CODE. Show all posts
Showing posts with label CODE. Show all posts

Saturday, December 15, 2012

How to make a Batch File Without knowledge of Programming

 

Batch file is a text file with series of commands which would execute one by one on launching this single file. So, it can be used to automate your daily and repetitive tasks on windows. These tasks could be like executing a program, opening a website or simply open a file or document.

Let me give you a simple example where I need a batch file: I open Gmail, Facebook and Twitter every morning in web browser followed by a Music playlist in media player. All these tasks can be done by launching single batch file. Here’s how you can do it using a software to create batch file.

AutoStarter X3 is a portable software tool to create command files or batch file. And that too without knowledge of programming.Just specify file, web address or a program to be executed and batch file will be ready in one click.

 

Program has a single window interface and new command can be added by clicking on Add button. Here is a description of each command given there:

  • File(s)- Select one or more than one file to open in their default program. (Opening a .JPG file will open it with default photo viewer with which it is associated)
  • Webpages Tabs- Specify the web browser to be used to open a web address.
  • Webpages Windows- Open a web URL in default web browser of your PC.
  • Directory- Open a folder on your Hardrive or Network location.
  • Shortcut- Open a shortcut to file or web URL (lnk or url)
  • Music Files Directory- You can create a playlist of songs in a folder and then play them back via the default player. The creation of the playlist can take several minutes, depending on the number of songs in the folder, close the warning that pops up OK.
  • Open file with Program- Open a file in specific program of your choice instead of default. (Opening a JPG image in Photoshop when .JPG is associated with Windows photo viewer)
  • Execute Program- Run a software program specified.

After specifying the commands, you can test how the batch file will execute. If it is all right, click on Batch to create a Batch *.bat) file. Program also gives you an option to save project to edit or develop it later.

Batch file is a low level solution to automate tasks when there are software tools likeTimeComX and Scheduler  to schedule tasks and automate windows operations.

Download AutoStarter X3

Monday, March 7, 2011

test codes

namespace RunningInstance
{
    using System;
    using System.Diagnostics;
    using System.Reflection;
 
    class Program
    {
        static void Main(string[] args)
        {
            if (RunningInstance())
            {
                Console.WriteLine("Another instance of this process was already running, exiting...");
                return;
            }
 
            // ...
        }
 
        static bool RunningInstance()
        {
            Process current = Process.GetCurrentProcess();
            Process[] processes = Process.GetProcessesByName(current.ProcessName);
 
            // Loop through the running processes in with the same name
            foreach (Process p in processes)
            {
                // Ignore the current process
                if (p.Id != current.Id)
                {
                    // Make sure that the process is running from the exe file.
                    if (Assembly.GetExecutingAssembly().Location.Replace("/", @"\") == current.MainModule.FileName)
                    {
                        return true;
                    }
                }
            }
 
            return false;
        }
    }
}
 
However, suppose you have a multi function console application that accepts a dozen different command line arguments to perform different jobs, all of which run as separate scheduled tasks at overlapping intervals. If this is the case, then checking the list of running processes may well find your executable already running, but have no idea which command line argument was used to start it. I tried adding:
 
Console.WriteLine("Instance started with args: '{0}'", p.StartInfo.Arguments);
above the "return true" statement in RunningInstance() but it will not print the command line args used to start it. Lets suppose we add 2 classes to our project. Task1 and Task2. For the sake of simplicity, they both look something like this:
namespace RunningInstance
{
    using System;
    using System.Threading;
 
    public class Task1
    { 
        public void Start()
        {
            Console.WriteLine("Starting Task 1");
        }
    }
}
 
Task 2 is exactly the same, except it prints "Starting Task 2". If we keep our RunningInstance check in place Main() now looks like this:
 
        static void Main(string[] args)
        {
            if (RunningInstance())
            {
                Console.WriteLine("An instance of this application is already running. Exiting.");
                Console.ReadLine();
                return;
            }
 
            if(args.Length < 1)
            {
                Console.WriteLine("Unrecognized Command.");
                return;
            }
 
            switch (args[0])
            {
                case "-task1":
                    var t1 = new Task1();
                    t1.Start();
                    break;
                case "-task2":
                    var t2 = new Task2();
                    t2.Start();
                    break;
                default:
                    Console.WriteLine("Unrecognized Command.");
                    break;
            }
        }

Sunday, February 27, 2011

FIND BIG FILES BY EXCEL FILE

 
' BigFiles Macro
 
' This software is provided as-is, without any warranty, either
' express or implied, including the implied warranties of
' merchantability or fitness for a particular purpose. In no event
' will the author be liable to you for any special, consequential,
' indirect, or similar damages. In no case shall the author's liability
' exceed one dollar.
 
Dim bigfile As Double
Dim base As String
Dim row As Integer
Dim fso
 
Sub BigFiles()
  Dim s As String
 
' specify how big
  s = InputBox( _
          "How big is big?" + vbCrLf + _
          "Your report will show all big files and all big folders." + vbCrLf + _
          "Specify threshhold size in MB", , "10")
  If s = "" Then
    Exit Sub ' user hit cancel
  End If
  bigfile = CDbl(s) * 1048576# ' convert from MB to bytes.
 
' determine beginning path
' if a cell in the name col is selected,
'   we're drilling down.
'   start with selected folder,
'   report on sheet 2
' else
'   starting with root.
'   ask for drive letter
'   report on sheet 1
  Sheets(1).Name = "Drive"
  Sheets(2).Name = "Drill Down"
  If Selection.Column = 10 Then
    base = Selection.Value
    Worksheets("Drill Down").Activate
  Else
    base = InputBox("Enter Drive Letter", , "C")
    If base = "" Then
      Exit Sub ' user hit cancel
    End If
    base = base + ":\"
    Worksheets("Drive").Activate
  End If
 
' Erase entire spreadsheet
  Cells.Select
  Selection.ClearContents
 
  row = 1
  ' create a file system object, to access the file system
  Set fso = CreateObject("Scripting.FileSystemObject")
 
  ' and so it begins
  Cells(1, 1).Select
  grandtotal = GetFolderSize(base, 0) ' start with base folder, level zero
 
  ' Done!
  
  ' Label Headers and format columns
  Range("A1").Select
  ActiveCell.FormulaR1C1 = "Created"
  Range("B1").Select
  ActiveCell.FormulaR1C1 = "Modified"
  Range("C1").Select
  ActiveCell.FormulaR1C1 = "Accessed"
  Range("D1").Select
  ActiveCell.FormulaR1C1 = "Base"
  Range("E1").Select
  ActiveCell.FormulaR1C1 = "Sub 1"
  Range("F1").Select
  ActiveCell.FormulaR1C1 = "Sub 2"
  Range("G1").Select
  ActiveCell.FormulaR1C1 = "Sub 3"
  Range("H1").Select
  ActiveCell.FormulaR1C1 = "Deeper"
  Range("I1").Select
  ActiveCell.FormulaR1C1 = "Size"
  Range("J1").Select
  ActiveCell.FormulaR1C1 = "Name"
  Columns("A:C").Select
  Selection.NumberFormat = "m/d/yy"
  Columns("D:I").Select
  Selection.NumberFormat = "#,##0"
  Range("A2").Select
  ActiveWindow.FreezePanes = True
  If row > 2 Then
    Selection.Sort Key1:=Range("J5"), Order1:=xlAscending, Header:=xlGuess, _
      OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
  End If
  Columns("A:J").EntireColumn.AutoFit
 
  Cells(1, 1).Select ' shift sheet full left
  Cells(2, 4).Select ' park in base folder size
  MsgBox ("DONE!")
End Sub
 
' *********************************************************8
' Here's where the work gets done
Function GetFolderSize(FolderName, depth)
  Dim totalsize As Double, mbsize As Long, sfsize As Double
  Dim s As String
  Dim lastslash As Integer, col As Integer
  Dim folder
 
  ' progress
  Cells(1, 1) = FolderName
  DoEvents
 
  ' get a folder object to access this folder
  Set folder = fso.GetFolder(FolderName)
 
  ' can't do system protected folders, except root, of course
  ' for example, if you look at "SYSTEM VOLUME INFORMATION",
  ' you get "access denied"
  ' This attempts to see the folder, but doesn't die if denied.
  If Not folder.IsRootFolder Then
    On Error Resume Next ' dont die if next stmt bombs
    totalsize = folder.Size ' err occurs if protected
    If Err <> 0 Then ' if there was an error...
      Err = 0
      GetFolderSize = 0
      Exit Function
    End If
    On Error GoTo 0 ' errors kill again.
  End If
 
  'add in length of each individual file in this folder.
  totalsize = 0
  Set filelist = folder.Files ' get a file list
  For Each file In filelist
    ' progress
    Cells(1, 1) = file.Path
    DoEvents
    totalsize = totalsize + file.Size
    ' ***********************************************************
    If file.Size >= bigfile Then
      row = row + 1
      Cells(row, 1) = file.DateCreated
      Cells(row, 2) = file.DateLastModified
      Cells(row, 3) = file.DateLastAccessed
      Cells(row, 9) = CLng(file.Size / 1048576)  ' MB
      s = file.Path
      lastslash = InStrRev(s, "\")
      If lastslash > 3 Then
        s = Left(s, lastslash - 1) + " - " + Mid(s, lastslash + 1)
      End If
      Cells(row, 10) = s
    End If
  Next
 
  ' scan all subfolders. This function calls itself.
  ' can't use "folder.size", which is denied on "C:\".
  ' and we have to crawl through each folder anyway, looking
  ' for big files.
  Set sflist = folder.SubFolders ' list of subfolders
  For Each sf In sflist ' for each subfolder in the list...
      sfsize = GetFolderSize(sf.Path, depth + 1)
      totalsize = totalsize + sfsize
  Next
 
  ' now log this folder (if it's big) to the spreadsheet
  If totalsize >= bigfile Then
    If depth > 3 Then
      col = 8
    Else
      col = depth + 4
    End If
    row = row + 1
    If folder.IsRootFolder Then
      ' properties are denied on "c:\"
      Cells(row, 1) = ""
      Cells(row, 2) = ""
      Cells(row, 3) = ""
    Else
      Cells(row, 1) = folder.DateCreated
      Cells(row, 2) = folder.DateLastModified
      Cells(row, 3) = folder.DateLastModified
    End If
    mbsize = CLng(totalsize / 1048576#)  ' size in MB
    Cells(row, col) = mbsize
    Cells(row, 9) = mbsize
    Cells(row, 10) = FolderName
  End If
  
  ' Done with this folder
  GetFolderSize = totalsize
End Function
 
 
 
 
 

Tuesday, October 5, 2010

FILE COPY PROGRAM IN C SOURCE CODE

/* WARNING: be sure to edit the line 23 and make "text the file you
want to copy, be sure to leave the file name in quotes, filename can me
relative or absolute
*/
#include <stdio.h>
int main()
{
		 char c[100];
		 FILE *inFile;
		 FILE *outFile;
		 char sourceFile;
		 char destFile;
		 int Byte;
		 int i;
//		 printf("Enter the File Name to read: ");
//		 scanf("%s",&sourceFile);
		 printf("Enter the File Name to write to: ");
		 scanf("%s",&destFile);
		 inFile = fopen("text", "rb");
		 /*open a text file for reading in binary */
		 outFile = fopen(&destFile, "wb");
		 /*open a text file for writing in binary*/
		 if(inFile==NULL)
		 {
		 /*if pointer to inFile is a null pointer,
		   return an error and display msg */
		 		 printf("Error: Can't Open sourceFile
");
		 		 /*be sure not invoke fclose, because
		 		   you can't pass a NULL pointer to it
		 		 */
		 		 return 1; //return 1 for error;
		 }
		 if(outFile==NULL)
		 {
		 		 printf("Error: Can't Open DestFile
");
		 		 return 1;
		 }
		 else
		 {
		 		 printf("File Opened Successfully.");
		 		 printf("
Contents:
");
		 		 while(1)
		 		 {
		 		 		 if(Byte!=EOF)
		 		 		 {
		 		 		 Byte=fgetc(inFile);
		 		 		 printf("%d",Byte);
		 		 		 fputc(Byte,outFile);
		 		 		 }
		 		 		 else
		 		 		 {
		 		 		 break;
		 		 		 }
		 		 }
		 /*		 for(i=0;c!='
			

Saturday, August 14, 2010

TIC TOE GAME IN C++ CODES

#include<stdio.h>
#include<conio.h>
void Board();
void PlayerX();
void PlayerO();
void Player_win();
void check();
int win=0,wrong_X=0,wrong_O=0,chk=0;
char name_X[30];
char name_O[30];
int pos_for_X[3][3];
int pos_for_O[3][3];
int pos_marked[3][3];
void main()
{
	int i,ch,j;
	char ans;
/*	clrscr();
	printf("\n\t\t\t\tTIC TAC TOE");
	printf("\n\t\t\t\t");
	for(i=1;i<=11;i++)
	{
		delay(10000);
		printf("*");
	}*/
	do
	{
		clrscr();
		printf("\n\t\t\t\tTIC TAC TOE");
		printf("\n\t\t\t\t");
		for(i=1;i<=11;i++)
		{
			delay(10000);
			printf("*");
		}
		printf("\n1.Start The Game");
		printf("\n2.Quit The Game");
		printf("\nEnter your choice(1-2) : ");
		scanf("%d",&ch);
		switch(ch)
		{
			case 1:
				chk=0;
				win=0;
				for(i=1;i<=3;i++)
				{
					for(j=1;j<=3;j++)
					{
						pos_for_X[i][j]=0;
						pos_for_O[i][j]=0;
						pos_marked[i][j]=0;
					}
				}
				printf("\n\n");
				clrscr();
				printf("\nEnter the name of the player playing for \'X\': ");
				fflush(stdin);
				gets(name_X);
				printf("\nEnter the name of the player playing for \'O\': ");
				fflush(stdin);
				gets(name_O);
				Board();
				for(;;)
				{
					if(win==1)
						break;
					check();
					if(chk==9)
					{
						printf("\n\t\t\tMATCH DRAWS!!");
						printf("\nPress any key....");
						break;
					}
					else
						chk=0;
					printf("\nTURN FOR %s:",name_X);
					PlayerX();
					do
					{
						if(wrong_X!=1)
							break;
						wrong_X=0;
						printf("\nTURN FOR %s:",name_X);
						PlayerX();
					}while(wrong_X==1);
					check();
					if(chk==9)
					{
						printf("\n\t\t\tMATCH DRAWS");
						printf("\nPress any key....");
						break;
					}
					else
						chk=0;
					printf("\nTURN FOR %s:",name_O);
					PlayerO();
					do
					{
						if(wrong_O!=1)
							break;
						wrong_O=0;
						printf("\nTURN FOR %s:",name_O);
						PlayerO();
					}while(wrong_O==1);
					}
				Board();
				if(win!=1)
				{
					printf("\n\t\t\tMATCH DRAWS!!");
					printf("\nPress any key.......");
				}
				getch();
				break;
			case 2:
				printf("\n\n\n\t\t\tThank You For Playing The Game.");
				printf("\n\t\t\t###############################");
				getch();
				exit(1);
				break;
		}
		printf("\nWant To Play(Y/N) ? ");
		fflush(stdin);
		scanf("%c",&ans);
	}while(ans=='y' || ans=='Y');
}
void Board()
{
	int i,j;
	clrscr();
	printf("\n\t\t\t\tTIC TAC TOE BOARD");
	printf("\n\t\t\t\t*****************");
	printf("\n\n\n");
	printf("\n\t\t\t    1\t      2\t        3");
	for(i=1;i<=3;i++)
	{
		printf("\n \t\t\t _____________________________");
		printf("\n \t\t\tº\t  º\t   º\t     º");
		printf("\n\t\t%d\t",i);
		for(j=1;j<=3;j++)
		{
			if(pos_for_X[i][j]==1)
			{
				printf("    X");
				printf("     ");
			}
			else if(pos_for_O[i][j]==1)
			{
				printf("    O");
				printf("     ");
			}
			else
			{
				printf("          ");
				continue;
			}
		}
		printf("\n\t\t\tº\t  º\t   º\t     º");
	}
	printf("\n\t\t\t------------------------------");
	Player_win();
}
void PlayerX()
{
	int row,col;
	if(win==1)
		return;
	printf("\nEnter the row no. : ");
	fflush(stdin);
	scanf("%d",&row);
	printf("Enter the column no. : ");
	fflush(stdin);
	scanf("%d",&col);
	if(pos_marked[row][col]==1 || row<1 || row>3 || col<1 || col>3)
	{
		printf("\nWRONG POSITION!! Press any key.....");
		wrong_X=1;
		getch();
		Board();
	}
	else
	{
		pos_for_X[row][col]=1;
		pos_marked[row][col]=1;
		Board();
	}
}
void PlayerO()
{
	int row,col;
	if(win==1)
		return;
	printf("\nEnter the row no. : ");
	scanf("%d",&row);
	printf("Enter the column no. : ");
	scanf("%d",&col);
	if(pos_marked[row][col]==1 || row<1 || row>3 || col<1 || col>3)
	{
		printf("\nWRONG POSITION!! Press any key....");
		wrong_O=1;
		getch();
		Board();
	}
	else
	{
		pos_for_O[row][col]=1;
		pos_marked[row][col]=1;
		Board();
	}
}
void Player_win()
{
	int i;
	for(i=1;i<=3;i++)
	{
		if(pos_for_X[i][1]==1 && pos_for_X[i][2]==1 && pos_for_X[i][3]==1)
		{
			win=1;
			printf("\n\nRESULT: %s wins!!",name_X);
			printf("\nPress any key............");
			return;
		}
	}
	for(i=1;i<=3;i++)
	{
		if(pos_for_X[1][i]==1 && pos_for_X[2][i]==1 && pos_for_X[3][i]==1)
		{
			win=1;
			printf("\n\nRESULT: %s wins!!",name_X);
			printf("\nPress any key............");
			return;
		}
	}
	if(pos_for_X[1][1]==1 && pos_for_X[2][2]==1 && pos_for_X[3][3]==1)
	{
		win=1;
		printf("\n\nRESULTL: %s wins!!",name_X);
		printf("\nPress any key......");
		return;
	}
	else if(pos_for_X[1][3]==1 && pos_for_X[2][2]==1 && 
pos_for_X[3][1]==1)
	{
        	win=1;
		printf("\n\nRESULT: %s wins!!",name_X);
                printf("\nPress any key.....");
		return;
	}
        for(i=1;i<=3;i++)
	{
		if(pos_for_O[i][1]==1 && pos_for_O[i][2]==1 && pos_for_O[i][3]==1)
		{
			win=1;
			printf("\n\nRESULT: %s wins!!",name_O);
                        printf("\nPress any key.....");
			return;
		}
	}
	for(i=1;i<=3;i++)
	{
		if(pos_for_O[1][i]==1 && pos_for_O[2][i]==1 && pos_for_O[3][i]==1)
		{
			win=1;
			printf("\n\nRESULT: %s wins!!",name_O);
                        printf("\nPress any key.....");
			return;
		}
	}
	if(pos_for_O[1][1]==1 && pos_for_O[2][2]==1 && pos_for_O[3][3]==1)
	{
		win=1;
		printf("\n\nRESULT: %s wins!!",name_O);
		printf("\nPress any key.....");
		return;
	}
	else if(pos_for_O[1][3]==1 && pos_for_O[2][2]==1 && 
pos_for_O[3][1]==1)
	{
        	win=1;
		printf("\n\nRESULT: %s wins!!",name_O);
                printf("\nPress any key.....");
		return;
	}
}
void check()
{
	int i,j;
	for(i=1;i<=3;i++)
	{
		for(j=1;j<=3;j++)
		{
			if(pos_marked[i][j]==1)
				chk++;
			else
				continue;
		}
	}
}