Skip to content

Commit

Permalink
support start_show
Browse files Browse the repository at this point in the history
  • Loading branch information
rexdf committed Nov 28, 2017
1 parent 0546c51 commit 4fecda1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CommandTrayHost/CommandTrayHost.rc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "CommandTrayHost.exe\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "CommandTrayHost taskbar\0"
VALUE "ProductVersion", "0, 4, 0, 0\0"
VALUE "ProductVersion", "0, 5, 0, 0\0"
VALUE "SpecialBuild", "\0"
END
END
Expand Down
36 changes: 21 additions & 15 deletions CommandTrayHost/configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ bool initial_configure()
// 下面的是可选参数
// 当CommandTrayHost不是以管理员运行的情况下,由于UIPI,显示/隐藏会失效,其他功能正常。
"require_admin":false, // 是否要用管理员运行
"start_show":false, // 是否以显示(而不是隐藏)的方式启动子程序
},
{
"name":"cmd例子2",
Expand Down Expand Up @@ -97,6 +98,7 @@ bool initial_configure()
"enabled":true, // run when CommandTrayHost starts
// Optional
"require_admin":false, // to run as administrator, problems: User Interface Privilege Isolation
"start_show":false, // whether to show when start process
},
{
"name":"cmd example 2",
Expand Down Expand Up @@ -568,12 +570,25 @@ void create_process(

check_and_kill(reinterpret_cast<HANDLE>(handle), static_cast<DWORD>(pid), name.c_str());
}

LOGMESSAGE(L"%d %d\n", wcslen(cmd), wcslen(path));

bool require_admin = false, start_show = false;
try
{
require_admin = js["configs"][cmd_idx].at("require_admin");
start_show = js["configs"][cmd_idx].at("start_show");
}
catch (std::out_of_range& e)
{
LOGMESSAGE(L"create_process out_of_range %S\n", e.what());
}
LOGMESSAGE(L"require_admin %d\n", require_admin);

js["configs"][cmd_idx]["handle"] = 0;
js["configs"][cmd_idx]["pid"] = -1;
js["configs"][cmd_idx]["running"] = false;
js["configs"][cmd_idx]["show"] = false;

LOGMESSAGE(L"%d %d\n", wcslen(cmd), wcslen(path));
js["configs"][cmd_idx]["show"] = start_show;

std::wstring name = utf8_to_wstring(js["configs"][cmd_idx]["name"]);
TCHAR nameStr[256];
Expand All @@ -583,7 +598,7 @@ void create_process(
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.wShowWindow = start_show ? SW_SHOW : SW_HIDE;
si.lpTitle = nameStr;

PROCESS_INFORMATION pi;
Expand All @@ -601,16 +616,7 @@ void create_process(
LOGMESSAGE(L"cmd_idx:%d\n path: %s\n cmd: %s\n", cmd_idx, path, commandLine);


bool require_admin = false;
try
{
require_admin = js["configs"][cmd_idx].at("require_admin");
}
catch (std::out_of_range& e)
{
LOGMESSAGE(L"create_process out_of_range %S\n", e.what());
}
LOGMESSAGE(L"require_admin %d\n", require_admin);


// https://stackoverflow.com/questions/53208/how-do-i-automatically-destroy-child-processes-in-windows
// Launch child process - example is notepad.exe
Expand Down Expand Up @@ -660,7 +666,7 @@ void create_process(
shExInfo.lpFile = file_wstring.c_str(); // Application to start
shExInfo.lpParameters = parameters_wstring.c_str(); // Additional parameters
shExInfo.lpDirectory = working_directory;
shExInfo.nShow = SW_HIDE;
shExInfo.nShow = start_show ? SW_SHOW : SW_HIDE;
shExInfo.hInstApp = NULL;

if (ShellExecuteEx(&shExInfo))
Expand Down
2 changes: 1 addition & 1 deletion CommandTrayHost/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ void LOGMESSAGE(wchar_t* pszFormat, ...);

#define CommandTrayHost (L"Command_Tray_Host")

#define VERSION_NUMS L"0.4.0"
#define VERSION_NUMS L"0.5.0"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ example configure
"enabled":true, // run when CommandTrayHost starts
// Optional
"require_admin":false, // to run as administrator, problems keywords: User Interface Privilege Isolation
"start_show":false, // whether to show when start process
},
{
"name":"kcptun 1081 8.8.8.1:12346",
Expand Down
5 changes: 3 additions & 2 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ A Command Line program systray for Windows
"enabled":true, // 是否当CommandTrayHost启动时,自动开始运行
// 下面的是可选参数
"require_admin":false, // 是否要用管理员运行,当CommandTrayHost不是以管理员运行的情况下,显示/隐藏会失效,其他功能正常。
"start_show":false, // 是否以显示(而不是隐藏)的方式启动子程序
},
{
"name":"kcptun 1081 8.8.8.1:12346",
Expand Down Expand Up @@ -107,8 +108,8 @@ A Command Line program systray for Windows

**提示2**: 管理员比较复杂,如果不是真的需要。配置中不要出现任何`require_admin`
简而言之:
- 如果CommandTrayHost是以管理员启动的,那么启动的要求特权的子进程没啥问题,但是CommandTrayHost开机启动会比较麻烦,不能用菜单的那个。
- 如果CommandTrayHost是普通用户,而且没有要求提权,但是 尝试启动了一个要求提权的程序 或者 对程序加上了`"require_admin":false,`, 那么运行时会弹出UAC,授权后是可以正常运行以及重启应用,但是启动后,非特权的CommandTrayHost是没法唤出显示的。
- 如果CommandTrayHost是以管理员运行的,那么启动的要求特权的子进程没啥问题,但是CommandTrayHost开机启动会比较麻烦,不能用菜单的那个。
- 如果CommandTrayHost是以普通用户运行的,而且没有要求提权,但是 尝试启动了一个要求提权的程序 或者 对程序加上了`"require_admin":false,`, 那么运行时会弹出UAC,授权后是可以正常运行以及重启应用,但是启动后,非特权的CommandTrayHost是没法唤出显示的。

**注意**: 所有的路劲,必须是`\\`分割的,这是因为json规定字符串,会自动转义`\`之后的字符。

Expand Down

0 comments on commit 4fecda1

Please sign in to comment.