Tuesday, February 25, 2014

Accessing Sysprep.exe using a program written in C#

The Sysprep folder is a read only folder in System 32. I was getting the same File not found error. Essentially, this will work if you execute your program in release mode. For running this in debug mode, use the below code.


Use the LeaveDebugMode to allow System.Diagnostics.Process component of out the state that


lets you interact with OS processes that run in special mode. The below code worked for me:


System.Security.SecureString pwd = new System.Security.SecureString();

pwd.AppendChar('x');

pwd.AppendChar('x');

pwd.AppendChar('x');

pwd.AppendChar('x');

pwd.AppendChar('x');

pwd.AppendChar('x');

pwd.AppendChar('x');


Process.LeaveDebugMode();


Process.Start("C:\\windows\\system32\\sysprep\\sysprep.exe", "<enter your user ID>", pwd, "<enter your domain>");

Process.EnterDebugMode();

No comments:

Post a Comment