John Fors 2014-01-22 05:32
I've recently inherited some code utilizing Ultramon com objects. I'm still learning. Question: Can I programmatically edit the properties of the short cuts. I would like to be able to set the width and height fields to what the appropriate monitor specs are.
John Fors
|
Christian Studer 2014-01-23 09:11
There's no API for editing .umshortcut files, but you could do basically the same thing using the Utility and Window COM objects. If you're interested in this let me know which language you're using and I can post a code sample.
Christian Studer - www.realtimesoft.com
|
Christian Studer 2014-01-23 09:18
Hadn't noticed that you're using VBScript, here's sample code which should do what you want:
Set sys = CreateObject("UltraMon.System")
Set util = CreateObject("UltraMon.Utility")
Set wnd = CreateObject("UltraMon.Window")
If util.Run("%WINDIR%\notepad.exe") = True Then
If wnd.GetAppMainWindow(util.ProcessID, 10000) = True Then
Set mon = sys.Monitors("2")
wnd.Left = mon.Left
wnd.Top = mon.Top
wnd.Width = mon.Width
wnd.Height = mon.Height
wnd.ShowState = 2 'SHOWSTATE_NORMAL
wnd.ApplyChanges 0
End If
End If
Christian Studer - www.realtimesoft.com
|
John Fors 2014-01-27 12:32
Thanks Christian, for the reply :}
I currently have the UM_Shortcuts being executed from a script which runs at Login startup. I was thinking that a configuration stage of the installation would modify the shortcuts file to have the proper spec's including the display exe path. So run-time setting of the Wnd properties isn't enough.
John Fors
|
Christian Studer 2014-01-27 13:05
Is the application installed under Program Files? If yes you could use environment variables, like I did in the sample script for notepad.exe, for example: %ProgramFiles%\UltraMon\UltraMon.exe
Otherwise you could also modify the script to read the location of the executable from a text file or the registry.
Christian Studer - www.realtimesoft.com
|
John Fors 2014-02-25 05:03
I've gotten back to this project and the following snippet doesn't work. It seems the Util.ProcessId returns the wrong Id number, for the rest of the code to work. Sorry for the formating of the snippet. I am using a document file name to open the application via known extension.
Thanks ******* For MonNum = 1 To sys.Monitors.Count ' Start the Shortcut task wait and check the proc Id returned. ' util.Sleep WAIT_NUM_SEC * 1000 If (DbgFlag) Then DebugTxt "DisplayFile= " & DisplayExes(MonNum) ' check if the file exists or the array entry is empty If lcObjFSO.FileExists(DisplayExes(MonNum)) then If (util.Run(DisplayExes(MonNum)) ) Then ProcNum = util.ProcessId If (wnd.GetAppMainWindow(util.ProcessID, 10000)) Then Set mon = sys.Monitors(MonNum) If DbgFlag Then DebugTxt "Mon specs left=" & Mon.Left & " top=" & Mon.Top & " width=" & Mon.Width & " Height=" & Mon.Height wnd.Left = mon.Left wnd.Top = mon.Top wnd.Width = mon.Width wnd.Height = mon.Height wnd.ShowState = 2 'SHOWSTATE_NORMAL wnd.ApplyChanges 0 End If End If Else DebugTxt "File Not found " & DisplayExes(MonNum) End If Next
John J Fors
|
John Fors 2014-02-25 09:23
I've resolved the "incorrect" ProcId issue by passing the EXE path as well as the document path into the Util.Run call. Example
Util.run "C:\office\Excel.exe D:\mydocs\report.xls"
The Excel opens the document correctly and the Util.ProcessId returns the correct Id so that I can change the window.left(top,width,Height,showstate) as you helped show me earlier in this chain.
My problem is that I hardcoded the EXE path into the application for the test but would like to perform a OS query to get the EXE association via document file extension. Any ideas?
John J Fors
|
Christian Studer 2014-02-25 13:09
For Excel the following will work fine:
Set sh = CreateObject("WScript.Shell")
exe = sh.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe\")
Let me know if you need a generic way to do this based on document file extension, that should be possible as well by querying HKEY_CLASSES_ROOT in the registry.
Christian Studer - www.realtimesoft.com
|
John Fors 2014-02-27 13:25
The Example I posted using Excel was a bad choice for example but the application I'm most using to display documents is from OSISoft call ProcessBook. It would not allow me to get the ProcId through the document launch process. I did find a win api call to get the associated Exe. Follows is the example I found, my only problem is VBS will not allow the declares:
*************************************************
Option Explicit
Private Declare Function FindExecutable Lib "shell32" _ Alias "FindExecutableA" _ (ByVal lpFile As String, _ ByVal lpDirectory As String, _ ByVal sResult As String) As Long
Private Const MAX_PATH As Long = 260 Private Const ERROR_FILE_NO_ASSOCIATION As Long = 31 Private Const ERROR_FILE_NOT_FOUND As Long = 2 Private Const ERROR_PATH_NOT_FOUND As Long = 3 Private Const ERROR_FILE_SUCCESS As Long = 32 'my constant Private Const ERROR_BAD_FORMAT As Long = 11
Private Sub Command1_Click()
Dim success As Long Dim pos As Long Dim sResult As String Dim msg As String sResult = Space$(MAX_PATH)
'lpFile: name of the file of interest 'lpDirectory: location of lpFile 'sResult: path and name of executable associated with lpFile success = FindExecutable("Slideshow01.pdi", "C:\UltramonXcel\ControlCenter", sResult) Select Case success Case ERROR_FILE_NO_ASSOCIATION: msg = "no association" Case ERROR_FILE_NOT_FOUND: msg = "file not found" Case ERROR_PATH_NOT_FOUND: msg = "path not found" Case ERROR_BAD_FORMAT: msg = "bad format" Case Is >= ERROR_FILE_SUCCESS: pos = InStr(sResult, Chr$(0)) If pos Then msg = Left$(sResult, pos - 1) Debug.Print msg Debug.Print sResult End If End Select MsgBox msg End Sub
John J Fors
|
Christian Studer 2014-02-27 14:21
I don't think there's an equivalent function in VBScript, you would need to query the registry manually. But if you can also use VB instead of VBScript, you could use UltraMon from your VB app as well.
Christian Studer - www.realtimesoft.com
|