Arcane Tricks: Cut / Copy / Paste To and From Virtual PC

As you might guess from my various posts, I like using Virtual PC. It has one annoyance, you can’t cut / copy / paste between the Virtual PC and another machine, like the host operating system.

This is actually a good thing, as it’s a security feature. It allows you to test suspicious software safely, without fear of it damaging your host. There are times though, when you know it is safe to allow the cut / copy / paste connection between your Virtual PC and your host. It would be nice to have a switch or option that turns this on and off. Sadly, it’s not there.

There is a work around though. Back in December, I talked about the combination of Virtual PC and Remote Desktop. (https://arcanecode.wordpress.com/2006/12/06/arcane-combinations-virtual-pc-and-remote-desktop/ or http://shrinkster.com/mvq) . While VPC lacks the ability to cut / copy / paste, Remote Desktop does not. Using Remote Desktop you can cut, copy, and paste data from your host (or any other remotely controlled PC) to the Virtual PC you are controlling via Remote Desktop.

All you have to do is follow the instructions in the post mentioned above, and “remote” into the virtual machine. Yes, you will be remoting to a machine running on the same box, but all the remote desktop software sees is an IP address. It can’t tell if that IP is on the same host computer or one across the planet.

This little trick has saved me several times, and was one of those “doh!” moments when it first occurred to me. Even if you have been following along and using Remote Desktop with VPC, it may not have occurred to you to use it on the same machine.

Resources

Advertisements

Arcane Thoughts: Thanks to you, ArcaneCode made the top 5!

Thanks! Thanks to all of you. In the WordPress Wednesday they were showing how rapidly the list of top blogs changes. For a brief time anyway, the Ubuntu post was #5 on the “What’s Hot” list. Read for yourself at http://www.blogherald.com/2007/03/14/wordpress-wednesday-mandatory-update-reminder-wordcamp2007-instant-upgrade-plugin-sxsw-conference-and-more/ or http://shrinkster.com/mvt.

ArcaneCode has been averaging about 800 hits a day lately, and has had over 24,000 hits at the time I write this.

I just wanted to say thanks to everyone who has read ArcaneCode, and passed on links to all their friends. That’s what the whole social web thing is all about, helping each other out.

Thanks!

Allowing Remote Desktop Access to Windows XP, Step by Step

Way back in October of last year (https://arcanecode.wordpress.com/2006/10/09/remote-desktop-connection/ or http://shrinkster.com/mvr) I wrote about using the Remote Desktop tool.

A few people have had problems accessing their desktops, so I thought I’d provide some step by step instructions on how to allow your computer to be access via Remote Desktop.

First, open Control Panel.Then, open the User Accounts.

Click “Change the way users log on or off” and uncheck “Use the Welcome screen”. Click Apply Options.

[Picture of User Acct Screen]

Click on your account, and make sure it has a password. If not, click “Create a password”, then create one.

Close out the user accounts, then close out Control Panel.

Right click on the “My Computer” icon, and pick Properties.

Select the “Remote” tab.

Check the box on that reads “Allow users to connect remotely to this computer”.

[Pic of System Properties Remote tab]

Click Apply and OK, and you should now be able to access your computer via Remote Desktop. Just follow my instructions in the post I mentioned at the beginning of the message and you should be in good shape!

Developing From The Network

When developing, it’s nice to be able to save and run your projects from your corporate network. Network drives are typically backed up, where local hard drives are often not unless you take the time to do it yourself.

As part of it’s code security initiative, the .Net Framework protects us by not allowing us to run code from an “unsafe” location. Unfortunately .Net often sees company networks as locations that are not safe.

It’s easy enough to remedy, with a simple command that no one seems to know about. I finally lucked out and found a brief reference on Chris Sells blog. I’d like to expound on his entry slightly and go into a little detail about what’s going on.

First though, let me give you the command in case you are the type of person who just wants a quick fix:

First, navigate to your c:\windows\microsoft.net\framework\ directory. Now, if you are using .Net 1.1, drop into the v1.1.4322 folder, if you are using .Net 2.0, go into the v2.0.50727 directory. Now execute the command

caspol -q -machine -addgroup 1 -url file://z:/* FullTrust -name “Z Drive”

Make sure to type it in all as one single command, in case your reader has wrapped the line. The two things you need to note are the folder designation, z:/* and the name in quotes “Z Drive”. For the z:/* put the drive letter for the network drive you want to give permissions to. You can also add a folder if you want to narrow it down for security, such as z:/myprojects/* .

Inside the quotes you can put anything you want, I made it easy and named it Z Drive, but you could call it “Projects on Z” or “My Projects” or “Arcane is a wizard at this coding stuff”.

Now for those who are a bit more inquisitive, here’s a breakdown of the command line options.

-q     Runs in quiet mode, suppressing all of the normal “are you sure” prompts

-machine     The commands will apply to this computer.

-addgroup     This adds a new security group to your machine, with the name you enter in quotes.

1     is the parent group under which you are adding, use 1 for the base group on the machine.

-url file:     Indicates we are adding a url, in the form of a file spec. Normally caspol expects your adding a website or webservice you want to execute code from, using the file: spec gives us a work around to add a network drive.

FullTrust     Again, an obvious entry that sets the security level in addgroup.

-name     Obviously the name you want to give to your group. Following the –name place the name in double quotes, such as –name “Z Drive”

After issuing the command, you probably want to verify your new permissions have been set. To do so, use this command:

caspol –listgroups

This will list your security groups, with your newly named group (the name you put in quotes) at the bottom of the list. It should look something like:

1.7. Url – file://z:/*: FullTrust

Finally, if you want to find out more about the access security policy tool, use the command

caspol -?

To display screen after screen of help text.

And that’s how you can set it up so you can run your .Net applications from your company network.

Dictionaries in C#: OrderedDictionary

There are times in life when you’d like to have your cake and eat it too. With a hashtable, this means there are times when you want to use the keys to look things up, or iterate in a foreach using DictionaryEntry objects. There are other times though when it would be easiest to treat the collection as if it were an array, using a traditional for(int i=0; … type syntax.

The OrderedDictionary is what lets you have the best of both worlds. Using it, you can perform specific actions at a numeric index in the collection, or you can use the Dictionary Entry style of looping over the collection. Like the other specialized dictionaries I’ve mentioned in the latter part of this week, you will need a using System.Collections.Specialized reference.

Let’s take a look at an example.

      OrderedDictionary myOD = new OrderedDictionary();

 

      myOD.Add(“01”, “First”);

      myOD.Add(“02”, “Second”);

      myOD.Add(“03”, “Third”);

      myOD.Add(“04”, “Fourth”);

      myOD.Add(“05”, “Fifth”);

 

      // Reference the values array style

      for (int i = 0; i < myOD.Count; i++)

      {

        // Create a strongly typed variable to hold the

        // generic object in myOD[], then do a cast

        string valueString = (string) myOD[i];

        Console.WriteLine(valueString);

      }

 

      // Reference the values Dictionary style

      foreach(DictionaryEntry myDE in myOD)

      {

        Console.WriteLine(myDE.Value);

      }

 

Above you can see I used two different methods to iterate over my collection. In the first example, I used a for loop and a numeric index to retrieve each object (in this case a string) stored in the collection. Using a cast I convert it from the generic object type into a more strongly typed variable.

While it’s true I simply could have used Console.WriteLine(myOD[i].ToString()), you will not always be dealing with string data in your value. This example demonstrates how to do a simple conversion.

In the second loop, you can see code similar to what has been shown all week, using a DictionaryEntry object to iterate over the collection.

The other advantage to an OrderedDictionary is speed. When going over a large collection, reading the OrderedDictionary using the first example, the numeric index, is always going to be faster than using the dictionary style method.

When you need both the power of a collection, and the simple access of a numeric index, the OrderedDictionary is the collection of choice.

Arcane Thoughts: Hug Your Developer Evangelist Today

Last night Doug Turnure came to give a presentation to the Birmingham Software Developers Association (BSDA). Doug is the Microsoft Developer’s Evangelist for Alabama / Georgia / Mississippi. Brian Hitney, Developer Evangelist for North and South Carolina happened to be in Atlanta where Doug lives, and came along.

Together, the pair did an excellent presentation on Vista. Doug started things out with the new gadget sidebar component, the various kinds of gadgets, and gave a demonstration on developing a gadget.

Brian then picked up the presentation, giving us a technical overview of the core changes to the OS. He covered a surprising amount of technical detail in the short amount of time he had, and made it understandable.

We had a packed room, but Doug and Brian stayed until they’d answered every question from the crowd. They did a great job, and I just wanted to take a moment to thank them publicly. The Developer Evangelists do a lot for us, they spend a lot of time away from home visiting user groups and giving us a lot of free training and advice.

Take time to get to know your developer evangelist, work with them to coordinate presentations at your user groups. And don’t forget to thank them when it’s all over. Thanks guys!

Dictionaries in C#: The SortedList

There are times when you need to sort your collection easily. Fortunately, there is a special dictionary called the SortedList to handle these needs. The SortedList is part of the System.Collections.Specialized library (don’t forget your using reference!).

There is one thing to understand that is a bit counter intuitive. The SortedList sorts off of the Key, and not the Value. While this may not seem natural, it can work to your advantage in times when users want to have peculiar sort orders. You can store the odd sort in the key, then display the values to the users.

In my simple example below, I’ve created a SortedList of the artists I might listen to during a day of programming. To make the sort case insensitive, I entered all the keys in lower case, then the value is the artist name in normal type.

      SortedList myMusic = new SortedList();

 

      myMusic.Add(“zztop”, “ZZTop”);

      myMusic.Add(“midnight synidicate”, “Midnight Syndicate”);

      myMusic.Add(“kate bush”, “Kate Bush”);

      myMusic.Add(“bond”, “Bond”);

      myMusic.Add(“clint black”, “Clint Black”);

      myMusic.Add(“queen latifah”, “Queen Latifah”);

 

      foreach (DictionaryEntry favoriteArtist in myMusic)

      {

        Console.WriteLine(favoriteArtist.Value);

      }

 

Produces this output in the command window:

Bond
Clint Black
Kate Bush
Midnight Syndicate
Queen Latifah
ZZTop

When you need to maintain a frequently changing list of values that need to be sorted, using the SortedList dictionary can be a real time saver.