I’m trying to invoke the CreateProcess function and am having trouble with the path name for the application, which contains spaces. The documentation here instructs me to ‘use quoted strings’ to specify a path such as X:\My Directory\Myexe.exe but is silent on how to do this, which is a shame as I haven’t managed it yet.
"""X:\My Directory\Myexe.exe"""
gets error 123 (syntax incorrect), and
"X:\""My Directory""\Myexe.exe"
gets error 3 (path not found).
Does anyone know how to do this?
Edit as asked, more code. I’m using this, with various attempts at the exe path name. This doesn’t actually work but fails for other reasons (yet to be discovered).
Dim our_process_information As PROCESS_INFORMATION
Dim process_attributes As SECURITY_ATTRIBUTES
Dim thread_attributes As SECURITY_ATTRIBUTES
create_result = CreateProcess("X:\Myexe.exe", _
vbNull, _
process_attributes, _
thread_attributes, _
0, _
0, _
0, _
"X:\", _
startup_information, _
our_process_information)
This may be failing because you are passing the application name to the command line. The documentation describe them as more or less interchangable (except you can put command line arguments in the second parameter). The second argument is for the command line so you could do something like this:
To wrap the command line in quotes and pass it to the command line argument of the function call. I’ve had success with doing it this way around in the past.
Edit
Fairly nice example here.