Archive for June, 2007

Run this program as program as an administrator

Vista will try and run most programs without admin rights even if you are signed on as an admin. Some programs such as Visual Studio need admin rights so it is worth setting them to always run as administrator.

Confusingly, looking at a shortcut’s properties, the compatibility tab has an option to “Run this program as an administrator”. This option is greyed out:

Shortcut Compatibility Tab

To set the shortcut to run as administrator go to the shortcut tab > click on Advanced… > check Run as administrator:

Shortcut Advanced Properties

 

No Comments

Macro to Set Outlook’s Master Category List

I upgrade, move, or reinstall the OS on my PCs fairly often so setting a master category list with a macro is useful:

Public Sub ResetCategories()

    DeleteAllCategories
   
    CreateCategory “! goals”, 1, 0
    CreateCategory “! objectives”, 2, 0
    CreateCategory “! projects”, 3, 0
    CreateCategory “@ anywhere”, 4, 0
    CreateCategory “@ computer”, 5, 0
    CreateCategory “@ email”, 6, 0
    CreateCategory “@ errands”, 7, 0
    CreateCategory “@ home”, 8, 0
    CreateCategory “@ office”, 9, 0
    CreateCategory “@ phone”, 10, 0
    CreateCategory “1:1″, 11, 0
    CreateCategory “2 inbox”, 23, 1
    CreateCategory “2 someday maybe”, 24, 0
    CreateCategory “2 waiting for”, 19, 0
    CreateCategory “meeting”, 22, 0
    CreateCategory “holiday”, 17, 0
    CreateCategory “social”, 18, 0
    CreateCategory “STS”, 20, 0
    CreateCategory “travelling”, 21, 0
    CreateCategory “cards”, 25, 0
   
End Sub

Private Sub DeleteAllCategories()
    Dim objNameSpace As NameSpace
    Dim objCategory As Category
   
    Set objNameSpace = Application.GetNamespace(“MAPI”)
   
    If objNameSpace.Categories.Count > 0 Then
       
        For Each objCategory In objNameSpace.Categories
            objNameSpace.Categories.Remove (objCategory.CategoryID)
        Next
       
    End If
       
    Set objCategory = Nothing
    Set objNameSpace = Nothing
   
End Sub

Private Sub CreateCategory(strCategoryName As String, intColor As Integer, intKey As Integer)
    Dim objNameSpace As NameSpace
    Dim objCategory As Category
   
    Set objNameSpace = Application.GetNamespace(“MAPI”)
   
    If intColor > 25 Then intColor = -1
   
    objNameSpace.Categories.Add strCategoryName, intColor, intKey
       
       
    Set objCategory = Nothing
    Set objNameSpace = Nothing
   
End Sub

No Comments

Outlook Item to Task Macro

The following macros convert outlook items to tasks with different categories. Based on this blog post which in turn is based on this one.

  • The item body is copied to the task body and the item itself is added as an attachment.
  • If multiple items are selected, multiple tasks will be created.
  • Created tasks are left open for editing.
  • I am in two minds about deleting the item after the task is created and have decided against it at the moment.
  • It appears that OL 2007 does not allow shortcut keys to be assigned to macros .

Public Sub CreateInboxTaskFromItem()
    CreateCatagorisedTaskFromItem (“2 inbox”)
End Sub

Public Sub CreateWaitingTaskFromItem()
    CreateCatagorisedTaskFromItem (“2 waiting for”)
End Sub

Public Sub CreateSomedayTaskFromItem()
    CreateCatagorisedTaskFromItem (“2 someday maybe”)
End Sub

Public Sub CreateTaskFromItem()
    CreateCatagorisedTaskFromItem (“”)
End Sub

Private Sub CreateCatagorisedTaskFromItem(catagory As String)

  Dim olTask As Outlook.TaskItem
  Dim olItem As Object
  Dim olExp As Outlook.Explorer
  Dim fldCurrent As Outlook.MAPIFolder
  Dim olApp As Outlook.Application
 
  Set olApp = Outlook.CreateObject(“Outlook.Application”)
  Set olExp = olApp.ActiveExplorer
  Set fldCurrent = olExp.CurrentFolder
 
  Dim cntSelection As Integer
  cntSelection = olExp.Selection.Count
 
  For i = 1 To cntSelection
    Set olTask = olApp.CreateItem(olTaskItem)
    Set olItem = olExp.Selection.Item(i)
    olTask.Attachments.Add olItem
    olTask.Body = olTask.Body + olItem.Body
    If catagory = “2 waiting for” Then
        olTask.Subject = olItem.SenderName & “: ” & olItem.Subject
    Else
        olTask.Subject = olItem.Subject
    End If
    olTask.Categories = catagory
    ‘olItem.Delete
    olTask.Display
    olTask.Save
  Next
 
