Lenovo 360
Lenovo 360

Reputation: 647

What does the win32api.ShellExecute() function do?

I'm learning about printing a file in python. I found many ways to do this, One of the most common ways I've seen is using the win32api module.

import win32api
win32api.ShellExecute(0, "print", path_for_file , None, ".", 0)

When I run this program, the file gets printed without any problems.

But the thing is that I'm not understanding what is actually going on in the win32api.ShellExecute() function and what are the functions of it's arguments. By arugments, I mean this: (0, "print", path_for_file , None, ".", 0)

Can anyone please explain what does each and every argument inside the win32api.ShellExecute() function do?

It would be great if anyone could help me out.

Upvotes: 5

Views: 10844

Answers (1)

dxiv
dxiv

Reputation: 17668

Based on the ShellExecute documentation:

ShellExecute(0,              // NULL since it's not associated with a window
             "print",        // execute the "print" verb defined for the file type
             path_for_file,  // path to the document file to print
             None,           // no parameters, since the target is a document file
             ".",            // current directory, same as NULL here
             0)              // SW_HIDE passed to app associated with the file type

In brief, this performs the same action as right-clicking the path_for_file document in Windows Explorer, then choosing print from the context menu. The app associated with the file type is executed with the print verb and SW_HIDE show command, which normally means it will print the document silently, without displaying any UI.

Upvotes: 4

Related Questions