opening a file using Shell/CPAU (1 Viewer)

Zakraket

Registered User.
Local time
Today, 05:21
Joined
Feb 19, 2013
Messages
88
I want to open files from a networklocation from VBA, only normal users don't have access to that location (and should preferably not get it).

I instead of using shell("explorer.exe filepath") to open files using windows standard app for the file, which needs userpermissions to the path the file is located, for the currently logged in user.
I'm trying to use CPAU in combination with Shell, because using CPAU you can pass a user/password that has permission to open a process

The only problem is that the filepaths have spaces in them and that is Always a bit of a tricky thing to tackle.

So, for example, this works:
Code:
shell("N:\Guideline\Ontw\CPAU -u Domain\User -p password -LWOP -ex " & Chr(34) & "C:\windows\Explorer.exe c:\temp\test.pdf")
But I cannot get it to work with a file that is on a path with a space in it (or with a space in the name), like
Code:
N:\Engineering\JB-MAT\BB\BB-004_Panel Pin\BB-004_Panel Pin.pdf
I'm trying all kinds of thinks:
- adding chr(34) at certain places
- using """
- the above in different versions

But to this point without result.

Trying to figure out the plain cmdline:
Works:
Code:
 N:\Guideline\Ontw\10_Ontw\cpau -u Domain/User -p Password -ex "c:\windows\Explorer.exe "c:\temp\test.pdf""
Doesnt work:
Code:
 N:\Guideline\Ontw\10_Ontw\cpau -u Domain/User -p Password -ex "c:\windows\Explorer.exe "c:\temp\test 1.pdf""
(difference in filename with a space in it)

The last command start explorer, but doesn't open the file (just as the first line I posted, it opens Explorer, but not the file. Must be something with the way I pass the filename?)

Code:
explorer.exe "C:\temp\test 1.pdf"
Also works in commandline
 
Last edited:

vbaInet

AWF VIP
Local time
Today, 04:21
Joined
Jan 22, 2010
Messages
26,374
Like this:
Code:
    Shell "N:\Guideline\Ontw\CPAU " & _
          "-u Domain\User -p password -LWOP -ex " & _
          "C:\windows\Explorer.exe " & _
          [COLOR="Blue"]Chr(34)[/COLOR] & "N:\Engineering\JB-MAT\BB\BB-004_Panel Pin\BB-004_Panel Pin.pdf" & [COLOR="blue"]Chr(34)[/COLOR]
 

Zakraket

Registered User.
Local time
Today, 05:21
Joined
Feb 19, 2013
Messages
88
Tnx, but this didn't work, but I found the solution

Code:
N:\Guideline\Ontw\10_Ontw\cpau -u Domain/User -p Password -ex "c:\windows\Explorer.exe \"c:\temp\test 1.pdf""
I need to add a \ before the second path. This tells the system how to handle the second quoted part. Don't know the exact details, but this works
 

Zakraket

Registered User.
Local time
Today, 05:21
Joined
Feb 19, 2013
Messages
88
Could be, I believe I found it on some page where the author of CPAU explained some possibilities
 

Users who are viewing this thread

Top Bottom