| 128 | |
| 129 | |
| 130 | void |
| 131 | RunConnectScript(connection_t *c, int run_as_service) |
| 132 | { |
| 133 | STARTUPINFO si; |
| 134 | PROCESS_INFORMATION pi; |
| 135 | TCHAR cmdline[256]; |
| 136 | DWORD exit_code; |
| 137 | struct _stat st; |
| 138 | int i; |
| 139 | |
| 140 | CLEAR(si); |
| 141 | CLEAR(pi); |
| 142 | |
| 143 | /* Cut off extention from config filename and add "_up.bat" */ |
| 144 | int len = _tcslen(c->config_file) - _tcslen(o.ext_string) - 1; |
| 145 | _sntprintf_0(cmdline, _T("%ls\\%.*ls_up.bat"), c->config_dir, len, c->config_file); |
| 146 | |
| 147 | /* Return if no script exists */ |
| 148 | if (_tstat(cmdline, &st) == -1) |
| 149 | { |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | if (!run_as_service) |
| 154 | { |
| 155 | SetDlgItemText( |
| 156 | c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONN_SCRIPT)); |
| 157 | } |
| 158 | |
| 159 | /* Create the filename of the logfile */ |
| 160 | TCHAR script_log_filename[MAX_PATH]; |
| 161 | _sntprintf_0(script_log_filename, _T("%ls\\%ls_up.log"), o.log_dir, c->config_name); |
| 162 | |
| 163 | /* Create the log file */ |
| 164 | SECURITY_ATTRIBUTES sa; |
| 165 | CLEAR(sa); |
| 166 | sa.nLength = sizeof(SECURITY_ATTRIBUTES); |
| 167 | sa.lpSecurityDescriptor = NULL; |
| 168 | sa.bInheritHandle = TRUE; |
| 169 | |
| 170 | HANDLE logfile_handle = CreateFile(script_log_filename, |
| 171 | GENERIC_WRITE, |
| 172 | FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 173 | &sa, |
| 174 | CREATE_ALWAYS, |
| 175 | FILE_ATTRIBUTE_NORMAL, |
| 176 | NULL); |
| 177 | |
| 178 | /* fill in STARTUPINFO struct */ |
| 179 | GetStartupInfo(&si); |
| 180 | si.cb = sizeof(si); |
| 181 | si.dwFlags = STARTF_USESTDHANDLES; |
| 182 | si.wShowWindow = SW_SHOWDEFAULT; |
| 183 | si.hStdInput = NULL; |
| 184 | si.hStdOutput = logfile_handle; |
| 185 | si.hStdError = logfile_handle; |
| 186 | |
| 187 | /* make an env array with confg specific env appended to the process's env */ |
no test coverage detected