Freigeben über


Gaming with the Windows Troubleshooting Platform

Today we’re going to dive straight into a fun, simple project; creating a multiple choice trivia style game using the Windows Troubleshooting Platform. We’re skipping the architecture, applicability, and design discussions; instead we’ll build this simple game that’ll run in our troubleshooting pack. Let’s get to it! Before we get started, let’s go thru the list of things you’ll need.

1. A computer running Windows 7

2. Basic understanding of PowerShell

3. Windows 7 SDK

The first step is to install the tools that we’ll use to build your troubleshooting pack. These tools are included in the Windows 7 SDK, which is available here. If you’re only interested in building troubleshooting packs you don’t need to install the entire SDK, you only need to install the “Win32 Development Tools”

Now let’s get into the tool and start building a troubleshooting pack. Launch the Windows Troubleshooting Pack Designer.

1. Start

2. All Programs

3. Microsoft Windows SDK v7.0

4. Tools

5. Windows Troubleshooting Pack Designer

Remember, we’re building a game, which isn’t the most appropriate use of this technology, but whatever. We’re going to build a simple question and answer game. Select New from the Project menu to create the troubleshooting pack. Call this pack “Guess” then click create. Now we get to define what our troubleshooter will look like. On this first screen we can see the project name, description, and privacy URL, all of which will be displayed on the first screen of the troubleshooter. Add a description to your troubleshooter and enter in a URL for the privacy link (this can be any URL for now).

Next we need to add a “Root Cause”. In a real troubleshooter the root cause is a specific problem that you’re trying to fix, like “service x is stopped”. For our guessing game, we’ll make a root cause for when the player guesses incorrectly. Click “Add New Root Cause”, enter the following values, and then click next.

  • Root Cause ID: GuessIsWrong
  • Root Cause Name: Oops! You've guessed wrong!
  • Root Cause Description: The answer you selected was incorrect.

The next screen will ask us a little bit more about this root cause. Does the user need to be elevated to detect the problem? Does the user need to answer any questions? We don’t need elevation, but we do need the user to answer questions, so check Yes under Interactions. Notice that when you select yes a new list of interactions appears. We’ll define the questions for our game here. Click the Add Interaction button.

The Interaction Designer needs to know which type of question we want to ask. We’re going to limit our game to single answers of a multiple choice question, so select the single response type. Next you’ll need to define the specifics for this interaction. Enter the following values.

  • Interaction ID: Question_01
  • Question or Prompt: In what year was Microsoft founded?
  • Explanation: Please select an answer from the list of choices below.

Now we need to add some answers. Scroll down to the Choice List, click Add Choice, and enter the details for each answer. The title and description fields will be shown to the player; the value field will be used by our PowerShell script to determine which answer was selected. Add the choices listed below, and then click OK.

Title

Description

Value

1970

 

0

1975

 

1

1977

 

2

1980

 

3

 

Each root cause that you define needs a resolver. This is the action that should be taken when the root cause is detected. In our case, we want to educate the player if they choose the wrong answer. Click Add Resolver and fill out the fields as follows.

  • Resolver Name: Show the history of Microsoft
  • Resolver Description: Display "The History of Microsoft" video series on Channel 9
  • Prompt the User: Yes
  • Elevation: No
  • Interactions: No

Finally, we must define if the fix can be verified. For the purposes of our game we won’t ask the player the same question again. Click Define Verifier, select no under verifiable then click next.

Now you’re ready to save and run your troubleshooting pack. Click save, then select run from the build menu. First you’ll be asked to install a test certificate for testing, click OK to continue. If you skip this step your troubleshooting pack won’t work!

At this point your troubleshooter doesn’t do much, but that’s about to change. Notice that when you ran the troubleshooter it found the “Oops! You’ve guessed wrong!” problem. Let’s go change this so that it’s based on the answer to our question. Click on the Scripts node in the troubleshooting pack designer, then click edit troubleshooter script. This will open the PowerShell editor and display your troubleshooting script. You’ll notice that by default is just passes true to the update-diagrootcause cmdlet, which tells the troubleshooter if the problem was found.

First thing we need to do is show the player the question and get the answer. This is pretty simple; all we need to do is call the get-diaginput cmdlet, pass it the id of our question, and get the result. This is what that looks like in PowerShell

#Ask the customer a question
$Answer = Get-DiagInput –id Question_01

The answer variable will contain the value, not the text, for the selected answer. Next we need to determine if the answer is correct. In this case, the correct answer is “1975”, which has a value of 1. This is the value that we entered for this item in the choice list. Checking for the correct answer is now pretty simple; if the answer is 1 then they answered correctly, otherwise it’s incorrect. Here is the completed PowerShell for our troubleshooter. Notice that I’ve also changed $RootCauseDetected to set the problem (“Oops! You’ve guessed wrong!”) to be true only if the answer is incorrect.

$RootCauseID = “GuessIsWrong”

#Ask the customer a question
$Answer = Get-DiagInput –id Question_01

#Check the answer
if ($Answer –eq 1)
{
#Question answered incorrectly
$RootcauseDetected = $False
}
else
{

#Question answered correctly
$RootcauseDetected = $True
}

#The following line notifies Windows Troubleshooting Platform of the status of this root cause
update-diagrootcause –id $RootCauseId –detected $RootCauseDetected

Save your PowerShell script, switch back to the troubleshooting pack designer, and hit run. Now the player has a question to answer! Run thru it a few times picking different answers to see how the rest of the experience changes.

Now it’s time to set up our resolver. Click on the scripts node again, then click edit resolver script. By default, your resolver script is empty. We want to display the “History of Microsoft” web page if they user answers incorrectly. To do this, add the following line to your PowerShell script.

explorer.exe “https://channel9.msdn.com/shows/History”

That’s it. Save your script and run your troubleshooter. Now when the player answers incorrectly they’ll be taken to the site. Our game is complete! This is a very simple example, but you’ve used most of the elements that you’d need to build a full-fledged troubleshooter. You’ve asked the customer for input, evaluated their answer, and taken an action when the “problem” was detected. We could flesh out this game a bit more by adding more questions, keeping score, loading questions from a file, etc. All of this is possible within the windows troubleshooting pack framework. You can even create your own text-based adventure game as a troubleshooting pack; maybe I’ll cover that in a later example…

It’s not the intended purpose of the platform, but it’s good for a laugh. Enjoy!

-MB

Comments

  • Anonymous
    November 01, 2010
    How do you put in a fill in the blank question in powershell