Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creatre a Dword via vb script

Posted on 2008-10-01
5
Medium Priority
?
771 Views
Last Modified: 2008-10-08
Dear Experts,
I need to create a dword in the registry:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies

I need to create Create the following value (DWORD):

WriteProtect

and give it a value of 1.
and also if possible create another vb that will delete it the idea is to enable usb writing and disable it via both scripts

can anybody please help me

Thank you very much
0
Comment
Question by:TheoGeerman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:TheoGeerman
ID: 22616831
Experts,
I create the dword manualy and it works perfect, the question is? can it be done with a vb script and also can it bo done from my computer to a remote computer over the lan ( I have the administrator rigts)

Thank you
0
 
LVL 7

Expert Comment

by:Hubasan
ID: 22616973
Yes it can be done via VB script and yes it can be done remotely. All you have to do is change sComputer = "." variable to and instead of the "." put "REMOTECOMPUTERNAME".

Also "StorageDevicePolicies" key has to be created since the script assumes that computer you want to add the value to, already has it.
If that is not the case it can be modified to create that key as well, so let me know.

Here is the script:
Const HKEY_LOCAL_MACHINE = &H80000002
 
sComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    sComputer & "\root\default:StdRegProv")
 
 
' This part will create the value
sKeyPath = "SYSTEM\CurrentControlSet\Control\StorageDevicePolicies"
sValueName = "WriteProtect"
dwValue = 1
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName,dwValue
 
'This part will delete that value
 
oReg.DeleteValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName

Open in new window

0
 

Author Comment

by:TheoGeerman
ID: 22617146
Hubasan,

U r fantastic it worked perfect, only 2 questions.

1- can you please show me how to create also the "StorageDevicePolicies" key ?
2- There is an issue with the process, I pluged on a external HD to my pc and create the "StorageDevicePolicies" manualy then run the script and certainly it created the dword but when I tried to compy a file to the hd id didn't stop me, than I unpluged the HD and plug it back and it work then I unpluged back then it alow me to copy ? it seems that if you have a usb device already attached to the computer and you run the script it does not block the usb any suggestions?

Thank you very much. the idea is that the users can plug their usb devices and download data in to the pc but not upload any.
0
 
LVL 7

Expert Comment

by:Hubasan
ID: 22617332
No Problem man,

For creating your "StorageDevicePolicies" key you need the following code:

sKeyPath = "SYSTEM\CurrentControlSet\Control\StorageDevicePolicies"
oReg.CreateKey HKEY_LOCAL_MACHINE,sKeyPath

Just insert that to the script and that should be it.

As for the issue with the USB refresh, I'm pretty sure that is exactly how USB works. If the HD is already plugged in and you apply this policy it's not going to be affected until next time USB does the refresh, which can be a restart of the PC or unplugging the HD and plugging it back in.



0
 
LVL 7

Accepted Solution

by:
Hubasan earned 2000 total points
ID: 22617434
so your "CreateDWORD-Value" script would look like this:
Const HKEY_LOCAL_MACHINE = &H80000002
 
sComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    sComputer & "\root\default:StdRegProv")
 
 
' This part will create "StorageDevicePolicies" key
sKeyPath = "SYSTEM\CurrentControlSet\Control\StorageDevicePolicies"
oReg.CreateKey HKEY_LOCAL_MACHINE,sKeyPath
 
' Here you set the value name and it's valuedata and create it
sValueName = "WriteProtect"
dwValue = 1
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName,dwValue

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question