End Sub

20 Comments

Vista Install Blank Screen

Trying to install Vista on a machine and getting a blank screen after one of the reboots?

This could be caused by an incompatible display driver. I solved this problem by:

  1. Reboot the machine and hit F8 to get the Windows boot menu.
  2. Select Safe Mode with Networking.
  3. Vista will boot then will complain that it cannot continue with the installation in Safe Mode. Do not hit OK!
  4. Press Shift + F10 to get a command window.
  5. Run Device Manager by entering ‘devmgmt.msc’.
  6. Right click the video card and select Update Driver.
  7. Choose ‘Select a Driver’.
  8. Select ‘Choose from a list’.
  9. Click on the generic VGA driver and hit Next to install it.
  10. Close the wizard, close the Device Manager, close the command prompt.
  11. Click OK on the installation message and Vista will reboot.
  12. Finish the install, create a restore point, then install the correct video driver.

1 Comment

How to Use InternalsVisibleTo

VS2005 defaults new classes to internal rather than public (although it appears that Orcas defaults to public). This is good as it reduces the public interface of your assembly and it encourages you to actually think about whether a class needs to be public.

You can allow other assemblies access to your internal types and members though, by using the InternalsVisibleTo attribute. This is especially useful for allowing your test assembly to access your internal classes.

This attribute can only be applied to strongly named assemblies.

[assembly:InternalsVisibleTo("TestAssembly, PublicKey=TestAssembly’s public key")]

The attribute requires the assembly name and the public key. To retrieve the public key use sn.exe. Open a visual studio command prompt and enter:

sn.exe -Tp AssemblyPath

Alternatively if you use an alternate file explorer you could set up a macro.

1 Comment

This page has an unspecified potential security risk.

With Vista (and probably XP and IE7) right clicking on a zip file on a network share brings up an Internet Explorer dialogue:

This page has an unspecified potential security risk. Would you like to continue?

It appears that the OS thinks that your network share is in the Internet Zone rather than the Intranet Zone. This is easily fixed by:

  1. Control Panel > Internet Options > Security.
  2. Select Local intranet > click Sites > Advanced.
  3. Type your server name into the textbox (e.g. If the server is called FileServer just type FileServer) and click Add.
  4. Click Close > OK > OK.

24 Comments

How to Give an Assembly a Strong Name

To Strongly name an assembly you need to associate it with a public and private key. This can be either done by the developer when they compile the assembly (signing) or by at a later stage for instance by the QA department (delayed signing).

Public and private keys can be associated with code signing certificates, generated using sn.exe, or they can be generated from within Visual Studio.

Open the project properties for the assembly you want to sign and check ‘sign the assembly’ on the signing tab. To create a key file, select New from the drop down and follow the directions or Browse for an existing key file. If you create a key file it is worth moving it from the bin directory as you should be using it across multiple projects.

Once compiled you will have a signed assembly with a strong name.

No Comments

User Commands in Xplorer2

When I am doing anything more complicated than simple file browsing I use Xplorer2 rather than the windows file browser.

One of the features of Xplorer2 is the ability to run commands on files you have selected.

These are the commands I currently have set up:

  • VS Cmd
    $”C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sdkvars.bat”
    Sets the console to act like a Visual Studio command prompt
  • Get Public Key
    $sn -Tp “$F”
    Gets an assemblies public key (requires vs Cmd to be run first).
  • DiffMerge Files
    >”C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe” “$F” “$G”
    Uses Source Gear’s DiffMerge to diff files from each pane.
  • DiffMerge Folders
    >”C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe” “$P” “$I”
    Uses Source Gear’s DiffMerge to diff folders from each pane (although Xplorer2 does this well enough itself).
Tags:

No Comments