开发者

How can I read this parameters inside my software? (c#)

I have created a shortcut of my .exe file.

I want add to '.exe' extra parameters.(on shortcut: Target attribute)

Example

Target:

"C:\Documents and Settings\de开发者_运维技巧zigo\My Documents\c# programm\DirectoryScanner\DirectoryScanner\DirectoryScanner\bin\Debug\DirectoryScanner.exe" + extra parrams(like a method=1)

How can I read this parameters inside my software? (c#)

Then ,when starting .exe

check

if(method == 1)
{
 //do something
}
else
{
 //do something
}


You could use Environment.CommandLine property to get the command line that has been passed when running the executable and parse it to obtain the parameters. Arguments will also be passed in the Main method:

class Program
{
    static void Main(string[] args)
    {
        // The args array will contain the arguments passed at the command line
        // For example if the executable has been launched like: 
        // "DirectoryScanner.exe method=1"
        // args[0] will contain "method=1"
    }
}


You have to use args variable passed into main function.

Here You will find details: http://msdn.microsoft.com/en-us/library/bb251798.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