Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'DevicePlugNotification v1.0.1, Sep 2022.
- 'https://www.reddit.com/user/jcunews1
- 'https://pastebin.com/u/jcunews
- 'https://greasyfork.org/en/users/85671-jcunews
- '
- 'Script to display notifications when a device is plugged in.
- 'Each device may contain one or more subdevices.
- 'e.g. for USB thumb drive: the device itself (mass storage), a disk drive,
- 'then one or more disk volumes (partitions)
- 'Each notification will display 2 lines: device name and type.
- '
- 'Run the script to start monitoring.
- 'Run the script while it's already monitoring, to stop monitoring.
- 'Run the script with any arguments to omit displaying startup/shutdown dialogs.
- '--------SETTINGS BEGIN
- 'y position in pixels from screen bottom to start placing notifications.
- ypos = 80
- 'display time in milliseconds (1 sec = 1000ms) for each notification.
- 'notifications can be clicked to close it early.
- duration = 10000
- 'notification font size in pixels
- fontsize = 12
- '--------SETTINGS END
- title = "DevicePlugNotification"
- set fs = createobject("scripting.filesystemobject")
- tp = fs.getspecialfolder(2)
- fna = tp & "\DevicePlugNotification.active"
- fns = tp & "\DevicePlugNotification.stop"
- py = 0
- on error resume next
- set fa = fs.createtextfile(fna)
- if err.number = 0 then 'already active
- if wscript.arguments.count = 0 then
- msgbox title& " will be active after this dialog is closed." _
- &vblf& "Run this script again to stop monitoring.", 64, title
- end if
- else
- if msgbox(title& " is already active." &vblf& _
- "Do you want to stop monitoring?", 33, title) = 1 then
- fs.createtextfile(fns).close
- end if
- wscript.quit
- end if
- fs.deletefile fns
- on error goto 0
- set ps = createobject("scripting.dictionary")
- getobject("winmgmts:root\cimv2").execnotificationqueryasync _
- wscript.createobject("wbemscripting.swbemsink", "ev_"), _
- "select * from __instancecreationevent within 1" & _
- " where targetinstance isa 'win32_pnpentity'"
- do
- wscript.sleep 300
- if fs.fileexists(fns) then exit do
- loop
- fa.close
- fs.deletefile fna
- on error resume next
- fs.deletefile fns
- if wscript.arguments.count = 0 then
- msgbox title& " has been stopped.", 32, title
- end if
- sub phide(y)
- ps(y).parentwindow.p.hide
- ps.remove y
- if y = (py - 1) then py = 0
- end sub
- sub pop(s)
- set d = createobject("htmlfile")
- d.write "<script>fontsize=" &fontsize& ";phide=null;" & _
- "function pop(s,y){" & _
- "p=createPopup();d=p.document;" & _
- "d.write('" & _
- "<body onclick=""parent.phide(" &py& ")""><div></div><style>" & _
- "body{margin:0;border:1px solid #007;overflow:hidden;padding:.3em;" & _
- "background:#ddf;font:" &fontsize& "px/normal sans-serif}</style>" & _
- "</body>');" & _
- "h=(a=String(s).split('\n')).length;w=0;" &_
- "for(i=0;i<a.length;i++){l=a[i].length;if(l>w)w=l}" &_
- "w=w*(fontsize*0.55);h=h*(fontsize*1.65);" & _
- "d.close();" & _
- "d.body.firstChild.innerText=s;" & _
- "p.show(screen.width-w-10," & _
- "screen.height-h-" &ypos& "-" &py& "*(h+10),w,h);" & _
- "setTimeout(function(){parent.phide(" &py& ")}," &duration& ")" & _
- "}</script>"
- d.close
- set d.parentwindow.phide = getref("phide")
- d.parentwindow.pop s, py
- ps.add py, d
- py = py + 1
- end sub
- sub ev_onobjectready(o, c)
- set o = o.targetinstance
- pop o.caption &vbcrlf& o.description
- end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement