Execute the command command "ksetup.exe" programmatically

The Ksetup.exe tool is used to configure the KDC server on a Windows machine; Link1 , Link2 ;

This tool is present in 'C: \ Windows \ System32 \'; Find image;

This can be done directly from the command line to get the result of installing the KDC on the machine; (Check the image)![KDC executed]

I need to execute this command programmatically via C #; I tried to use ProcessInfo class with below code; But I couldn't get the result for just this command; What I mean is that I can get the output of all the other command I have tried (e.g. ipconfig, hostname ,.)

ProcessStartInfo startInfo = new ProcessStartInfo("cmd", "/c ksetup")
        {
            WindowStyle = ProcessWindowStyle.Hidden,
            UseShellExecute = false,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            CreateNoWindow = true,
            WorkingDirectory = @"C:\Windows\System32"
        };
Process p = Process.Start(startInfo);
p.Start();
p.WaitForExit();

      

When I do the same, I get an output like this,

"'ksetup' is not recognized as an internal or external command, \ r \ nprogram variable, or batch file."

What change do I need in my code to execute the command?

Edit - with a workaround

This problem occurs because we are trying to access a file belonging to the directory "C: \ Windows \ System32"

Later, I just copied the file and put it in the "C: \ Windows \ ksetup.exe" folder and it worked;

Other References: Why are 64-bit DLLs going to System32 and 32-bit DLLs to SysWoW64 on 64-bit Windows?

Another solution is to uncheck the "Prefer 32-bit option" on the "Design" tab of the project properties window;

So my question is that we cannot access the files / command located in "C: \ Windows \ System32" programmatically?

+3


source to share


1 answer


Although the OP indicated permission by moving the app to a different folder and assuming that the issue is permissions related, I would like to offer a different answer based on specific testing of this issue.

I strongly suspect that the shelling executable in this case was either x86 or AnyCPU / X64 with "Preferred 32bit Code" enabled.

ksetup.exe is a 64-bit executable file. If the application trying to "call" ksetup is 32-bit and tries to launch the application from the c: \ Windows \ System32 folder, Windows will transparently try to launch this application from the C: \ Windows \ Syswow64 folder. This is why the error "ksetup not recognized ..." - the subsystem tried to find a file in c: \ Windows \ SysWow64 and it was not there.



Moving ksetup to SysWow64 is not a starter because it is initially a 64-bit application, and the dependencies from this folder will not be correct to support the application.

The solution, I respectfully suggest, is to either mark the executable as AnyCPU or x64, with "Prefer 32-bit" unchecked explicitly.

I tried the solution myself with the ksetup executable and reproduced these results by changing the executable between 32 and 64 bit as noted. Installing executable executable for 64-bit or AnyCPU works.

+1


source







All Articles