CaptureAnother of my little Windows 7 deployment annoyances has been the fact that windows media player is pinned to the new taskbar by default, and with windows 7, it’s not possible to programmatically add or remove pinned items from the taskbar.

After a while of script hunting for something that might get around this, I found out that there is an option that can be used in the unattended xml file will stop it from being automatically added!

 

 

In windows system image manager, add the following under phase 7 (OOBE):

   Windows shell setup >> Windows Features >> ShowWindowsMediaPlayer >> false

Using get and set methods with C#

October 2nd, 2009 by Rob Milner No Comments

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).

Windows 7 point and print restrictions

September 3rd, 2009 by Geoff Kendal No Comments

I’m currently looking into deploying Windows 7 in our environment, and was having a bit of an issue with printers… When our (non-admin) users log on, our logon script detects the client location and connects the appropriate printers, I don’t want any warnings to be shown or UAC prompts, but just want the drivers to be automatically downloaded and printers added.

On vista, you could disable any prompts, by disabling the “point and print restirctions” group policy object in the user configuration, or enable it and specify certain trusted servers, unfortunatly this didn’t seem to do the trick on Windows 7 RTM. After a bit of playing, I found out that on Windows 7, you need to apply the policy to both computer and user configuration!

From time to time our Citrix users end up with multiple sessions on our Citrix farm, especially when accessing the farm via Citrix access gateway and they loose connectivity. Most of these are fixed by setting sessions in the disconnected state to be automatically reset after 15 mins. (We allow this time  incase users are moving to a meeting room for example).

The big problem for us is that you can’t run multiple instances of Lotus Notes, so the disconnected session needs to be reset before the user can fire up Lotus Notes again, otherwise they will see an error like:

“You cannot use the Administration program while the Domino Server is running. Either shut down the Domino Server (buy keep the file server running) or choose the icon labeled ‘Lotus Notes’ instead.”

In order to try and make things a bit easier on the helpdesk, I created a script that will allow users to reset their own Citrix sessions. If you want to use it you’ll need to populate the first array with a list of all the servers in your farm, then create a shortcut:

cscript /nologo citrixreset.vbs

I’ve set mine to run minimized so that they don’t see random command windows popping up.

It should also be noted, that the script resets any disconnected sessions first, so that it can still carry on and kill the active one at the end! I know it’s not the slickest of scripts (Lots of splitting arrays and capturing command output), but I couldnt find any nice objects to do it properly with!

 citrixServers = array("CXS38", "CXS39", "CXS40", "CXS41")

Set objShell = CreateObject("WScript.Shell")

Sub resetSession(s)
    count = count + 1
    sessionID = trim(mid(s,48,5))
    citrixServer = trim(mid(s,1,6))
    wscript.echo "RESET SESSION " & sessionID & " /SERVER:" & citrixServer
    Set oExec = objShell.Exec("RESET SESSION " & sessionID & " /SERVER:" & citrixServer)
End Sub

userName = objShell.ExpandEnvironmentStrings("%UserName%")

For Each citrixServer In citrixServers

    wscript.echo "QUERY SESSION " & userName & " /SERVER:" & citrixServer
    Set oExec = objShell.Exec("QUERY SESSION " & userName & " /SERVER:" & citrixServer)

    Do While oExec.Status = 0
        WScript.Sleep 100
    Loop

    Do While oExec.StdOut.AtEndOfStream <> True
        sessionOutput = sessionOutput & vbCrLf & citrixServer & oExec.StdOut.ReadLine
    Loop

Next

count = 0
sessions = split(sessionOutput, vbCrLf)
wscript.echo

For Each session In sessions
    if InStr(session, "wdica") and InStr(session, "Disc") then wscript.echo session
Next

For Each session In sessions
    if InStr(session, "wdica") and InStr(session, "Active") then wscript.echo session
Next

For Each session In sessions
    if InStr(session, "wdica") and InStr(session, "Disc") then resetSession(session)
Next

For Each session In sessions
    if InStr(session, "wdica") and InStr(session, "Active") then resetSession(session)
Next

msgbox "Reset " & count & " Citrix session(s) for " & userName

CLSID error 80040154

June 18th, 2009 by Geoff Kendal No Comments

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!

Accessing servers with DNS aliases

May 21st, 2009 by Geoff Kendal No Comments

When trying to access a windows server via a DNS alias (e.g. using \\fileserver.company.co.uk that is an alias of \\SERVER12), you will probably get a ‘duplicate name exists on the network’ error. This is because the default behaviour of windows only permits using the proper name of the server (SERVER12 in this case, or a bound IP address). This applies to both CNAMEs and A records in DNS.

