DX Hidden Object - How To

Wednesday, February 5, 2003 by themac | Discussion: WinCustomize Talk

I have a desktop where I have created a hidden printer object. Upon a registry hit (like the printer is printing a file) I want the printer object to show up on the desktop. I have created the VB Script to find the registry entry and just note that the printer has gone online and is printing. But this little script pegs the system usage. Any ideas on how to make it run in the background with little to no overhead or hook the system tray when the printer icon shows up there or to just run with VERY little overhead? Any help would be greatly appreciated.


Option Explicit
Dim ScriptShell, FileSysObj
Set ScriptShell = CreateObject("Wscript.Shell")
Set FileSysObj = CreateObject("Scripting.FileSystemObject")

Sub Object_OnStateChange(State)
If State = "Mouse Away") Then
Object.SetTimer 10,5000
End If
End Sub

Sub Object_OnTimer10
Dim PrinterOnline
PrinterOnline = ScriptShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\0001\System\CurrentControlSet\Control\Print\Printers\Epson\PrinterOnline")
If PrinterOnline = 1 Then
Msgbox ("Printer Is ON line!")
End If
If PrinterOnline = 0 Then
Msgbox ("Printer Is Now OFF line!")
End If

End Sub
werewolf
Reply #1 Thursday, February 6, 2003 10:10 AM
bump

Powered by SkinBrowser!
Weaksid
Reply #2 Thursday, February 6, 2003 10:34 AM
Bumpy Bump Bump

Powered by SkinBrowser!
_Martin_
Reply #3 Thursday, February 6, 2003 2:22 PM
Try this and see how nice it is to the processor. It will loop through the printers on the local machine and display it's status.

Sub Object_OnScriptEnter
Object.SetTimer 10,5000
End Sub

Sub Object_OnTimer10
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")
For Each objPrinter In colInstalledPrinters
Select Case objPrinter.PrinterStatus
Case 1
strPrinterStatus = objPrinter.Name & ": Other"
Case 2
strPrinterStatus = objPrinter.Name & ": Unknown"
Case 3
strPrinterStatus = objPrinter.Name & ": Idle"
Case 4
strPrinterStatus = objPrinter.Name & ": Printing"
Case 5
strPrinterStatus = objPrinter.Name & ": Warmup"
End Select
Script.MsgBox strPrinterStatus
Next
End Sub
themac
Reply #4 Thursday, February 6, 2003 4:03 PM
Martin,

Please excuse my ignorance on VB Script since I have not done a lot with it. But I need to ask a couple of questions.

I replaced the VB script that I had with your changes. I attempted to run the test option inside of the DXScript editor and it won't run. I simply click on the Test button and the system does nothing. Not sure why.

This should run without a user needing to create any state changes (i.e. mouse over, away, down, up, etc.) Is this what the Object_OnScriptEnter does? This is not documented in the DX info and I did not know that this was available to me.

The object is currently a layer. Does it need to be of another type? And what exactly is the difference between a Layer and a Container? I still have not received what I consider a real definition between the two.

Sorry I digress..

OK, so back to the code.

In the GetObject instantiation can you tell me what the ->
(winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") means?

Is this defining the computername to determine the printers attached to the machine? Does this mean that I have to alter it to address my specific printers or is this meant to be generic?

Thanks in advance!!!! I appreciate it.
themac
Reply #5 Friday, February 7, 2003 5:38 PM
Martin,

OK, so I forgot about how finicky VB Script is about tabs, etc. Once I formatted the code it started working.

I appreciate the help. I am working on a couple of other pieces that I want to do as well.

Any way of taking an external program to DesktopX and 'messaging' to it to activate an object?
themac
Reply #6 Friday, February 7, 2003 6:07 PM
Martin,

Can you explain how the following lines actually work? I would really appreciate it.

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")

Thanks!!!
_Martin_
Reply #7 Sunday, February 9, 2003 6:32 PM
Hi,

Sorry, been away for the weekend so I missed these. Mail me personally ([email protected]) and we can discuss things further but here's a few notes relating to your questions which we can progress:

1) The code does not need user interaction. OnScriptEnter will set up parameters etc when the object is first loaded (i.e. DX loads). You can set up a timer here, and then add code to this time the runs at set intervals without action required.

2) The sample script pops up a message with the state, but can be made to change text, or images to represent the result.

3) Re "winmgmts". To quote Microsoft "Windows® Management Instrumentation (WMI) is a component of the Microsoft® Windows® operating system that provides management information and control in an enterprise environment. Using industry standards, managers can use WMI to query and set information on desktop systems, applications, networks, and other enterprise components. Developers can use WMI to create event monitoring applications that alert users when important incidents occur".

I can discuss this more when you mail, and hopefully help you with some other stuff.

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01