Archive for the ‘Programming’ Category

I have been looking at getting a script together for a while to mass change some shortcuts we have on our file server to point to a different location. After some research, and some playing around I found a really easy way to do this in Powershell:


# Call wscript com object
$shell = new-object -com wscript.shell

# Recurse through directories for .lnk files
dir "I:\" -filter *.lnk -recurse | foreach {
$lnk = $shell.createShortcut($_.fullname)
$oldPath= $lnk.targetPath

# If match text, perform operation
if($oldpath -match "\\serverold\share1")
{
write-host "Match: " + $_.fullname
remove-item $_.fullname
$lnknew = $shell.createShortcut($_.fullname)
$lnknew.targetPath = "`"\\newserver\share1`""
$lnknew.IconLocation = "%SystemRoot%\system32\SHELL32.dll,4"
$lnknew.Save()
}
}
Write-Host "End..."

I’ve always wondered when looking at C# what get and set methods are used for.  In basic terms I found that the get and set method was mainly for reading (get) or writing (set) a property.  After scratching my head for some time, I tried to give it a go as I have problems setting a string to a particular value within one of my C# projects.

I setup another class within my project called “tgtNotes”, which would contain my get and set:

class tgtNotesJK
{
   private string LocNotes = null;
   public string NotesLoc
{
   get
   {
     return LocNotes;
   }
   set
   {
     LocNotes = value;
   }
}

I then thought, “surely it’s not that easy”!  I then went back to the code on the form, and defined the class within the code for button1:

tgtNotesJK notestgt = new tgtNotesJK();

Getting and setting is really easy.  To set a value:

notesgt.NotesLoc = "Some text";

And to get the value for example:

Console.WriteLine(notesgt.NotesLoc);

Another great benefit of this is that you will be able to access the methods from anywhere within the C# project.  So because I ’setted’ a value within button1, will mean for example that I can still access the value within other parts (for example button2).

I’ve got a c# app that I’ve developed, and am now trying to compile on my new system I’ve had a few problems, biggest one being at the line: ‘NotesSession session = new NotesSession();’ ….I’m sure it compiled ok on my last system..hm!

I get the error….CLSID {blahblah} failed with error 80040154.

Turns out that Visual studio was compiling for “Any CPU”, this needs changing to x86, as the notes COM objects don’t do the x64 shizzle. All makes sense now, as new laptop is 64-bit!!

App now works and I’m a bit happier!