You might have aliases set up so that if you ever move a service onto a different server, all you have to do is update the alias.

To enable a windows server to respond to aliases like this, you’ll need to edit the registry. Navigate to:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters

Then add a new DWORD value, called DisableStrictNameChecking and the the value to 1.

Once this is done, you’ll need to restart the server service, after that you should be able to access the server using the alias name!

Windows 7 default explorer location

May 12th, 2009 by Geoff Kendal No Comments

In Windows 7, it’s been annoying me for a while how the windows explorer item on the taskbar always default to my libraries, as on most systems I use they are empty.

You can change the location by holding shift and right clicking on the taskbar item so you can select properties in the context menu (If you’ve already got explorer windows open, you’ll need to right click the taskbar item once, then hold shift and right click on the Windows Explorer entry.)

Once in the properties window, if you set the target to the following, it will open ‘My Computer’ by default…

%SystemRoot%\explorer.exe /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}

Lotus Notes And Vista Virtual Store

March 30th, 2009 by Rob Milner No Comments

Over the last few days, I have been having a lot of problems trying to write Lotus Notes .NET applications in Windows Vista. I had no problems writing the apps under XP, but since upgrading I kept getting error messages like “Unable to find user id file” when trying to initiate a Notes Session. The problem was with Windows Vista Virtual Store!

Installing Lotus Notes on Windows Vista, seems to be a normal installation. But when you launch Lotus Notes for the first time, it will start to write the notes.ini file and your id file (plus some other user related files…) to the following location: C:\Users\username\AppData\Local\VirtualStore\Program Files\lotus\. I never realised this before, until a colleague told me that Lotus Notes wrote files to this folder! With Lotus Notes writing to this folder, it made my .NET applications stop working!

The way to fix this, is to browse to: C:\Program Files, right click on “lotus”, go to the security tab and Edit the permissions for “Users” to Full Control. Apply the security settings. If you then copy the lotus folder from the VirtualStore to the normal Program Files folder, you will not lose any of your setting:

Copy: C:\Users\username\AppData\Local\VirtualStore\Program Files\lotus\ To: C:\Program Files

You should now be able to delete the lotus folder from the VirtualStore (or just rename the lotus folder to lotus.old if you are worried about losing the data – this would be useful to see Lotus Notes recreates the folder in the VirtualStore).

Lotus Notes should now not use the Virtual Store, and your .NET apps should run without any error.

Capturing & Deploying WLAN Profiles

February 27th, 2009 by Rob Milner 8 Comments

For a long time I have been trying to find a solution for rolling out a standard wireless profile so that anyone with a Laptop can visit any remote site with a WIFI connection and just connect without searching for a new network and without entering a new password everytime.

I stumbled upon the solution the other day whilst trying to solve another problem. If you take a look at this webpage that is on the Symantec Juice website (click here). If you use the file attached at the bottom of the post called WLAN.exe, it will allow you to export an existing WLAN profile saved on your laptop into an XML file. What you can do then do is create a script to import the XML file using the WLAN.exe utility to create the WLAN profile. What I have done is use Altiris to run this script on all client computers, as this process made it very simple to deploy. The script can be found at the end of this blog.

Firstly, you will need to have the WLAN profile already created on your computer. In my case I set-up a test WLAN environment with an SSID of “Test-Wireless” along with a WPA key of “@test-w1rele55!”. Once this was saved, I could use the utility to export the Test-Wireless profile to the XML file (you only need to do this once as long as the settings do not change!). But first, you need to do the following:

You need to find the GUID of your WIFI card, which you can find out by using the WLAN.exe tool and issuing the following command:

WLAN.exe ei
There are 1 interfaces in the system.
Interface 0:
GUID: 4ccd4bf2-4876-4993-a3de-3ed1cdf54eeb
Intel(R) PRO/Wireless 3945ABG Network Connection - Packet Scheduler Mini port
State: “connected”
Command “ei” completed successfully.

You then need to export the WLAN profile for your chosen WLAN network (in this case “Test-Wireless). In the below example you need to pass WLAN.exe your GUID of your WIFI card:

WLAN.exe gp 4CCD4BF2-4876-4993-A3DE-3ED1CDF54EEB Test-Wireless

This then produces the following ouput in the command prompt window:

