Using C# to invoke powershell server commandlets to Enable-WindowsOptionalFeature netfx3 - c#

I am working on a WiX installer that uses Burn and therefore has a .Net requirement. Bundling the prerequisite version of .Net does not work on server OS's as they require the role manager to be used. The fact that it's part of a WiX install is not really of overwhelming importance it's there in case there are other methods to help me accomplish my task. I am running/testing the code below as a standalone .Net Console application. After failing using this method in order to work around this I wrote the following use powershell and "Enable-WindowsOptionalFeature".
static void Main(string[] args)
{
PowerShell ps = PowerShell.Create();
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
Command addDotNet = new Command("Enable-WindowsOptionalFeature");
addDotNet.Parameters.Add("-FeatureName netfx3 -Online -All");
pipeline.Commands.Add(addDotNet);
Collection<PSObject> log = pipeline.Invoke();
}
When I run it this window pops up.
Windows Server roles and features cannot be automatically installed or uninstalled via the Windows Features Control Panel.
Seeing as how I figured I was already using the equivalent of "Server Manager cmdlets" I'm not sure what it's actually asking for. So the two part question is 1) What is the proper way to work around this issue. 2)How do I keep it quiet during install.
PS: If this question really belongs to Server Fault let me know.

Enable-WindowsOptionalFeature is part of the DISM, it would be used to create a windows image to deploy to a new system
Add-WindowsFeature is the one you are looking for, it adds a feature to the current instance of Windows Server. It is in the ServerManager powershell module, which is only available on Windows Server (not on Windows 7)

All I'm going to say is based on common sense, rather than on prior experience, so sorry if this is not relevant.
You seem to be able to be on Windows Server 2012 as only this version has Windows ADK that you are using. Windows 8 (client os )nd Windows Server 2012 (server os) have differen ways of enabling feature. Those surfaced as Optional Features in Windows 8 but as Server Roles/Features in the server.
Note, that contrary to what you say, the bundle does not work not because it's a server OS it does not work because it's included with the OS and need to be enabled. This applies both to server OS (Win 2012) and client OS (Windows 8).
It's just that you need to use different methods for Windows 8 and Win 2012.
For Windows 8 your method could work. For Windows 2012 the help you are seeing suggest that you use Add-WindowsFeature cmdlet.

Basically, the command fails, because the component you need to install is not present in the component store. The administrator needs to insert the install media. Perhaps you could include the respective file(s) with your installer to avoid that manual step, but I've never tried that and it might also pose a licensing problem.
For Server 2012 Microsoft decided to remove the .NET framework 3.5 from the component store by default. It's still present on the install media, just not spooled onto the disk during installation. I wrote a rant about this in my blog a while ago.

I added some additional logging/writeline statements while trying to figure out where things were broken in the server 2012 instance. I realized that those debug lines were not output to the console at all.
It turns out that I was not READING the pop-up closely enough. The complaint was not about using the PS commandlets, but a complaint about trying to install .Net 3.5 to run my app. My app was targeting .Net 3.5 so the message was about the attempt to automatically install .Net 3.5
May this question be more than a testament to my momentary blindness and stupidity, but also serve as commentary on the importance of paying attention to detail and reading the error understanding why it's occurring. :)

Related

C# finding OS and calling reference based on OS

I am trying to call a script from C# to run in powershell, now this works perfectly fine on my machine which is Windows 10 64 bit, however on Windows 7 machines the powershell references are located in a different place and I'm assuming this is why I am getting an exception when hitting the button to run the script, System.IO.FileNotFound-exception.
So back to my original question after some context, can I check the OS and dependant on the result call a different Reference.
If im not making sense please let me know and I'll be happy to discuss further!
Here's a page on MSDN describing how to get the OS version.. What you can do is find the version and set up conditions based on what version you get: if it's Win10, go to C:\Windows\Directory\, if it's Win7 then go to C:\Windows\DifferentDirectory\. As long as you know where the files you need are, it shouldn't be too difficult.
You have compiled your application against a newer PowerShell-version than your Windows 7 client has installed. The exception should say which version it's looking for. A Windows 7 client has PowerShell 2.0 unless you've updated WMF.
You have two options:
Compile you application against System.Management.Automation 6.1.7601 (PowerShell 2.0). Ex. use this NuGet-package: System.Management.Automation
Update Windows Management Framework on the Windows 7 clients. The latest version is 5.0 which is the version that comes with Windows 10).

