How to set the ExecutionPolicy using Powershell

To set the ExecutionPolicy using Powershell, run Powershell as Administrator.
Type in Set-ExecutionPolicy followed by the ExecutionPolicy you wish to use.

  • Restricted: Restricted is the default execution policy. PowerShell scripts are not allowed to run.
  • All Signed: All Signed means thath if they are signed by a trusted publisher.
  • Remote Signed: Remote Signed means, any PowerShell scripts that have been locally created will be allowed to run.
  • Unrestricted: As the name implies, Unrestricted removes all restrictions from the execution policy.
  • Microsoft has disabled scripting by default to prevent malicious code from being executed.

    How to Log off, Restart or Shutdown Windows using Batch

    To Logoff, Restart or Shutdown Windows using Batch you can Simply execute shutdown with the needed parameters. To execute the shutdown command you need the sufficient user privileges.

    List of Parameters

  • -l Logs off the current user, this is also the default. -m ComputerName takes precedence.
  • -s Shuts down the local computer.
  • -r Reboots after shutdown.
  • -a Aborts shutdown. Ignores other parameters, except -l and ComputerName. You can only use -a during the time-out period.
  • -f Forces running applications to close. Note that if you are on a remote machine without using -f your session maybe closed but a hanging program blocks the Shutdown
  • -m [ \\ ComputerName ] Specifies the computer that you want to shut down.
  • -t xx Sets the timer for system shutdown in xx seconds. The default is 20 seconds.
  • -c ” message “ Specifies a message to be displayed in the Message area of the System Shutdown window. You can use a maximum of 127 characters. You must enclose the message in quotation marks.
  • -d [ u ][ p ] : xx : yy Lists the reason code for the shutdown. Reason Codes (u=Indicates a user code), (p=Indicates a planned shutdown cod), (xx=Specifies the major reason code (0-255)), (yy=Specifies the minor reason code (0-65536)
  • /? Displays help at the command prompt.

    How to download a image from url in C# and VB.NET

    Sample C#

    private static void DownloadImage(string url, string saveFilename)
    	var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    	var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    	if ((httpWebResponse.StatusCode != HttpStatusCode.OK && 
    		httpWebResponse.StatusCode != HttpStatusCode.Moved && 
    		httpWebResponse.StatusCode != HttpStatusCode.Redirect) 
    		|| !httpWebResponse.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
    	using (var stream = httpWebResponse.GetResponseStream())
    	using (var fileStream = File.OpenWrite(saveFilename))
    		var bytes = new byte[4096];
    		var read=0;
    			if (stream == null) {continue;}
    			read = stream.Read(bytes, 0, bytes.Length);
    			fileStream.Write(bytes, 0, read);
    		} while (read != 0);

    Sample VB.NET

    Private Shared Sub DownloadImage(url As String, saveFilename As String)
    	Dim httpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
    	Dim httpWebResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
    	If (httpWebResponse.StatusCode <> HttpStatusCode.OK AndAlso httpWebResponse.StatusCode <> HttpStatusCode.Moved AndAlso httpWebResponse.StatusCode <> HttpStatusCode.Redirect) OrElse Not httpWebResponse.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase) Then
    	End If
    	Using stream = httpWebResponse.GetResponseStream()
    		Using fileStream = File.OpenWrite(saveFilename)
    			Dim bytes = New Byte(4095) {}
    			Dim read = 0
    				If stream Is Nothing Then
    					Continue Do
    				End If
    				read = stream.Read(bytes, 0, bytes.Length)
    				fileStream.Write(bytes, 0, read)
    			Loop While read <> 0
    		End Using
    	End Using
    End Sub