C# finding OS and calling reference based on OS - c#

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

Related

Is it possible to run a program developed for Windows Embedded Compact 7 on Windows Mobile 6.5?

I have tried searching for this answer and have had no luck.
Any information would be useful.
Windows Mobile 6.5 was released in 2008 based on CE 5.2. Windows Embedded Compact 7 was released in 2011 and is CE 7.
If the application is developed targeting .Net Compact Framework 3.5 on Compact 7 then I think it will still run on 6.5.
If it was developed as native on Compact 7 then it may not run on Mobile 6.5 depending on APIs it uses. This answer says it can work. Applications going the other way are more likely to work.
Since you added C# I suppose that you are talking about a managed app.
To run it you need the right version of the compact framework or a newer one on your device.
Latest version supported on WM6.5 should be 3.5, I don't remember if it was part of the OS or if you needed to install it separately, here's the download link:
https://www.microsoft.com/en-us/download/details.aspx?id=65
If your app uses also native code things may be a little more complicated.
CE 7 is binary compatible with older versions (WM6.5 is based on CE5), so those binary components may run on CE5 too. On the other side, new APIs have been added in CE6 and CE7 and this (or just the fact that they have been rebuilt using new SDKs) may prevent those things from running on that device.
It may also happen that a managed app invokes some APIs that are not supported on that specific device (this may depend from OS version but also from the component the manufacturer decided to include in the OS image for that specific device).
If you have source code you may be able to fix those issue.
The only thing you can do is try and see what errors you get (if any). It's not granted that it will run, it's not granted that it won't run.

Simple Windows form app and .NET framework requirements in XP

I have written a very simple Windows form application (my first) in C# using Visual Studio. The application simply shows a dialog with information about the local machine (Local IPs, user name, PC name, domain, among others) and that's it. It finishes when the users clicks the 'OK' button.
I'd like to deploy the application as an executable that runs directly on double click. I have extracted the executable generated by Visual Studio in the project folder and I've succesfully run it in a number of different computers. However, on some computers with XP I get an error message saying that it is not a valid WIN32 application.
I'm pressuming the problem is the .NET framework not being present or an older version than the targeted version is installed.
My question is, is it possible to ensure that the application runs on (at least) Windows XP but still have it as a simple executable that runs on double click?
Thanks in advance.
You could try one of the following approaches:
Use an installer (e.g. Inno Setup) to deploy your application and install the .NET framework if required (Sample for .NET 4.5 and Inno Setup)
Just check if the required .NET framework version is installed during the setup and notify the user if it isn't (Sample with Inno Setup)
Compile with .NET Native (I didn't use it yet, therefore I don't know much about it, but maybe this Intro may help you)
Use C++ and WMI instead
EDIT1: .NET Native requires Windows 10, crossed it out from above
EDIT2: Added C++ with WMI as an alternative approach

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.

Windows CE Console output converting strings

I created a C# console application running on a Windows CE device. I have one line of code in the program so far:
Console.WriteLine("Hello World");
Output on Screen: 11
The 11 is the length of the string, so is something converting my string to a character array or something?
I am using the SDK created from the BSP to target my device. In addition, the BSP includes both .NET 2.0 and .NET 3.5 for the OS, and I'm using Visual Studio 2005 for my console application.
Has anyone ever seen this before in a .NET console app? Thanks.
UPDATE: I tried to create a basic Windows Forms app and run that on my device. This time I got an actual error "System.Windows.Forms dll cannot be found", so that indicates to me that .NET is not installed correctly. I have it included in the Platform Builder catalog, so I'm not sure what else might be missing. Any ideas?
I've definitely never seen this, and I've seen a lot of CF behaviors.
First, don't put CF 2.0 and 3.5 in the OS. Ever. They don't coexist in an OS image project peacefully due to SYSGEN overlaps, plus it's unnecessary as the 3.5 runtimes can load and run 2.0 binaries.
You're certain that your only code is that one line? You're certain that you're runnign the app that is the code you're seeing (i.e. it's not running an old or different version by mistake)? Are you at a breakpoint when this happens?
I finally got it working, but I'm still not sure what the exact issue was.
The "fix" was to start with a clean install of Windows XP, Visual Studio 2005, and Windows Embedded CE 6.0 with all the latest QFE's.
After a rebuild of the OS image, both of my test applications started working as expected.

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

Categories

Resources