WPF Application designed in VS 2012 won't run on Windows 7 machine

I've designed a WPF C# application using Visual Studio 2012. The application, which is simple enough, runs fine on my Windows 8 machine using the ClickOnce deployment method. The datagrid displays the content from a SQL Server database and performs all of it's other functions just as I've designed it to, but when I attempt to install it on a Windows 7 machine it immediately crashes and I'm not sure why. The Windows 7 computer I'm trying to install the application on has .NET 4.5 running on it, but is there anything else that computer needs to have installed on it in order to run applications developed with VS 2012. This is my first attempt to install an application developed with VS 2012 on a Windows 7 machine, so I'm not sure if there's another step that I'm missing here. Any help you guys can provide would be greatly appreciated. Thank you.
The message you stated "The application has stopped working and that if Microsoft has a solution..." is an indicator of one of the following:
The Framework is disabled; though 4.5 is installed several root instances are built on the foundation which are apart of Framework 2.0. This particular Framework can cause issues for 3.0, 3.5, 4.0, and even 4.5.
The System.EnterpriseServices.dll is damaged in the Framework. Which needs to be connected back to the Global Assembly Cache (GAC).
And another common issue is the machine.config file log in the Framework Folder can be corrupt and needs to be replaced with a valid one.
There are others that can occur within the System Policy Folder as well, which may require you to use the .Net Cleanup Tool and reinstall the Framework. But before you do any troubleshooting you should go to the Event Viewer and get details of what is going on.
Try these steps first for me:
Windows Key + R
When the run prompt appears type: appwiz.cpl
Go to the left hand side: Turn Windows Features On or Off
Turn Framework 3.5 on if it isn't already; if it is already on go to Step 5.
Turn off the Framework; then reboot.
Once rebooted follow steps 1-4 again.
Now at this point I would suggest trying the application again. If it fails try this:
Open Start
Type 'cmd' in Search
Right Click and Run as an Administrator
Type %windir%\Microsoft.Net\Framework\v2.0.50727\ngen.exe update
Then type: sfc /scannow
The Native Regeneration tool will try to repair the Framework back to a factory state; the System-File-Checker will attempt to fix any errors indicated in Windows. If it can't it will say 'it found integrity violations'.
Those are the steps I would do for general support; but you really should try and locate an error message. As the Framework can become a huge ordeal to cleanup and fix. If you provide more information I will revise my response to help address it.
Hopefully that helps.

How to "Install"/"Enable" .Net 3.5 SP1 under Windows 7?

I'm writing a deployment application that should install all required components before load main module. But I has an issue with dotnet 3.5 SP1 installation on Windows 7. Windows 7 incorporate the dotnet 3.5 SP1, but some times that component disabled by user/manufacturer/...
User can enable it from the Control Panel, but I can't ask him to do that.
How can I enable it from my software, I should exclude a all manual configuration from the deployment process.
I found a way by myself, through ocsetup.exe.
The final command is:
%systemroot%\system32\ocsetup.exe NetFx3
Update:
ocsetup is not available at Winodws 8+, you should use dism to achive the same result.
For Winodws 8+ you have to use the following command:
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All
Being a Win7 user that has had unending problems with .NET 3.5 and would prefer it just stay disabled because it's corrupt, doesn't work right anyway, and once in this state is unfixable in Win7 without a whole new, fresh install of Windows, I wish programmers would just NOT require it be installed. .NET 4.1+ are 3.5.1 backwards compatible and if you write your code properly so that you are looking for 3.5 functionality rather than 3.5 itself, it works and if you coded it right in the first place, you could just install 4.2 instead of 3.5 and it would work, but I have a small handful of programs, including all of MS's own email applications (like outlook) that just insist on using .NET 3.5 and you know what? None of them work on my system.
I would also like to add that if I did install some piece of software that turned on or off windows features on my system without asking for permission first, you'd be getting hate mail from me and that software would be off my system as quickly as I could uninstall it and delete it's folders.

Cant install .NET application in Clients PC