< ?xml version="1.0"?>
<wlanprofile xmlns=”http://www.microsoft.com/networking/WLAN/profile/v1″>
<name>Test-Wireless</name>
<ssidconfig>
<ssid>
<hex>4A4E422D576972656C657373</hex>
<name>Test-Wireless</name>
</ssid>
</ssidconfig>
<connectiontype>ESS</connectiontype>
<msm>
<security>
<authencryption>
<authentication>WPA2PSK</authentication>
<encryption>TKIP</encryption>
<useonex>false</useonex>
</authencryption>
<sharedkey>
<keytype>networkKey</keytype>
<protected>false</protected>
<keymaterial>12754EB0C3B25D3F9268E1C49C1E09E5FAD4F9930A67CEB8E3BC944A68047D67</keymaterial>
</sharedkey>
</security>
</msm>
</wlanprofile>

If you copy and paste the text into Notepad, you will be able to save it as an XML file (call it testwireless.xml).

Now that you have captured your WLAN profile, you are ready to think about deploying the profile. To deploy, test it on your computer. Delete the Test-Wireless network in your WLAN network list, and then issue the following command:

WLAN.exe sp 4CCD4BF2-4876-4993-A3DE-3ED1CDF54EEB testwireless.xml

If you check your list of Wireless Networks, you should find that Test-Wireless should be there along with the WPA key already entered!

That is the manual way of doing it, if you need to automate this amongst a different number of computers you face a problem in that for each computer that requires the WLAN profile, the WIFI GUID will be different on each machine! This did cause me some problems, but after messing with PowerShell for a few hours I managed to create a very simple script that will find the GUID of the machine that you want to deploy the profile to and then pass the GUID to the command line. Here is the PowerShell script to automate this:

$path = "HKLM:\Software\Microsoft\WZCSVC\Parameters\Interfaces\"
$guid = Get-ChildItem -name $path
$guid = $guid.TrimStart(”{”)
$guid = $guid.TrimEnd(”}”)
.\WLAN.exe sp $guid testwireless.xml

And there you have an automated way of deploying a WLAN profile. This will prove to be a great time saver for our IT department & I hope someone will find this useful!

Managing shadow copies with VBScript

February 18th, 2009 by Geoff Kendal 1 Comment

Shadow copies are a brilliant time-saver… I can recover a deleted/overwritten/corruped file in a matter of seconds – or better still, the end user can do it! We currently have a schedule that takes a snapshot of our main fileserver at 7am and noon. While this is quite good, it quickly eats up diskspace, then all the snapshots get ditched and we have to start collecting them again. I wished there was some more complex scheduling and management for the shadows - I would find it far more useful to have more of the recent snapshots, and less of the older ones. Unfortunatly there’s no inbuilt functionality to do this, so I thought it was time to write a script…

I put together the following, it looks through all the snapshots on the system, and will delete those that match the following criteria:

- Older than 3 days and created after 7am
- Older than 7 days and not created on a Monday
- Older than 31 days

Scheduled to run daily, it should work a treat. The amount of snapshots should also stay constant, as once they are older then 31 days they will be removed.

  option explicit

  Dim objWMI, snapshots, snapshot, sDate, vDate, deleteSnapshot

  Set objWMI = GetObject("winmgmts://localhost/root/cimv2")
  Set snapshots = objWMI.ExecQuery("select * from Win32_ShadowCopy")
  set sDate = CreateObject("WbemScripting.SWbemDateTime")

  WScript.echo "Searching for all snapshots..."

  for each snapshot in snapshots

      sDate.Value = snapshot.InstallDate
      vDate = sDate.GetVarDate(True)
    
      WScript.echo vbCrLf & "Found snapshot... Created " & vDate
      'WScript.echo snapshot.VolumeName

      if (DateDiff("d", vDate, Date) > 7) then
          if (DatePart("w", vDate) <> 2) then
              WScript.echo "Older than 7 days & Not created on a Monday"
              deleteSnapshot = true
          end if
      end if

      if (DateDiff("d", vDate, Date) > 3) then
          if (hour(vDate) > 7) then
              WScript.Echo "Older than 3 days & Created after 7AM"
              deleteSnapshot = true
          end if
      end if

      if (DateDiff("d", vDate, Date) > 31) then
          WScript.Echo "Older than 31 days"
          deleteSnapshot = true
      end if

      if (deleteSnapshot) then
          WScript.echo "*** Deleting snapshot ***"
          snapshot.Delete_()
          deleteSnapshot = false
      else
          WScript.echo "*** Keeping snapshot ***"
      end if

  next