0

Hi currently I am able to get the process name with the following codes. The process name I wanted to get is EXCEL.EXE but now I want to get the document name eg. data.xlsx.

Is it possible to get the document name from the process ID?

I am currently using VB.net

        Dim w As Object
        Dim processQ As String
        Dim processes As Object
        Dim process As Object
        w = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & pc & "\root\cimv2")
        processQ = "SELECT * FROM win32_process WHERE name = 'EXCEL.EXE'"
        processes = w.execquery(processQ)
        For Each process In processes
                MsgBox(process.processid & process.name)
        Next

The code works fine for me to get the process's id and name, but what I want now is the document name instead.

The reason that I'm using win32_process is because later on I want it to be able to retrieve it from remote pc as well.

Any replies will be much appreciated :)

After some digging, I found a code that can display Microsoft Excel.

dim activeprocess as Process = Process.GetProcessById(process.processid) MsgBox(FileVersionInfo.GetVersionInfo(activeprocess.MainModule.FileName).FileDescription)

but it's still not I wanted

WLeo
  • 203
  • 2
  • 16
  • data.xlsx is document, not an application. – Sarvesh Mishra Apr 01 '16 at 05:49
  • ohh my bad @Sarvesh thanks for correcting me :) – WLeo Apr 01 '16 at 05:54
  • If you are using `vb.net` why are you using `GetObject`? Also why don't you use the `Process.GetProcessByName` [**here**](https://msdn.microsoft.com/en-us/library/system.diagnostics.process.getprocessesbyname(v=vs.110).aspx)? Also to answer your question, **yes it's possible to get the document's name** only with some `API` call's though... – Trevor Apr 04 '16 at 03:09
  • @zaggler if it is possible, can you explain more on in or can I have any example? I'm really new to this.. sorry – WLeo Apr 04 '16 at 08:30
  • Are you wanting the workbook name's that are currently open? – Trevor Apr 04 '16 at 20:39
  • @zaggler yes exactly :) – WLeo Apr 05 '16 at 01:14
  • If that is the case please see [**this answer**](http://stackoverflow.com/questions/36265674/retrieve-all-workbook-names-during-more-than-one-excel-instances-are-running/36267576#36267576) I have already done. It retrieve's the open `Excel` instances and their workbook names. If you find it to fit your needs please vote. Also it uses a few API to do the work as to get what you need isn't just a few calls, it may be a little overwhelming as you mentioned `I'm really new to this...`, but it works and works well... – Trevor Apr 05 '16 at 01:30
  • @zaggler thanks! it works fine on my pc, but now my question is, how can I retrieve the excel doc name from a remote pc? – WLeo Apr 05 '16 at 02:44
  • Welcome, if it worked you need to vote. Otherwise people won't help people... – Trevor Apr 05 '16 at 02:49

0 Answers0