Galin Iliev's blog

Software Architecture & Development

Reboot PC from network

Today I tried to to RDC(Remote Desktop Connection) to a remote computer (of course) and I got a nasty error basically saying that I need to restart the machine in order to connect to it :) So I searched the web for a bit, connected to another computer in same LAN, shot the command and waited for about 5 minutes and… voila. I was able to connect.

So what is the command?! shutdown, of course :)

shutdown -m //computername -r -f
-s shutdown
-r restart
-f force close any applications
//computername or ip

Or just run
shutdown /i
and the UI on the right will appear to make you feel more

For more information see Microsoft Knowledge Base Article: How To Use the Remote Shutdown Tool to Shut Down and Restart a Computer in Windows 2000.

P.S. The target machine was Windows Server 2008 so this one still works :)


Cross-site request forgery or how dangerous REST can be if not implemented properly

A friend of mine send me link to article in Wikipedia describing Cross-site request forgery attack.

Cross-site request forgery, also known as one-click attack or session riding and abbreviated as CSRF ("sea-surf"[1]) or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts.[2] Unlike cross-site scripting (XSS), which exploits the trust a user has for a particular site, CSRF exploits the trust that a site has in a user's browser.

(source Wikipedia)

This is how the attack is performed:

<img src="http://bank.example/withdraw?account=bob&amount=1000000&for=mallory">

Note how simple this would be?! And end user won’t see anything – not even image :).

This illustrates why is so important when implementing REST in your services to do only read on GET requests.

C# 4.0 vs Visual Basic 10

This is how close will become C# and VB in next release:

C# 4.0 Visual Basic "10"
Named/Optional Parameters Named/Optional Parameters
Dynamic Scoping Dynamic Scoping
Statement Lambdas Statement Lambdas
Multiline Lambdas Multiline Lambdas
Auto-Implemented Properties Auto-Implemented Properties
Collection Initializers Collection Initializers
Generic Variance Generic Variance
Extension Properties Extension Properties

The items in white-bold are new features…

(Source: PPTX from VS2010 and .NET Framework 4.0 Training Kit)

MSBuild resources

MSBuild is very powerful language for automating build process but as every computer thing it could be confusing.

So for a start this should work as Visual Studio solution files (*.sln/*.proj) files are valid MSBuild files:

MSBuild MySolution.sln

So for more script-like example this can show how complex solution with Web Application project can be build and files (result of publish operation) copied to drop location.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns= 
  <Target Name="Clean">
    <Exec Command="MSBuild.exe WcfFileTransfer.sln /t:Clean" />
  <Target Name="Build">
    <Exec Command="MSBuild.exe WcfFileTransfer.sln /t:Rebuild /p:Configuration=Release 
/p:OutDir=..\$(OutputFiles)" ContinueOnError="False" />

      <!--include needed files-->
      <WebFiles Include="$(PrecompiledWeb)**\*.*"
    <!--show message-->
    <Message Text="Copying to Deployment Dir:@(WebFiles) to $(ReleseFolder) :" />
    <!--perform recursive copy-->
            DestinationFiles="@(WebFiles->'$(ReleseFolder)\%(RecursiveDir)\%(Filename)%(Extension)')"  />

This script is executed from Visual Studio Command Prompt like this

MSBuild build.proj

For more information  about MSBuild you can take a look at MSDN reference page or Channel9 Wiki:

* Project File Format
* Shipping Tasks
* Loggers
* Tasks
* VS / Integration
* Conversion
* MSBuild.exe Command Line
* Object Model
* Scenarios
* Does Microsoft use to build its own products?
* How to execute CS templates from MSBuild?
* External Links and Resources
* Quick Start Tutorials
* Write a simple project
* Clean my Build
* Specify which Target to Build First
* Build All Files in a Directory
* Build All Files in a Directory Except One
* Build the Same Sources with Different Options

* Use Environment Variables in a Build
* Check whether an Environment Variable has been set
* Build a Project with Resources
* Build Incrementally
* Use the Same Target in Multiple Project Files
* Tell to Ignore Errors in Tasks
* Extend with a New Task
* Build a Set of Dependant Projects
* Run a Custom Tool From my Project
* Specify Several Build Options on the Command Line
* Use Reserved XML Characters in Project Files
* Display an Item List Separated with Commas
* Convert an Item List into a scalar string
* Reference the Name or Location of the Project File in the Project File
* How do I do a recursive copy?
* Batching Examples
* MSBuild Specifications
* How the batching algorithm works
* How to find targets files in a canonical place

Or the MSBuild: By Example tutorial:

  1. Introducing Well-Known Metadata
  2. Formatting Your Output
  3. Editing MSBuild Files with IntelliSense
  4. Integrating MSBuild into Visual Studio
  5. Introducing Custom Metadata
  6. Understanding the Difference Between @ and %
  7. Using Environment Variables in Your Project
  8. Reusing MSBuild Project Elements
  9. Dealing with MSBuild Errors

I hope this is good as a start.

It’s playtime… with C# 4.0

After being quite busy for last 4 months it is a time to ramp up with new cool technologies that are on the product line.

So while installing VS 2010 it is a good reading to find out what to do once it is done:

And of course get some free time – a night or two should be enough :) should be enough for starting…

How cool is that…

What is it if not the future :)

This could solve the biggest two issues for cell phones and mobile computers – keyboard and screen size