Showing posts with label Tips and Tricks. Show all posts
Showing posts with label Tips and Tricks. Show all posts

Auto Start Website on IIS 7.0 or 7.5

Some time we may need to restart application pools regularly or we may need to restart the system on certain intervals. At that time, the first user to hit the site has to wait while everything is warms up again. It may take some time may be up to 30 to 60 seconds or above. To avoid this lag time for the first user, Microsoft introduced a feature called Application Initialization. It will automatically initialize the application when application pool starts and avoid the time lag for the first user.

In IIS 8 Application Initialization is part of the IIS feature set. But in IIS 7.0 or 7.5 you need to install this feature from here . It requires a system reboot.

Once it installed, you can check the it in IIS.
  1. Open IIS and click or the server node
  2. In the details pane open the Configuration Editor under Management
  3. Inside the editor, check for the section "System.webServer/applicationInitialization" in the Section drop down list in the top. If you find the section, it is installed successfully.

Now IIS is all set but you need to tell which application pools and websites you want to start. Just open 

C:\Windows\System32\inetsrv\config

and open the applicationHost.config file and do the following changes (Make sure to take a backup of the file before you make changes).

1) Applicaton pools Section:
Find the applicationPools node and add startMode="AlwaysRunning" to the application pool which needs to be start automatically.
<add autoStart="true" managedRuntimeVersion="v4.0" name="Jobs" startMode="AlwaysRunning"/>
Check whether it's autoStart property is "true". Otherwise set it to true. If it is not  there or its value is false then will not autoStart.

2) Web site Section:

Go to the sites node and find your site to which you need to start automatically and set preloadEnabled="true".
<application applicationPool="APPLICATION POOL NAME" path="YOUR SITE NAME" preloadEnabled="true">
        <virtualDirectory path="/" physicalPath="YOUR SITE PHYSICAL PATH">
        </virtualDirectory>
</application>
That's it. Now your site will starts automatically.


Run two Skype accounts in one computer

To use more than one Skype account on the same computer at the same time you need to start a new instance of Skype.
Method 1:
a) From the Windows taskbar, click Start > Run (or press the Windows and R keys on your keyboard at the same time)
b) In the Run window, enter the following command (include the quotes) and press OK.
"C:\Program Files\Skype\Phone\Skype.exe" /secondary 

      If you get an error message, copy and paste the exact command from this page and try again.Be aware that if you have changed the installation path for Skype then you will need to enter the correct path for the Skype.exe file.

Method 2:
a) Find the Skype executable file (Skype.exe) in: C:\Program Files\Skype\Phone\ 
b) Right click on it and select Send to > Desktop (create shortcut)
c) Locate the shortcut on the desktop, then right-click on it and select Properties
d) In the Target field, add: /secondary. The Target field should now be
       "C:\Program Files\Skype\Phone\Skype.exe" /secondary 
e) Click OK.
     You can now start a new instance of Skype every time you double-click the new shortcut.

How to debug Windows Service Without installing it

While developing a Windows service if you want to debug or run it will give you the following message.

"Cannot start service from the command line or a debugger.A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command."

So for debugging you first install the service, but it is a long process because every time you make changes, you need to reinstall your service and debug it again.

Here is the solution for avoiding this long process.

For debugging your service without installing it, make changes in Program.cs like this.
Suppose if your Program.cs file is

static class Program
{
    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[]
{
    new MyWindowsService()
};
        ServiceBase.Run(ServicesToRun);
    }
}

Change the above code like below

static class Program
{
    static void Main()
    {
        #if(!DEBUG)
           ServiceBase[] ServicesToRun;
           ServicesToRun = new ServiceBase[]
  {
       new MyWindowsService()
  };
           ServiceBase.Run(ServicesToRun);
         #else
           MyWindowsService myWindowsServ = new MyWindowsService();
           myWindowsServ.RunService();
         
         #endif
    }
}

Here RunService is My Service function that initiates the OnStart Event of the Service.

Now if you run your service then it will not show you the above message. It simply runs the service. Now you can debug you application by simply adding the breakpoints.


Lock your folder with a batch file

You can make the folder lock software by your own.
Just Copy and paste the following code into a notepad and save it as a batch file (i.e. with ".bat" extension).
Then close the notepad and click the batch file. It creates a folder with name "Locker" in the same location.
Now paste all the folders and files which you want to hide into the "Locker" folder. Double click the batch file and enter 'y'  or 'Y' to lock the folder. It will locks your folder.
If you want to unlock your folder, double click the batch file again and you would be prompted for password.
Enter the password and access your files


if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Locker goto MDLOCKER
:CONFIRM
echo Are you sure u want to Lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
cls
echo Invalid choice.
goto CONFIRM
:LOCK
ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
cls
echo Folder locked
goto End
:UNLOCK
echo Enter password to Unlock folder
set/p "pass=>"
if NOT %pass%=="your password" goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker
cls
echo Folder Unlocked successfully
goto End
:FAIL
cls
echo Invalid password
goto UNLOCK
:MDLOCKER
md Locker
cls
echo Locker created successfully
goto End
:End



In the above code change the "your password" with your password before saving as batch file(remove the double quotes also) It is the password to unlock your folder