WinPE and .NET (Part 2): Creating and Editing Variables

In Part 1 we saw how to prepare a visual studio solution to be able to access the OSD Environment as well as obtain one specific or all of our task sequence variables. In there I linked a full solution that allows you to get all of those variables in a variety of file formats (txt, csv, xml, etc…).

In Part 2, I’ll be going over creating and setting Task Sequence variables via c# and .NET. If you have not read Part 1, please do. There are some important references and steps that need to be performed in order to properly access the environment.

As highlighted in Part 1, we need to:

  1. Extract and create our DLL (If you did this in Part 1, you can reuse this DLL)
  2. Create a solution setting the target framework to “.Net Framework 4”
  3. Reference the assembly in your solution

Now, just like we did in Par 1, we’ll need to create an instance of our Task Sequence environment:

ITSEnvClass TsEnvVar = new TSEnvClass();

If you recall the way we obtained variable names was using the GetVariables method of our Task Sequence Environment Instance. To get the value of a specific variable we accessed this by:


Creating and Setting variables is just as easy! In fact, its the exact same! With our Task Sequence Environment Instance (TsEnvVar):

TsEnvVar["VariableName"] = "VariableValue";

Really…that’s all there is to it! I’d like to say there’s more magic behind this but really there isn’t!

To help with your own implementations of this, I’ve created a helper class that can be used for getting and setting variables. While is is very basic, it does give a good ‘skeleton’ to work with. I’ve used this class in countless projects for both my company and other experiments/tests I’ve done. You can view this class here.

Up Next: In Part 3 I’ll go through a very quick and basic Task Sequence Wizard using WPF and C#!




3 thoughts on “WinPE and .NET (Part 2): Creating and Editing Variables

  1. Pingback: WinPE and .NET (Part 1): Get Task Sequence Variables | Noah Swanson's Tech Blog

  2. Pingback: WinPE and .NET (Part 3): WPF OSD Task Sequence Wizard | Noah Swanson's Tech Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s