My client's PC runs Windows 7 Ultimate with .netframework 4 client profile. I am unable to install my application developed in VS2008. I tried uninstalling .NET Framework 4 From his PC and running the Clean up tool provided by Microsoft. But still I am unable to install it successfully. It provides Error 1001.
I tried running the program as administrator. I also tried to Turn on .net 3.5 feature from add or remove program.
Thanks in advance. :)
Edit:
The error what i get is shown here.
Furthermore,
I have confirmed that it is a 32bit processor and i run x86 release version of setup
The application is developed in a Windows 7 OS with .NET Framework 3.5
I have installed this application in 7 PCs which have .NET 3.5 installed in them and having OS Windows XP,Vista and Windows 7; and all are working fine.
In clients PC, when I try to install .NET 3.5 again, the installer starts but then it disappears suddenly without doing anything
I have tried turning on .NET 3.5 framework feature from control panel> Program and Features.
I have tried running the program as Administrator
I have tried setting the application setup in Windows XP and Vista compatible mode.
But still the issue persists.
Thanks :)
#Niraj.. hope you recognize me.. :)
Well, I think the issue is with your installer. Something in your package settings is conflicting with the environment at your client's computer. With the error message that you posted, it looks like there is some dependency on some assembly which isnt available to the installer, and hence its failing. This might include version number mismatches too.
You should also look at this question, which talks about an issue similar to yours.
or try using FusLogvw.exe to check which assemblies fail to load at runtime.
As you said you have only .net framework 4 client profile which is a subset of the .NET Framework 4 and is optimized for client applications. Please make sure that everything needed for your new application is included in client profile version. Also it is possible that your application installer requires .NET Frw 3.5 as a dependency. Anyway as already said by Henk no need to do anything with .NET Frw 4 just install 3.5.
There is an exception raised during the installation, and you should as it wished to collect MSI debug log and other necessary information to troubleshoot.
I don't think .NET 4 is the root cause. Otherwise, you should already install this app after uninstallation of .NET 4.
in my opinion
be sure that you not run X64 application in X86 based computer
trying to run them in compatibility mode for OS depend on which OS you used in client system
check the prerequested component are installed or not in client system.
you show the problem 1001 in snapshot so you can Read the log for more information about the setup you trying to install on client side.
your setup forced client system to load a specific type during the installation and type not exactly load as setup want so they give you a exception called "LoaderException"
for more information start googling may be it solved your problem
http://www.google.co.in/search?sourceid=chrome&ie=UTF-8&q=loaderexception+in+.net&qscrl=1
I got it finally...nothing was stopping my application but Crystal Reports.
We forgot to include Crystal Reports Basic as a prerequisite.
Thank you guys for the efforts taken. :)
Niraj

Web Installer for an ASP.NET application failing on machines running IIS7

I have a relatively simple ASP.NET application that I am trying to create an installer for. I am currently using Visual Studio 2008's "Web Setup Project" which, though I'm told is not ideal, has proved no problems when installing on Windows Server 2003 & IIS6.
IIS7 on Server 2008 and Vista has proved substantially more difficult. The installer starts off fine before halting with an unhelpful "The installer was interrupted before could be installed. You need to restart the installer to try again." UAC is switched off, and I've already ensured I'm executing the installer with administritive privledges.
The problem sounds identical to the issue outlined in this blog post, however I have the IIS6 Metabase Compatibility role service installed already. I've also tried playing around with AppPools, the Integrated/Classic pipelines and so on, all to no avail.
I've since turned on MSI logging and, whilst I found nothing concrete, I believe the rollback begins somewhere around this error message.
The error indicates that IIS is in 64 bit mode, while this application is a 32 bit application and thus not compatible.
This doesn't make any sense to me whatsoever, as both Vista and Server 2008 are 32-bit installations. I suspect it's a red herring, but I can't be sure.
Has anyone encountered a similar problem, and if so, is there a solution that doesn't involve me moving to a different installation framework?
Try putting a friendly lil checkmark beside each node in
[Programs and Features // Turn Windows features on or off // Internet Information Services // Web Management Tools // IIS 6 Management Compatibility]
Note that I had the same symptoms posted in the blog though, and this fixed it for me. Yours may be different.
Just tackled this last night, therefore my sincerest good luck to you.
In order to fix that error message for those using Windows 2003 x64, use the following commands from a cmd prompt:
cscript.exe %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 "true"
cd WINDOWS\Microsoft.NET\Framework\v2.0.50727
aspnet_regiis.exe -i
Source:
How to Run a Microsoft .NET 2.0 or higher Web Application in 32-bit Mode in IIS 6.0 on a 64-bit Server
Note:
By doing the first step, you will now notice that the ASP.net tab is no longer visible.
This is a known bug and the work around is too use scripts to change the .Net version for any running sites.

Categories

Resources