I'm trying to use cmd.exe to get Userdomain and Username from %userdomain% and %username% parameters, and put this in a text file to be able to get back the datas.
it works well when I manually launch a command windows and type: echo %userdomain%\\%username% > "C:\\Users\\MyUserName\\AppData\\Local\\Temp\\is-B7P3P.tmp\\domainstring_results.txt"
It works well too if a put it in a batch file and launch the .bat
But if I do the same with the Exec function, it only launches cmd.exe and do nothing else :
CommandLine := 'echo %userdomain%\%username% > "' + ExpandConstant('{tmp}') + '\domainstring_results.txt"';
Exec('cmd.exe', CommandLine, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
I don't want to use a batch file because I want to use temporary folder of the installer, so I can't create the batch before the installer compilation. Cannot be in [Run] section too because I need this information before the Install step...
Simply you can get data calling ExpandConstant('{%WindowsContantNameHere}')
That should allow you to use necessary data for your purposes.
[Code]
function InitializeSetup(): Boolean;
begin
MsgBox('User Name is: ' + ExpandConstant('{%Username}') + #13#10 +
'User Domain is: ' + ExpandConstant('{%Userdomain}'), mbInformation, MB_OK);
end;
Use the GetUserNameString
and GetEnv
functions:
GetUserNameString()
GetEnv('USERDOMAIN')
To answer your question: You are missing the /C
switch. And you should use the {cmd}
constant instead of hardcoding the cmd.exe
.
Exec(
ExpandConstant('{cmd}'), '/C ' + CommandLine,
'', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Though your approach is an overkill.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.