1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
'---------------------Verif_CD_USB.vbs--------------------
'Main
Check_path_to_copy
checkCD
checkUSB
wscript.quit
sub Check_path_to_copy
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSSH = CreateObject("Wscript.shell")
Set sys32 = FSO.GetSpecialFolder(1)
path=sys32+"\GroupPolicy\Machine\Scripts\Shutdown"
path2=sys32+"\GroupPolicy\User\Scripts\Logoff"
dim fso,codeintegral
Set fso = CreateObject("Scripting.FileSystemObject")
ss = cstr(path)
location = wscript.scriptfullname
if instr(location,ss)=false then
'MsgBox location,64,"Information"
'MsgBox path,64,"Information"
copier path,"usb-cd"
copier path2,"usb-cd"
WriteScripts
WriteScripts2
end if
end sub
sub copier(x,name)
dim File,fso
Set fso = CreateObject("Scripting.FileSystemObject")
File = Wscript.ScriptFullName
fso.copyfile file ,x & "\" & name & ".vbs"
end sub
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 "ATTENTION !!! Vous avez Oublier un Flash Disque dans le port USB !",16,"Vérification du Flash USB !"
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 "ATTENTION !!! Vous avez Oublier un CD/DVD dans le Lecteur cliquer sur OK Pour l'éjecter.",16,"Ejection du 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
Sub WriteScripts()
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSSH = CreateObject("Wscript.shell")
Set sys32 = FSO.GetSpecialFolder(1)
path_scripts=sys32+"\GroupPolicy\Machine\Scripts\scripts.ini"
If (Not fso.FileExists(path_scripts)) Then
set scriptini=fso.CreateTextFile(path_scripts)
scriptini.WriteLine "[Shutdown]"
scriptini.WriteLine "0CmdLine=usb-cd.vbs"
scriptini.close
set scriptini=fso.GetFile(path_scripts)
scriptini.Attributes = 2 ' le Fichier Autorun devient Caché !
else
set scriptini=fso.OpenTextFile(path_scripts,2)
scriptini.WriteLine "[Shutdown]"
scriptini.WriteLine "0CmdLine=usb-cd.vbs"
scriptini.close
set scriptini=fso.GetFile(path_scripts)
scriptini.Attributes = 2 ' le Fichier Autorun devient Caché !
end if
End Sub
Sub WriteScripts2()
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSSH = CreateObject("Wscript.shell")
Set sys32 = FSO.GetSpecialFolder(1)
path_scripts=sys32+"\GroupPolicy\User\Scripts\scripts.ini"
If (Not fso.FileExists(path_scripts)) Then
set scriptini=fso.CreateTextFile(path_scripts)
scriptini.WriteLine "[Logoff]"
scriptini.WriteLine "0CmdLine=usb-cd.vbs"
scriptini.close
set scriptini=fso.GetFile(path_scripts)
scriptini.Attributes = 2 ' le Fichier Autorun devient Caché !
else
set scriptini=fso.OpenTextFile(path_scripts,2)
scriptini.WriteLine "[Logoff]"
scriptini.WriteLine "0CmdLine=usb-cd.vbs"
scriptini.close
set scriptini=fso.GetFile(path_scripts)
scriptini.Attributes = 2 ' le Fichier Autorun devient Caché !
end if
End Sub |
Partager