Remove Network Printers from Users Before they Log On

Dos Batch FileI had a little trouble with an HP Printer driver that was causing the Vista PCs to hang at logon.

Without going into the specifics of the problem (which comes down to poor HP drivers), I needed a way to ensure that the driver wouldn’t be active the next time that a user logged onto a computer.

A bit of quick thinking, and I quickly knocked up this command, that will enumerate all users in a folder and make the appropriate change while they are offline. Hurrah!

<code>for /D %D in (\\domain.local\users\*.*) DO (
  reg load HKU\UserLoad %D\profile.V2\ntuser.dat
  reg delete "HKU\UserLoad\Printers\Connections\,,domainsrv1,Suite Mono Printer" /f
  reg delete "HKU\UserLoad\Printers\Connections\,,domainsrv1,Suite Colour Printer" /f
  reg unload HKU\UserLoad
)</code>

This assumes that all of your users live in \\domain.local\users and that you are cleaning up vista profiles. Needless to say, you’d probably want to adjust this if you need to do something similar.

Deleting files older than a specific date or age

I needed to delete a chunk of cookies today – but I didn’t want to delete them all.

Thankfully there is a handy command that is within Windows versions after XP such as Server 2003 and Vista that will enable to clean up without too many problems.

The forfiles command will allow you to set a specific date for a file so that you don’t delete recent cookies:

<code>forfiles /S /p "C:\Users\John\cookies" /D -150 /c "cmd /c del @path"</code>

If you wanted to be super cool and delete multiple user cookie folders you could do something like this:

<code>for /D %D in (C:\Users\*) DO forfiles /S /p "%D\cookies" /D -150 /c "cmd /c del @path"</code>

This will enumerate all of the user folders in the C:\Users folder and then clean up the cookies folders inside.

If you wanted to – you can change the amount of days from 150 days to any other amount you like by changing /D -150 to any other number of days (or even use a specific date).

%Logonserver% session variable doesn’t work on network Vista logon

Some grief today as I found that Vista wasn’t behaving with user profiles. Whenever a user attempted to logon, he or she would be greeted with the following popup:

Your user profile was not loaded correctly!

You have been logged on with a temporary profile. Changes you make to this profile will be lost when you log off. Please see the event log for details or contact your administrator.

How annoying is that message when you are the administrator?

Anyway, the event log was equally unhelpful:

Windows cannot locate the server copy of the roaming profile and is attempting to log you on with you local profile. Changes to the profile will not be copied to the server when you log off. This error may be caused by network problems or insufficient security rights.

DETAIL – Access is denied.

What was weird was that some users were creating the username.v2 profiles.

After a bit of trial and error, I realised that the users that had a dynamic roaming profile path (such as %logonserver%\users\%username%) would not locate or create a profile in Windows Vista.

As soon as I replace %logonserver% with the name of a domain controller (\\server1\users\%username%), everything behaved itself.

This is pretty annoying, as I’d have to set up DFS to get around this. In the meantime, I’ve just changed the paths.

There is no evidence to suggest that this is by design, especially considering that using the SET command in Vista shows that the logonserver variable is indeed set.

ARGH!