Monday 27 January 2014

Microsoft: Delete Files after a Certain Number of Days

You may delete the file(s)  after a certain number of days with the ForFiles command.
forfiles -p "C:\what\ever" -s -m *.* /D -<number of days> /C "cmd /c del @path"

FORFILES.exe (Native command in Vista/Windows7/2008, via Resource Kit for XP)
Select a file (or set of files) and execute a command on each file. Batch processing.

Syntax
      FORFILES [/p Path] [/m SrchMask] [/s] [/c Command] [/d [+ | -] {date | dd}]

Key
  • /p Path: The Path to search  (default=current folder)
  • /m SrchMask: Select files matching the specified search mask (default = *.*)
  • /s: Recurse into sub-folders
  • /C command: The command to execute for each file. Wrap the command string in double quotes. Default = "cmd /c echo @file" The Command variables listed below can also be used in the command string.
  • /D date: Select files with a last modified date greater than or equal to (+), or less than or equal to (-), the specified date, using the region specific date format typically "MM/DD/yyyy" or "DD/MM/yyyy"
  • /D + dd: Select files with a last modified date greater than or equal to the current date plus "dd" days. (in the future)
  • /D - dd: Select files with a last modified date less than or equal to the current date minus "dd" days. (in the past) A valid "dd" number of days can be any number in the range of 0 to 32768.   (89 years) "+" is taken as default sign if not specified.
   Command Variables:
  • @file: The name of the file
  • @fname: The file name without extension            
  • @ext: Only the extension of the file            
  • @path: Full path of the file
  • @relpath: Relative path of the file      
  • @isdir: Returns "TRUE" if a file type is a directory and "FALSE" for files                
  • @fsize: Size of the file in bytes
  • @fdate: Last modified date of the file
  • @ftime: Last modified time of the file
