Hi !
I would like to make and update this VBScript founded here in this Forum bypassing the gpedit.msc that do like this :
- Autocopy itself once in this Folder C:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Shutdown
- Add the correct key in the registry to make this script running on shutdown.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0
Thank you for your Reply !
I would like to make and update this VBScript founded here in this Forum bypassing the gpedit.msc that do like this :
- Autocopy itself once in this Folder C:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Shutdown
- Add the correct key in the registry to make this script running on shutdown.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0
Thank you for your Reply !
Code:
'Main
checkUSB
checkCD
wscript.quit
Sub checkUSB
strComputer = "."
On Error Resume Next
Set WshShell = CreateObject("Wscript.Shell")
beep = chr(007)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive WHERE InterfaceType='USB'",,48)
intCount = 0
For Each drive In colItems
If drive.mediaType <> "" Then
intCount = intCount + 1
End If
Next
If intCount > 0 Then
WshShell.Run "cmd /c @echo " & beep, 0
MsgBox "Don't forget to remove your Flash drive!",16,"Flash drive Check !"
End If
End Sub
Sub checkCD
Const CDROM = 4
strComputer = "."
Set WshShell = CreateObject("Wscript.Shell")
beep = chr(007)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
'Eject if a CD is left in the drive
If objItem.MediaLoaded = True Then
WshShell.Run "cmd /c @echo " & beep, 0
MsgBox "Please remove the CD/DVD from the drive and click OK to continue shutdown.",16,"Remove the CD/DVD !"
Dim WMP: Set WMP = CreateObject("WMPlayer.ocx")
Dim colCDROMS: Set colCDROMS = WMP.CDROMCollection
If colCDROMS.Count > -1 Then
For i = 0 to colCDROMS.Count - 1
colCDROMS.Item(i).Eject
Next
End If
'Use the below line instead of above to eject if empty
'If objItem.MediaLoaded = False Then
Eject objItem.Drive & "\"
End If
Next
End sub
Sub Eject(CDROM)
Dim ssfDrives
ssfDrives = 17
CreateObject("Shell.Application")_
.Namespace(ssfDrives).ParseName(CDROM).InvokeVerb("E&ject")
End Sub