Avatar of expertblr
expertblr
 asked on

Script for making changes in the registry

Hi expert,

I have got a script(VBS) which disables the cd rom, floppy & usb store in the registry, which i have applied to O U in our domain controller(windows 2003) , i.e in windows settings -->startup. If any user computer is in that O U and after applying the script if the user restarts the machine the script will run at the startup and disables the cd rom, floppy & usb store. This script will disables the computers which are in that particular O U in which we have applied the script.

Now my problem is, i need a similar script which enables the cd rom, floppy and usb store which i will apply to another  O U so that if any user requests for enabling his computer CD Rom , floppy and USB store by moving his computer to this O U. The other option to enable these is by manually editing the registry.

Here i am attaching the script ( its a VB script) which is zipped (password is india@123). Pls let me know can we change the values in the script ie edit the same script for enabling. Pls let me know its very urgent.

'//////////////////////////////////////////////////////////////////
'// This script will Disable CD FLOPPY USB system driver service
'//////////////////////////////////////////////////////////////////
Dim oWsh,g_fVerbose
g_fVerbose = False
Set oWsh = WScript.CreateObject("WScript.Shell")

If WScript.Arguments.Named.Exists("V") Then g_fVerbose = True

      '// Disable support for USB Storage Devices
      ChangeMode "USBSTOR","DISABLE"
         '//oWsh.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start", "00000004", "REG_DWORD"
      
      '// Disable support for Floppy disk
      ChangeMode "Flpydisk","DISABLE"
      '//oWsh.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Flpydisk\Start", "00000004", "REG_DWORD"

      '// Disable support for CDROM
      ChangeMode "Cdrom","DISABLE"
      '//oWsh.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom\Start", "00000004", "REG_DWORD"



Sub ChangeMode (strDeviceName,blnMode)

Dim strRegKey : strRegKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"&strDeviceName&"\Start"
On Error Resume Next
Dim strTmp : strTmp = oWsh.RegRead (strRegKey)

      If strTmp <> Empty Then
      '// Key Already exists so change its value
            If blnMode = "DISABLE" Then
            '// Disable the Service
                  oWsh.RegWrite strRegKey , "00000004", "REG_DWORD"
                  oWsh.Run "cmd /c net stop """ & strDeviceName & """",0,False                  
            Else
            '// Enable the Service
                  oWsh.RegWrite strRegKey , "00000001", "REG_DWORD"
                  oWsh.Run "cmd /c net start """ & strDeviceName & """",0,False
            End If
      end if  
      
      '// Manage rights of user to read inf file
      '// CACLS.EXE stops for user input... which currently not able to automate
      
'      If blnMode = "ENABLE" Then
'            oWsh.Run "cmd /c cacls %systemroot%\inf\" & strDeviceName & ".inf /G BUILTIN\Users:R ""BUILTIN\Power Users:R"" BUILTIN\Administrators:F ""NT AUTHORITY\SYSTEM"":F",0,False      
'      Else
'            oWsh.Run "cmd /c cacls %systemroot%\inf\" & strDeviceName & ".inf /G BUILTIN\Administrators:F ""NT AUTHORITY\SYSTEM"":F",0,False
'      End If

End Sub

Windows Server 2003

Avatar of undefined
Last Comment
trenes

8/22/2022 - Mon
trenes

Hi expertblr,

if you extend the grouppolicy
http://support.microsoft.com/default.aspx?scid=kb;en-us;555324

Then you can ditch the script and use normal group policy to enable this.


Regards,

Trenes
expertblr

ASKER
Hi,

I know about .adm files, but i need this script which enables the same. Pls let me know its very urgent
trenes

You only have to change these lines "I've done it for you"
'//////////////////////////////////////////////////////////////////
'// This script will Disable CD FLOPPY USB system driver service
'//////////////////////////////////////////////////////////////////
Dim oWsh,g_fVerbose
g_fVerbose = False
Set oWsh = WScript.CreateObject("WScript.Shell")

If WScript.Arguments.Named.Exists("V") Then g_fVerbose = True

     '// Disable support for USB Storage Devices
     ChangeMode "USBSTOR","ENABLE"
         '//oWsh.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start", "00000004", "REG_DWORD"
     
     '// Disable support for Floppy disk
     ChangeMode "Flpydisk","ENABLE"
     '//oWsh.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Flpydisk\Start", "00000004", "REG_DWORD"

     '// Disable support for CDROM
     ChangeMode "Cdrom","ENABLE"
     '//oWsh.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom\Start", "00000004", "REG_DWORD"



Sub ChangeMode (strDeviceName,blnMode)

Dim strRegKey : strRegKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"&strDeviceName&"\Start"
On Error Resume Next
Dim strTmp : strTmp = oWsh.RegRead (strRegKey)

     If strTmp <> Empty Then
     '// Key Already exists so change its value
          If blnMode = "DISABLE" Then
          '// Disable the Service
               oWsh.RegWrite strRegKey , "00000004", "REG_DWORD"
               oWsh.Run "cmd /c net stop """ & strDeviceName & """",0,False              
          Else
          '// Enable the Service
               oWsh.RegWrite strRegKey , "00000001", "REG_DWORD"
               oWsh.Run "cmd /c net start """ & strDeviceName & """",0,False
          End If
     end if  
     
     '// Manage rights of user to read inf file
     '// CACLS.EXE stops for user input... which currently not able to automate
     
'     If blnMode = "ENABLE" Then
'          oWsh.Run "cmd /c cacls %systemroot%\inf\" & strDeviceName & ".inf /G BUILTIN\Users:R ""BUILTIN\Power Users:R"" BUILTIN\Administrators:F ""NT AUTHORITY\SYSTEM"":F",0,False    
'     Else
'          oWsh.Run "cmd /c cacls %systemroot%\inf\" & strDeviceName & ".inf /G BUILTIN\Administrators:F ""NT AUTHORITY\SYSTEM"":F",0,False
'     End If

End Sub
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
trenes

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
expertblr

ASKER
Hi

Yeh what changes u have made, i am not getting, the top script is for enabling and below script is for disabling right????????????????????.

Let me try and let u know.
trenes

No the top script is for enabling.
The last script can do both. but then you have to run the script like this myscript.vbs enable or myscript.vbs disable
trenes

Thank you for the points!

Regards,

trenes
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
expertblr

ASKER
Hey trenes,

I tried the enable script i.e  the top one and its enabling the cdrom etc.

What i did is, the script which i had given you i.e which disables the cd rom etc i applied for one particular O U(disabling O U)  and the enable script (the top one) i have applied it for another O . U.(enabling O U)

After that i moved one computer say xyz from main Computers( the default where all the computers will be in the domain) to disabling O U and checked the script was disabling .

Then i moved the xyz computer from disabling O U to enabling O U and checked the script was enabling the cd rom etc.

This is what i needed where i should have two O U's one for enabling and other for disabling.

But i got confused with your last sentence   "The last script can do both. but then you have to run the script like this myscript.vbs enable or myscript.vbs disable".

Let me know that, what i have done is perfect right and pls explain your last sentence i am bit confused with that.

Thanks!!!!!!!!!!!!!
expertblr

ASKER
Hi Trenes,

Is there any similar script which we can apply to the O U which disables the file and printer sharing in the registry pls let me know
trenes

Sorry will look at it later... today
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy