private char[] getCommandLine(List<String> commands) { StringBuilder sb = new StringBuilder(); boolean isFirstCommand = true; for (String command : commands) { if (isFirstCommand) { isFirstCommand = false; } else { // Prepend a space before the second and subsequent components of the command line. sb.append(' '); } // It's OK to apply CreateProcess escaping to even the first item in the commands // list (the path to execute). Since Windows paths cannot contain double-quotes // (really!), the logic in WindowsCreateProcessEscape.quote() will either do nothing // or simply add double-quotes around the path. WindowsCreateProcessEscape.quote(sb, command); } return Native.toCharArray(sb.toString()); }
/** * Set a string value in registry. * * @param hKey * Parent key. * @param name * Value name. * @param value * Value to write to registry. */ public static void registrySetStringValue(HKEY hKey, String name, String value) { char[] data = Native.toCharArray(value); int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_SZ, data, data.length * Native.WCHAR_SIZE); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } }
/** * Set an expandable string value in registry. * * @param hKey * Parent key. * @param name * Value name. * @param value * Value to write to registry. */ public static void registrySetExpandableStringValue(HKEY hKey, String name, String value) { char[] data = Native.toCharArray(value); int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_EXPAND_SZ, data, data.length * Native.WCHAR_SIZE); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } }
char[] cwdChars = (cwd != null) ? Native.toCharArray(cwd.toAbsolutePath().toString()) : null; if (!NuKernel32.CreateProcessW(null, getCommandLine(commands), null /*lpProcessAttributes*/, null /*lpThreadAttributes*/, true /*bInheritHandles*/, dwCreationFlags, env, cwdChars, startupInfo, processInfo)) {