[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0)
{
LoginByArgs(args); // 參數化登入
}
else
{
LoginNormal(args); // 一般登入
}
}
private static void LoginByArgs(string[] args)
{
CommandArgs commandArgs = CommandLine.Parse(args);
if (commandArgs.ArgPairs.Count > 0)
{
string userName = string.Empty;
string identity = string.Empty;
foreach (KeyValuePair<string, string> pair in commandArgs.ArgPairs)
{
if ("U".Equals(pair.Key, StringComparison.OrdinalIgnoreCase))
userName = pair.Value;
if ("P".Equals(pair.Key, StringComparison.OrdinalIgnoreCase))
identity = pair.Value;
}
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(identity))
{
bool bLogin = Portal.gc.LoginByIdentity(userName.Trim(), identity);
if (bLogin) ShowMainDialog();
else LoginNormal(args);
}
}
}

必要條件:IE 必須啟用「對未標示為安全的 ActiveX 控制項初始化並執行腳本」或相關權限,否則 WScript.Shell 無法啟動本地程式。
WScript.Shell.Run-u user -p token 傳遞給 Main(string[] args)CommandLine.Parse 解析參數 → 呼叫 LoginByIdentity