-
February 25th, 2014, 10:45 PM
#1
Can C# programs access the Sysprep program?
I have an extremely simple program -- so simple, in fact, that it does only one thing: attempts to run Sysprep.exe (C:\Windows\System32\Sysprep\sysprep.exe):
Process.Start("C:\Windows\System32\Sysprep\sysprep.exe");
When I run the above snippet, an error occurs indicating that the file called by Process.Start() cannot be found. This happens if I am running the C# program as a standard user or as an administrator user -- the result is the same either way.
However, I can copy and paste that exact path into Windows Explorer, and Sysprep runs just fine. I can also copy and paste the path into a Command Prompt window, and it runs fine there, as well.
If I place a batch (*.bat) file or an executable (*.exe) in the "C:\Windows\System32\Sysprep" folder, my C# program cannot see those. However, if I place them in a folder just one level higher ("C:\Windows\System32"), my C# program can see them.
I thought this might be a permissions issue, but even when I take ownership of the Sysprep folder and give my user account explicit full control of the folder, nothing changes. My C# program still cannot touch anything in that folder.
I am targeting .NET 4.5.
Any ideas on what could be preventing my C# program from accessing Sysprep.exe?
-
February 25th, 2014, 11:03 PM
#2
Re: Can C# programs access the Sysprep program?
Sure. You are not TrustedInstaller (which owns the rights). Sounds like Windows x64
-
February 25th, 2014, 11:15 PM
#3
Re: Can C# programs access the Sysprep program?
It is Windows 7 64-bit.
As I said, though, even when I take ownership of the folder, the same problem occurs. And I can access it even as a standard/limited user, so long as I don't try accessing it using a C# program.
Is there anything inherent about C#/managed programs that would disallow them to access the Sysprep folder?
-
February 26th, 2014, 12:17 AM
#4
Re: Can C# programs access the Sysprep program?
No. Windows elevates to TrustedInstaller privileges. C# doesn't
Look at Powershell. I'd bet it's a 2-5 line script.
-
February 26th, 2014, 08:54 AM
#5
Re: Can C# programs access the Sysprep program?
Yeah, I actually have a PowerShell script that will do this already.
Calling Sysprep is not all I want to do with this program, but that's one of the bare-minimum requirements for the program. I figured if I can't get it to do at least that, there is no reason to move to step two.
If I used a C# program to call a PowerShell program that called Sysprep, would I run into the same permissions issue?
-
February 26th, 2014, 10:51 PM
#6
Re: Can C# programs access the Sysprep program?
I haven't tried. It all depends on the OS, I guess. 64bit is tough. Server is tougher
-
February 28th, 2014, 11:04 AM
#7
Re: Can C# programs access the Sysprep program?
Hi JasonF,
Try using this code. I left the args line in, if you want to pass an unattend.xml file to it.
I also, used manifest files with UAC elevated, if you are still having rights issues.
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
If you need more help on the manifest file, please let me know, I can help you more.
Take Care,
-Mike
Code:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\windows\sysnative\sysprep\sysprep.exe";
startInfo.Verb = "runas";
//startInfo.Arguments = f;
Process.Start(startInfo);
-
February 28th, 2014, 12:21 PM
#8
Re: Can C# programs access the Sysprep program?
Wrong folder? "C:\Windows\System32\Sysprep\sysprep.exe" is the correct one
-
February 28th, 2014, 05:09 PM
#9
Re: Can C# programs access the Sysprep program?
Native is the correct folder, check MSDN, for System32, on 64-bit system.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|