0
votes

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...

2
I'm not quite sure but don't you need a "/C" preceding the command?D. Mika

2 Answers

1
votes

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;
0
votes

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.