11 August 2014

How to give password to the Word file?



Step 1: File -> Prepare -> Encrypt Document.
Step 2: Enter password and click on OK .

Step 3: Save the file.

How to find out the SQL Server installation date?



SELECT create_date as 'Installation Date' FROM sys.server_principals WHERE name='NT AUTHORITY\SYSTEM'

9 August 2014

How to find all printers in your Active Directory



         private void FindAllPrinters()
           {
               string[] wantedProps = { "name", "servername", "printername",
                                          "drivername", "shortservername", "location" };
    
               var ds = new DirectorySearcher { Filter = "(objectClass=printqueue)" };
               foreach (SearchResult sr in ds.FindAll())
               {
                   Debug.WriteLine(sr.Path);
                   ResultPropertyCollection rpc = sr.Properties;
    
                   // use rpc.PropertyNames instead of wantedProps if you want to
                   // know more about the printers than is provided below
                   foreach (string property in wantedProps)
                   {
                       foreach (object value in rpc[property])
                           Debug.WriteLine(string.Format("\t{0}: {1}", property, value));
                   }
               }
           }

loop through a table in SQL Server

Create table

CREATE TABLE tbl_Sample
(
     ID      int identity (1,1)
    ,Name    varchar(50)
)

Loop through Code

DECLARE @minID int
 -- get the first record
SELECT @minID = min(ID) FROM tbl_Sample
 -- loop until we have no more records
WHILE @minID is NOT NULL
BEGIN
    -- do actual work, for instance, get the Name and Address for this ID
    SELECT Name FROM tbl_Sample WHERE ID = @minID
     -- get the next record
    SELECT @minID = min(ID) FROM tbl_Sample WHERE @minID < ID
END