Wednesday, 30 January 2013

Windows 7: Show specific control panel item using GPO


The full path of this node in the Group Policy Management Console is:
  1. User Configuration\Administrative Templates\Control Panel
  2. Click on->Show only specified Control Panel items
    • Click on Add and type the control panel item name. For example: If you want to show mouse control it is named in the control panel as Mouse so just type Mouse in the Add box.


Monday, 10 December 2012

Cannot completly remove printer

  1. A stuck print job in the queue will prevent the printer from being removed. Try running Delete Print Jobs to remove the stuck print job.
  2.  Disconnect the printer.
  3.  Uninstall the printer.
  4.  Restart your computer. Make sure the printer is removed. Manual Printer Driver Removal


Thursday, 15 November 2012

Delete cached copied of user profile Windows 7 using GPO

Method 1:
Add your users to the 'Domain Guests' global group - those users won't leave any profile on your computers.. it works!


Method 2: 
You can configure a Group Policy Object (GPO) to perform the preceding behavior by performing the following steps:
  1. Edit the GPO that you want to modify.
  2. Locate the following section: Computer Configuration \ Administrative Templates \ System \ User Profiles.
  3. Double-click Delete cached copies of roaming profiles (the Group Policy setting).
  4. Click Enabled.
Method 3: 
You can run this script every night to clean up. The check at the start is to exclude certain machines (the ones in lecture theatres)

The next section uses a WMI call to get a list of profiles other than the "special" ones (localsystem etc) and delete them (this is what you see when you go to the control panel and delete profiles)

This will sometimes leave bits behind so the next step is to get a list of folders which shouldn't be deleted by reading the existing profiles from the registry - this list is built in a dictionary. To this is then added things like "public" and "default".

The script then scans c:\users and checks each folder it finds against the dictionary. If the folder isn't listed then it gets deleted (because it doesn't need to be there)

Code:
const HKEY_LOCAL_MACHINE = &H80000002

set oDic=createobject("scripting.dictionary")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
set oFSO=createobject("scripting.filesystemobject")
set oShell=createobject("wscript.shell")

on error resume next

'are we on an AV machine? if so, quit - leave profiles alone in theatres
if ofso.fileexists("c:\windows\av") then wscript.quit

Set colItems = oWMIService.ExecQuery("Select * from Win32_UserProfile where special=false and loaded=false",,48)
For Each oItem in colItems
  sSid=oItem.SID
  Set oUserProfile = GetObject("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2:Win32_UserProfile.SID='" & sSID &"'")
  oUserProfile.Delete_
Next

'now clean up directories not attached to profiles
'and profiles not completely deleted by first step
'build a list of the directories used by profiles

sPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
oReg.EnumKey HKEY_LOCAL_MACHINE, sPath, arrSubKeys
For Each subkey In arrSubKeys
  lRc=oReg.GetStringValue(HKEY_LOCAL_MACHINE, sPath & "\" & subkey ,"ProfileImagePath",sDir)
  sDir=lcase(sDir)
  oDic.add sDir, subkey
Next

'now add the "fixed" profiles

lRc=oReg.GetStringValue(HKEY_LOCAL_MACHINE, sPath ,"ProfilesDirectory",sRoot)
sRoot=lcase(oShell.expandenvironmentstrings(sRoot))
sRoot=sRoot & "\"

oDic.add sRoot & "public","public"
oDic.add sRoot & "all users", "all users"
oDic.add sRoot & "default","default"
oDic.add sRoot & "default user", "default user"


set oFolder=ofso.getfolder("c:\users")
for each oSubFolder in oFolder.subfolders
  sFolder=sRoot & lcase(oSubFolder.name)
  if not(oDic.exists(sFolder)) then
    'orphaned folder so delete it
    ofso.deletefolder sFolder, true
  end if
next

Thursday, 25 October 2012

Connect to registry settings remotely

Launching regedit, connecting to the remote system (File | Connect Network Registry), and inspecting that system's [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ Windows\CurrentVersion\Uninstall] may not be as nice as the Control Panel applet, but it may work in a pinch...

Monday, 22 October 2012

Windows 7: Task scheduler - Run a batch file in the background on every 5 minutes


  1. Create a batch file called copy.bat with following command: xcopy C:\inetpub\wwwroot\GYMREG \\its3\users\staff\mah\Website\GYMREG /E /Y  
  2. Create a new task in task scheduler and run it on every 5 minutes.
  3. In order to run batch file on every 5 minutes you have to run the scheduled task with another user not using the user normally will be logged on. For example if you login on your pc using mah account then you should run the scheduled task using its2 or any other account.
  4. The box for "Do not store password" also says "The task will only have access to local resources." As my task didn't need network access, I thought leaving this box checked was OK.  I un-checked it, and now the task runs with no users logged in.  The XML changed from


Error messege: the selected task "{0}" no longer exists. to see the current task, click refresh


I spent a few minutes and tracked down the problem and a solution. The issue is a result of task files which exist in the Tasks folders which have no entry in (presumably) in the registry. Here's how I worked through the issue - will take some time, but it has cleared up the issue completely for me:

  1. Open Task Scheduler and click OK when prompted with the error. It may seem like you are receiving the same error over and over, but this is really due to the number of tasks which are broken. Make a note of the number of times you are prompted with the the selected task "{0}" error. This is the number of task files that are out of sync with the registry.
  2. Start with the first folder under Windows tasks (Task Scheduler(Local)\Task Scheduler Library\Microsoft\Windows) and select each folder in turn until you receive the the selected task"{0}" error. This folder contains files that are not in sync with the task scheduler.
  3. Open Windows Explorer and navigate to the tasks file folder (%SystemFolder%\Tasks\Microsoft\Windows) and find the folder which corresponds to the folder in which you received the error.
  4. For some tasks you will be able to determine which files need to be deleted by comparing the list in the Task Scheduler with the list of files in Explorer. Some tasks will only have a single file in explorer, or, in one case I had 2 and the first was missing. Once Task Scheduler encounters this error it will no longer display tasks so it makes the job of getting the two in sync a little more difficult. Once you have determined which files exist in the File Folder but do not exist in the Task Scheduler folder, delete those files.
  5. IMPORTANT - Close and Re-open Task Scheduler. Once the error is encountered, Task Scheduler no longer displays the tasks so you need to close it and restart in order to continue your synchronization effort.
  6. Continue to select folders in Task Scheduler under Windows tasks until you encounter the error again and repeat the process of determining which file exists on the file system, but not in Task Scheduler.
I had 6 files that were out of sync with what was displayed in Task Scheduler. Once I deleted all of the offending files, Task Scheduler fired up without issue.

Thursday, 11 October 2012

Solution: IE (internet explorer) processes not closing down

Sometimes when you close a tab or IE itself it doesnt always shut down the corresponding process:
1. Open regedit
2. navigate to HKCU\Software\Microsoft\Internet Explorer\Main
3. Either create a dword entry called TabShutdownDelay or if its already there edit it (wasnt there on mine)
4. Enter the value (in seconds) you want for how long it takes to shut down the process (0 will force the process to close immediately)

pls do same to 2 more registry keys as below:

HKLM\Software\Microsoft\Internet Explorer\Main

HKLM\Software\Wow6432Node\Microsoft\Internet Explorer\Main