Link to home
Start Free TrialLog in
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

Avatar of trenes
trenes
Flag of Netherlands image

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
Avatar of expertblr
expertblr

ASKER

Hi,

I know about .adm files, but i need this script which enables the same. Pls let me know its very urgent
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
ASKER CERTIFIED SOLUTION
Avatar of trenes
trenes
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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
Thank you for the points!

Regards,

trenes
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!!!!!!!!!!!!!
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
Sorry will look at it later... today