Knowing an exe file arguments

D

dushkin

Hi,

Is there a way to know an exe file arguments?
Meaning: if an exe file can or should be executed with some
arguments, can I programmaticaly get them?

Thanks.
 
J

Jeff Johnson

Is there a way to know an exe file arguments?
Meaning: if an exe file can or should be executed with some
arguments, can I programmaticaly get them?

No, command line arguments are just a string and are parsed by the program.
Therefore you'd have to disassemble the code to figure out what it's doing.
Of course you might be able to search the file for strings, but it probably
won't tell you much.
 
M

Matt

Hi,

 Is there a way to know an exe file arguments?
 Meaning: if an exe file can or should be executed with some
arguments, can I programmaticaly get them?

Thanks.

The answer is, yes, kind of. Look at the WMI stuff, you can use
something like this, if you know the process name:

string wmiQuery = string.Format("select CommandLine from Win32_Process
where Name='{0}'", processName);
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();
foreach (ManagementObject retObject in retObjectCollection)
Console.WriteLine("[{0}]", retObject["CommandLine"]);
 
A

Arne Vajhøj

Is there a way to know an exe file arguments?
Meaning: if an exe file can or should be executed with some
arguments, can I programmaticaly get them?

If it is a console app that is written with user friendliness
in mind, then one of:

programname
programname -?
programname -h
programname /?
programname /h

should give some info.

Arne
 
A

Arne Vajhøj

Is there a way to know an exe file arguments?
Meaning: if an exe file can or should be executed with some
arguments, can I programmaticaly get them?

The answer is, yes, kind of. Look at the WMI stuff, you can use
something like this, if you know the process name:

string wmiQuery = string.Format("select CommandLine from Win32_Process
where Name='{0}'", processName);
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();
foreach (ManagementObject retObject in retObjectCollection)
Console.WriteLine("[{0}]", retObject["CommandLine"]);

That is for a running program.

Arne
 
M

Matt

The answer is, yes, kind of. Look at the WMI stuff, you can use
something like this, if you know the process name:
string wmiQuery = string.Format("select CommandLine from Win32_Process
where Name='{0}'", processName);
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();
foreach (ManagementObject retObject in retObjectCollection)
     Console.WriteLine("[{0}]", retObject["CommandLine"]);

That is for a running program.

Arne

Yes, that's how I read his question. If he meant what to run it WITH,
obviously,
there is no way. Unless he's talking about shortcut links.

Matt
 
A

Arne Vajhøj

Is there a way to know an exe file arguments?
Meaning: if an exe file can or should be executed with some
arguments, can I programmaticaly get them?
The answer is, yes, kind of. Look at the WMI stuff, you can use
something like this, if you know the process name:
string wmiQuery = string.Format("select CommandLine from Win32_Process
where Name='{0}'", processName);
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();
foreach (ManagementObject retObject in retObjectCollection)
Console.WriteLine("[{0}]", retObject["CommandLine"]);

That is for a running program.

Yes, that's how I read his question. If he meant what to run it WITH,
obviously,
there is no way. Unless he's talking about shortcut links.

The "or should be" gives me the impression that
it is potential arguments.

But I could be wrong.

Arne
 
D

dushkin

Thank you guys all for your comments.

1. Yes, the arguments are not mandatory. They are potential.
2. I hoped I could know the exe arguments BEFORE I run it, bacause I
wanted to avoid the need to be familiar with the arguments list before
running the exe and let the end user select an exe and automatically
display him the arguments list. But I understand now that it is
probably impossible...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top