Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable/Enable usbstor in registry using vbscript 1

Status
Not open for further replies.

psbrown

MIS
Oct 16, 2001
40
Hi.

We are trying to disable usb memory sticks on our pc's dependant on the user.
One way to do it is via Active directory and another is to change the value of
hkey_local_machine\system\currentcontrolset\services\usbstor\start from 3 (enabled) to 4 (Disabled)

I am still a learner in the scripting game and have tried to modify a script I have used in the past to achive this as listed below.

Any advice on why this does not work would be greatly appreciated.

Thanks

Paul

On Error Resume Next


'********set up varaibles for computer*******
HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

'************disable USBStor by setting to 4 hexadeciaml*************'

objReg.createkey HKEY_LOCAL_MACHINE, strKeyPath, ValueName

'***set variable strkeypath***
strKeyPath = "system\CurrentControlSet\Services\USBSTOR"

'***set variable valuename***
ValueName = "Start"

'***set variable strvalue***
strValue = hex(4)

'***update registry with settings***
objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, strValue
 
I'd call the CreateKey method AFTER populating the relevant var, ie strKeyPath and ValueName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PH, this does not seem to have any effect, on my machine the value is set to 3 and when I run the script it is still 3 even with a refresh.
Paul
 
Do a keyword search in this forum for stop service

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks again PVH, but there do not seem to be any subjects under this search that help me as I do not believe usbstor is a service.
I am trying to script the actions recocomended by microsoft in article KB832732.

Paul
 
Hello psbrown,

You script is very problematic.

[1] As PHV already pointed out a valid point. I won't repeat. Your strKeypath and Valuename are all empty when you apply createkey method.
There are other major problems.
[2] You define HKCU constant, but you apply HKLM which is no where defined as constant (&H80000002). You should define it up there.
[3] Createkey method requires two(2) parameters only, not three. Valuename should not be there at all.
[4] The star is a dword (REG_DWORD) rather than a string value (REG_SZ). Besides, hex(4) has no effect.
[5] Use setdwordvalue method to set dword value; se setstringvlaue to set string value.
[6] You do _not_ set HKCU branch remotely. It makes no sense.
[7] Do not put on error resume next without a reason.

This is the correction based on your script. (Make it prettier later if you like.)
Code:
'On Error Resume Next    'do not uncomment for no reason

'********set up varaibles for computer*******
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
  
'************disable USBStor by setting to 4 hexadeciaml*************' 

'***set variable strkeypath***
strKeyPath = "system\CurrentControlSet\Services\USBSTOR"

'***set variable valuename***
ValueName = "Start"

'***set variable strvalue***
dwValue = 4

iret=objReg.createkey(HKEY_LOCAL_MACHINE, strKeyPath)
    'wscript.echo iret    'should be 0 for success

'***update registry with settings***
iret=objReg.SetDwordValue(HKEY_LOCAL_MACHINE, strKeyPath, ValueName, dwValue)

set objReg=nothing
(Let error stop the script for debugging.)

regards - tsuji
 
tsuji

Thank you very much for helping me this worked perfectly.
I have little experience with vbscript and appreciate your help.

Are there any books you can reccomend to help me learn more?.

Thanks

Paul
 
psbrown,

Thanks for the vote. I am very reluctant to coin opinions on how to learn more. These are threads in the past I care to put forward some:

I have no problem to recommend [1] script56.chm documentation; [2] G Born "MS Scripting Host Developer's Guide" and [3] MS Scripting Team's "Windows 2000 Scripting Guide". All tend to be elementary---solid base is the most important thing to acquire. Else, the only most important sources are the msdn documentations on separate technologies.

There are many excellent specialized books, author's name like Lavy & Meggitt, Lissoir, Borge, Eck, Policht, ... even not covering many topics. But books come and go like fashion.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top