Disable USB for Massstorage

Dear All,

Could anyone help me with a script for doing the following:

I want to disable the USB ports so that students can’t plug in usb drives. I have tested and found that if I rename /System/Library/Extensions/IOUSBMassStorageClass.kext the usb ports do indeed stop working for mass storage devices.

I am after a script that has a disable and enable button. When disable is pressed it renames the file thus killing the ports and when enable is pressed it will reenable the ports by renaming the file back to its original name.

Thank you massively in advance for any help!!


(path to library folder from system domain as text) & "Extensions:"
tell application "Finder" to tell folder result
	if exists file "IOUSBMassStorageClass.kext" then
		tell current application to display dialog "Disable USB storage ?" buttons {"Cancel", "Disable"} default button 2
		if button returned of result is "Disable" then set name of file "IOUSBMassStorageClass.kext" to "OIUSBMassStorageClass.kext"
	else if exists file "OIUSBMassStorageClass.kext" then
		tell current application to display dialog "Enable USB storage ?" buttons {"Cancel", "Enable"} default button 2
		if button returned of result is "Enable" then set name of file "OIUSBMassStorageClass.kext" to "IOUSBMassStorageClass.kext"
	end if
end tell

is supposed to achieve your goal.

A password would be required.

Yvan KOENIG (VALLAURIS, France) jeudi 26 avril 2012 18:45:21

Yvan your fantastic.

For some reason, if i rename the file manually it works by from the script it does not. This is odd.

Could you modify the script so that it moves the file to an alternate folder so that it is physically out of the extensions folder?

Sorry to be a pain.

Thanks very much again for your time :slight_smile:

I’m puzzled.

I ran it here before posting it.

What is failing ?

The renaming or the disabling of the USB port ?


(path to library folder from system domain as text) & "Extensions:"
tell application "Finder" to tell folder result
	if not (exists folder "disabled" of it) then make new folder at it with properties {name:"disabled"}
	if exists file "IOUSBMassStorageClass.kext" then
		tell current application to display dialog "Disable USB storage ?" buttons {"Cancel", "Disable"} default button 2
		if button returned of result is "Disable" then move file "IOUSBMassStorageClass.kext" to folder "disabled" of it
	else if exists file "IOUSBMassStorageClass.kext" of folder "disabled" of it then
		tell current application to display dialog "Enable USB storage ?" buttons {"Cancel", "Enable"} default button 2
		if button returned of result is "Enable" then move file "IOUSBMassStorageClass.kext" of folder "disabled" of it to it
	end if
end tell

Yvan KOENIG (VALLAURIS, France) vendredi 27 avril 2012 11:49:41

Sorry, the USB disable was not working.

The script works perfectly. Im not sure why the rename of the file is not killing the USB.

If the file is moved it does work.

Thanks again :slight_smile:

I’ll bet whether it works or not after renaming depends on whether it’s loaded already or not. If you had restarted, renaming would have worked though obviously Yvan’s second script does work.