Archive for the ‘VBScript’ Category

Disable ‘Automatically detect settings’ in Internet Explorer

Tuesday, August 30th, 2011

This script allows you to turn off (or on) the ‘Automatically Detect Settings’ check box in Internet Explorer.

I have not been able to find a way which guarantees that this will not be checked. You can set a Group Policy into Internet Explorer Preference Mode, but if a user later changes it, then it will not change back. If you Disable Changing IE Proxy Settings, then the Preference Mode Setting seems not to work.

I have set this script to run at logon, as part of our general login script. It only modifies that one setting, no others. It reads the entire of the binary value, modifies the one binary value that needs changing and then writes back the entire value.

Option Explicit
On Error Resume Next
'Create a constant for the HKEY_CURRENT_USER object
Const HKCU = &H80000001
'Define variables
Dim strComputer
Dim strRegistryKey
Dim objRegistry
Dim strRegistryValue
DIm binValue
strComputer = "."
strRegistryKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
strRegistryValue = "DefaultConnectionSettings"
'Connect to the Registry
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
'Retrieve the current settings.
objRegistry.GetBinaryValue HKCU, strRegistryKey, strRegistryValue, binValue
'Change the 'Automatically detect settings' box to unticked
binValue(8) = 05
'binValue(8) = 13 - Enable this line to check the box instead of uncheck
'Save the changes
objRegistry.SetBinaryValue HKCU, strRegistryKey, strRegistryValue, binValue

Redirected My Documents folders showing as ‘Documents’ rather than the users name

Monday, December 20th, 2010

Had a complaint from a member of staff recently that all students work folders showed up as My Documents when he was browsing through their work.

Many of you may have been directed to this Microsoft KB as a ‘solution’. http://support.microsoft.com/kb/947222

Not much of a solution if you ask me. Redirection to a subfolder would work, but do you really want to change something that significant on your network? Enable exclusive access would be fine if you didn’t need to give other people access to the documents folder. In a student-teacher situation, teachers need to be able to see the students work, so this doesn’t work for us. Option 3 – deny permission to the desktop.ini. We have 1400 students. That’s a lot of changes – yes I could use xcacls or subinacl to automate it, but what a headache.

The best ‘solution’ that we have come up with, is to simply delete the desktop.ini file at logoff. We created a VB Script, which looks for a desktop.ini file in the user’s My Documents folder, and if it exists then delete it. Attach this into a GPO that affects the user as a logoff script.

The code we used is:

On Error Resume Next
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
DocsPath = WSHShell.SpecialFolders("MyDocuments")
If FSO.FileExists (DocsPath & "\desktop.ini") Then
  FSO.DeleteFile (DocsPath & "\desktop.ini")
End If

Next time the user logs on and then off again, the desktop.ini file will be deleted, and the folder will show as the username of the user.

Shame there isn’t a GPO option which allows you to turn off this feature. On a home machine it is great, but in a corporate environment you need to be able to turn off the fancy features and see exactly what you have got.

2 people found this post useful.

VBScript: If..Or..Then

Thursday, February 4th, 2010

Just been trying to do something that I thought would be really simple. Just been modifying a script which checks a specified network drive’s folders, to make sure that every folder has a corresponding user in Active Directory, and then, if it does set the owner and permissions on that folder accordingly. (We have changed from using Home Folders in AD to using Folder Redirection, which only works when the user is the owner of their folder)

So, during testing I noticed that two folders kept coming up that I did not want to modify the permissions on; System Volume Information and $RECYCLE.BIN. Instant thought: If folder is not called ‘System Volume Information’ Or ‘$RECYCLE.BIN’ Then Run Code.

Translated into VBScript it looked something like this:


For Each objSubfolder in colSubfolders
If objSubfolder.Name <> "System Volume Information" And objSubfolder.Name <> "$RECYCLE.BIN" Then
Code to check goes here
End If

Could not get this to work at all. Even Microsoft Technet says that it should. Tried converting to lowercase before comparing too. As a test I tried it with just a single condition, and both conditions individually work.

In the end I changed the code and used a Select Case. Not quite as short on the code, but the same end result and possibly more elegant.


For Each objSubfolder in colSubfolders
Select Case LCase(objSubfolder.Name)
Case "system volume information", "$recycle.bin"
Case Else
Code to check goes here
End Select

Just another really annoying 10 minutes trying to work out something that should just work!

VBScript – Create a shortcut with parameters

Thursday, September 17th, 2009

Hi,

This really is something quite simple, but it has taken me ages to find the answer. And it seems to be something that many people are looking for the answer to and not finding easily.

I wanted to create a shortcut using a VBScript, part of an installation script. The program had parameters passed after it with spaces inbetween.

I could create the shortcut, no problem using the code below, but whenever I checked the shortcut, it didn’t work. Windows was putting quotes around the target, meaning the parameters were being passed as part of the path.

Set oLink = WSHShell.CreateShortcut(strDirectory & "\Shortcut Text.lnk")
oLink.TargetPath = ServerPath & "\ApplicationName.exe /Parameter"
oLink.WorkingDirectory = ServerPath
oLink.WindowStyle = 4
oLink.Save

The resulting Target:

"\\server\share\ApplicationName.exe /Parameter"

After a bit of searching, I found the line I was missing:

oLink.Arguments = "/Parameter"

The resulting code becomes:

Set oLink = WSHShell.CreateShortcut(strDirectory & "\Shortcut Text.lnk")
oLink.TargetPath = ServerPath & "\ApplicationName.exe"
oLink.Arguments = "/Parameter"
oLink.WorkingDirectory = ServerPath
oLink.WindowStyle = 4
oLink.Save 

Which then gives a final Target Path of:

"\\server\share\ApplicationName.exe" /Parameter

 Works like a charm.

4 people found this post useful.