To include special characters in the command line, use the hex code for the character in 0xHH format (ex. 0x09 is theTAB character, 0x22 is the double quote " character.) so "C:\Program Files\" becomes ^0x22C:\Program^ Files\^0x22

Internal CMD.exe commands must be preceded with cmd /c

If ForFiles finds one or more matches if will return %errorlevel% =0
If ForFiles finds no matches if will return %errorlevel% =1 and will print "ERROR: No files found with the specified search criteria."

Early versions of FORFILES were supplied in the NT resource kits and used unix style '-' parameters, (still supported for backwards compatibility) also the /D option accepted dates only in DDMMYYYYHHMN format.

Last modified dates set in the future are not common but can happen when your computer clock date/time is changed e.g. due to daylight savings time.


Reference:
FORFILES.exe
http://ss64.com/nt/forfiles.html

Saturday 25 January 2014

Google: Google Apps Education Individual Qualification (IQ)

I have finally passed the five Google Apps Education exams and earned the certificate of Google Apps Education Individual Qualification (IQ).

If you are interested in testing your new knowledge acquired in the Training Center you can take all five exams.  Passing all five exams will give you the honor of being “Google Apps Education Qualified” and earn you a certificate. Google Apps Certificate The exams are $15 dollars each and you will need to pass each exam with a score of 80% or higher.  You can make a bundle purchase as well which is $75 dollars.


Reference:
Google Testing Center
https://google.starttest.com/

Thursday 23 January 2014

Microsoft: Redirect HTTP to HTTPS on IIS

Here are the steps to redirect your website from HTTP to HTTPS:
(Pre-requisites: HTTP Redirect module is installed and the website has a valid HTTPS binding in place.

1.  Launch the IIS Manager.

2.  Go to the HTTP Redirect module.

3.  Fill the details as per the requirement as shown below:


Reference:
HTTP to HTTPS redirects on IIS 7.x and higher
http://blogs.msdn.com/b/kaushal/archive/2013/05/23/http-to-https-redirects-on-iis-7-x-and-higher.aspx

Microsoft: Enable Basic Authentication for WebDAV on Windows 7

If you are having difficulty using Windows 7 to connect to a Web-based application on an Apache/Linux-based WebDAV server, you may need to enable support for Basic Authentication for WebDAV on your Windows 7 computer. To do this, open Registry Editor and create the following new registry entry under HKLM\SYSTEM\CurrentControlSet\Services\WebClient\Parameters:

Name: BasicAuthLevel

Type: DWORD (32-bit) Value

Value: 2

If you do this, you should make sure the Web-application uses SSL since the Basic Auth password is sent in cleartext.

Note that the possible values you can assign to this new registry entry are:

0 - Basic authentication disabled

1 - Basic authentication enabled for Secure Sockets Layer (SSL) shares only

2 or greater - Basic authentication enabled for SSL shares and for non-SSL shares

The following Windows command can help you to automate the change:
@echo ##############################################
@echo ##### WebDAV Script by Andres Cheah #####
@echo ##############################################
@echo #####                                    #####
@echo ##                                          ##
@echo #                                            #
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\WebClient\Parameters /v BasicAuthLevel /t REG_DWORD /d 0x2
net stop webclient
net start webclient
@echo ###You are ready to map the WebDAV drive!###
pause

Reference:
Enable Basic Auth for WebDAV on Windows 7
http://www.windowsnetworking.com/kbase/WindowsTips/Windows7/AdminTips/Security/EnableBasicAuthforWebDAVonWindows7.html

Microsoft: Error for Adding SSL Binding in IIS

<<Problem>>
Below is a snapshot of the error message while trying to add the SSL binding in IIS.

<<Cause>>
The most common scenario is when the users use the IIS MMC to import a certificate and they uncheck the option “Allow this certificate to be exported”. This results in a broken keyset and thus results in the problem.

<<Solution>>
There are two ways to fix this problem. Before we start off, delete/remove the existing certificate from the store.

  • If using IIS MMC to import the certificate, then ensure that the “Allow this certificate to be exported” is checked.
  • If making the private key exportable is not an option, then use the Certificates MMC to import the certificate. Please go through the following KB on how to import a certificate using the MMC: http://support.microsoft.com/kb/232137


Reference:
Error HRESULT: 0x80070520 when adding SSL binding in IIS
http://blogs.msdn.com/b/kaushal/archive/2012/10/07/error-hresult-0x80070520-when-adding-ssl-binding-in-iis.aspx

Microsoft: Setup HTTPS / SSL for a Website on IIS

Please follow the steps below to setup the HTTPS / SSL for your website:

1.  Select the server node in the tree view and double-click the Server Certificates feature in the list view:

2.  Click Import... in the Actions pane.

3.  Browser the certificate and type in the correct password. Then, import.

4.  Once the certificate is imported, select a site in the tree view and click Bindings... in the Actions pane. This brings up the bindings editor that lets you create, edit, and delete bindings for your Web site. Click Add... to add your new SSL binding to the site.

5.  The default settings for a new binding are set to HTTP on port 80. Select https in the Type drop-down list. Select the self-signed certificate you created in the previous section from the SSL Certificate drop-down list and then click OK.

6.  Now you have a new SSL binding on your site and all that remains is to verify that it works.
7.  Configure SSL settings if you want your site to require SSL, or to interact in a specific way with client certificates. Click the site node in the tree view to go back to the site's home page. Double-click the SSL Settings feature in the middle pane.


8.  In the Actions pane, under Browse Web Site, click the link associated with the binding you just created.

9.  Internet Explorere (IE) 7 and above will display an error page because the self-signed certificate was issued by your computer, not by a trusted Certificate Authority (CA). IE 7 and above will trust the certificate if you add it to the list of Trusted Root Certification Authorities in the certificates store it on the local computer, or in Group Policy for the domain. Click Continue to this website (not recommended).


Reference:
How to Set Up SSL on IIS 7
http://www.iis.net/learn/manage/configuring-security/how-to-set-up-ssl-on-iis

Wednesday 22 January 2014

Microsoft: Publish DFS with WebDAV

<<Server>>
For your information, I setup the WebDAV server on Windows Server 2008 R2. Here are the steps for you to setup a WebDAV server to publish the DFS.

1.  On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.

2.  In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).

3.  In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.

4.  On the Select Role Services page of the Add Role Services Wizard, expand Common HTTP Features, select WebDAV Publishing, and then click Next.

5.  On the Confirm Installation Selections page, click Install.

6.  On the Results page, click Close.

7.  In IIS Manager, in the Connections pane, expand the Sites node in the tree, then click the Default Web Site.

8.  As shown in the image below, double-click the WebDAV Authoring Rules feature.

9.  When the WebDAV Authoring Rules page is displayed, click the Enable WebDAV task in the Actions page.

10.  Once WebDAV has been enabled, click the Add Authoring Rule task in the Actions pane.

11.  When the Add Authoring Rule dialog appears:

  • Click All content to specify that the rule applies to all content types.
  • Choose "All users".
  • Select Read, Source, and Write for the permissions.
  • When you have completed these items, click OK.


12.  In IIS Manager, in the Connections pane, expand the Sites node in the tree, then click the Default Web Site.

13.  Double-click the Authentication feature.

14.  When the Authentication feature opens, make sure only the Basic Authentication is enabled. (Note: If Basic Authentication is not available in the options, please go to Roles > Web Server (IIS) > Add Role Services > Security > Basic Authentication and install the role.)

15.  In IIS Manager, click the Default Web Site under the Sites node in the tree.

16.  Double-click the Authorization feature. (Note: If Authentication Rules is not available in the manager, please go to Roles > Web Server (IIS) > Add Role Services > Security > URL Authorization and install the role.)

17.  When the Authorization feature opens, make sure that an Allow rule is defined that includes all users.

18.  On your WebDAV server, open a command prompt session.

19.  Type the following command to connect to your WebDAV server:
net use * http://localhost/
(Note: If you are not able to connect to your WebDAV server, you may want to go to Features > Add Features > Desktop Experience and install the feature.)

20.  Once you are able to connect to your WebDAV server, please proceed with the directory setup. Right click at the Default Web Site and select Manage Web Site > Advanced Settings...

21.  Please type in the domain admin account that can grant the full access on the web site at the Physical Path Credentials and click OK.

22.   Right click at the Default Web Site and select Add Virtual Directory...

23.  Type in the preferred Alias and the DFS path / UNC (Uniform Naming Convention). Then, click OK. Now, your WebDAV server is completed.


<<Client>>
You may setup the client now as follows:
1.  Open any browser and type in the respective URL (eg. http://<server name>/share). After that, type in the user name and password that you have used to log in to DFS. (Note: Please include the domain name in your user name.)

2.  For Mac OS X, go to Connect to Server and type in the respective URL (eg. http://<server name>/share). After that, type in the user name and password that you have used to log in to DFS. (Note: Please include the domain name in your user name.)

3.  For Windows, open the command prompt and type in the following command:
net use * http://<server name>/share <password> /user:<domain name/user name>


Reference:
Installing and Configuring WebDAV on IIS 7
http://www.iis.net/learn/install/installing-publishing-technologies/installing-and-configuring-webdav-on-iis