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
| Option Explicit
Dim oDlg, oFrm, oCtl, objWMIService, colInstalledPrinters, Wscript
Dim objPrinter, net, objPing, objStatus, Resultat, Serveur
Set net = CreateObject("WScript.Network")
'PING DU SERVEUR
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address ='serveur236'")
For Each objstatus in objping
If objStatus.statuscode = 1 Then
msgbox (objStatus.Statuscode)
msgbox ("TEST OK")
else
msgbox (objStatus.StatusCode)
msgbox ("TEST NOK")
'Si le ping ne répond pas
'Rassemble toutes les imprimantes dans colInstalledPrinters
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colInstalledPrinters = objWMIService.execQuery("Select * from Win32_Printer")
'Create the WshDialog.Kit object and store a reference in oDlg
Set oDlg = Wscript.CreateObject("WshDialog.Kit", "oDlg_")
'Add a new form and store a reference to it in the variable oFrm
Set oFrm = oDlg.NewForm("Sample")
'Add a listbox control named LBX1 to the oFrm form
'and store a reference to the control in the variable oCtl
Set oCtl = oFrm.NewListBox("LBX1", 150, 150, 5000, 1000)
'Use the reference variable to add some items to the listbox
For Each objPrinter In colInstalledPrinters
if InStr(1, objPrinter.Name, "\\serveur236\") = 0 then
oCtl.AddItem objPrinter.Name
End If
Next
'Sélectionner par défault la première imprimante
oCtl.ListIndex = 0
'Add an OK button and set it's Default property
Set oCtl = oFrm.NewButton("OK", 900, 1250, 1000, 375, "&OK")
oCtl.Default = True
'Automatically size the form and show it (modally)
oFrm.Autosize
oFrm.Show 1
'Définir l'imprimante selectionnée par défault
If oDlg.Clicked = "OK" Then
net.SetDefaultPrinter oFrm.Ctl("LBX1")
end if
end if
Next |
Partager