How can a required reboot be detected for Windows 7 - c#

I am working on a project where several software and drivers are installed on a windows 7 PC. This shall work without user inputs.
Now there is the question: How can I determine in this program if a reboot is required to finish an installation (can be driver or software).
We are working on Windows 7 embedded and there is no taskbar enabled or any tooltips or something like this visible. Software is installed in silent mode.

Use the following registry key:
HKLM\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations
Source: How to find out if an MSI I just installed requested a windows reboot?
As discovered by the asker of this question HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending shows when a reboot is pending on the machine as long as the OS is Vista or newer.

After a long research I found a way how to query pending restarts with a native Windows DLL directly in a .NET application.
The main problem is that there can be many reasons why Windows has to restart. In addition, the Windows version sometimes also plays a role.
During the research I came across an article describing various scripts in the Windows Update environment, such as determining whether the automatic updates service is enabled or a computer needs to be rebooted. There you will find a reference to the Microsoft.Update.SystemInfo Object, which finally led to ISystemInformation interface having the method ISystemInformation::get_RebootRequired (Gets a Boolean value that indicates whether a system restart is required to complete the installation or uninstallation of one or more updates.).
For more details about the journey, see my blog post Determine programmatically pending reboot status for a Windows machine in C# and PowerShell

The "PendingReboot" module incorporates all the mentioned tests (+ CCM WMI probe) into a single convenient cmdlet to reliably detect pending reboot:
# Install
Install-Module -Name PendingReboot
# Run
Test-PendingReboot -Detailed

Related

C# project runs into issues when deploying on other machines

Learning C# as I go along with managing an existing project given to me. I've noticed there seem to be deployment issues when I build from my windows 10 machine and set up the application on a user's Windows7 machine
Issues such as:
-Getting null pointer errors
-when saving word docs automatically, instead a save dialog box appears
I cannot for the life of me recreate the issues on my machine.
From what I see,
I use Windows 10 64bit with 32bit Microsoft Office
They use Windows 7 64bit with 32bit Microsoft office
We both have .NET v3, v3.5, v4.0.3... and the project is in v4
I can't help but think it is OS related issue I need to account for but I don't know whether I can trust this due to my lack of experience
Can anyone give some advice
My current plan is, since the users are not very accessible, I will try and get a laptop that replicates theirs. Then, if I can recreate the error on there, then i will install visual studio remote debugger and try to attach this external process and debug from my side. Mostly this is my only plan which is a long shot at best
It sounds like you're dealing with Office automation/addins. I would imagine that the version of Office is very important -- not just 32 bit vs 64 bit, but the specific build and version of Office/Word.
Recreating the error is key, as you suspect. Try setting up a Windows 7 VM on your PC with the same environment that the users have. This will make it easier for you to reproduce and debug the issue.
You also need to know the exact sequence of steps that causes the error, and if possible, you will need a copy of the document the user was working on.

Desktop applicaton not opening after installation in client system

I am currently working with visual studio 2017 with 4.6.1 .net framework. I created setup file for my desktop application the setup installs and runs perfectly in my system. The issue is that the setup installs successfully in other computers but the application not getting opened.
edit
Downloaded .net framework in client system but still same issue occurs.
edit 2
I ran a dependency scan using Dependency walker. It said there were a bunch of files the system could not find - error opening file. The system cannot find the files specified.
API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL
DCOMP.DLL
IESHIMS.DLL
Also, there was an error with modules with an x86 type found - including the setup.exe - but I am unaware how this happened. I have selected 64 wherever I saw the option listed. Please find the screenshot. If this is indeed the issue, how do I solve this?
Application Launch Problems: Here is a short version: WPF application crashes when I launch. Chattier version. Nice one from Martin Prikryl: Application does not work when installed with Inno Setup
Logs: Always check all event logs, application logs and MSI logs - if available. Just to mention it. Maybe try to attach debugger for testing as described here - provided the application gets off the ground at all. Then step through code.
The Usual Culprits: You probably just lack a runtime (example), have a bitness problem (32/64-bit) or insufficient permissions / privileges, or configuration errors (ini, xml, registry, etc...).
To summarize - torpedos, full spread below - nothing too dumb not to mention :-):
Missing Runtimes: First, always check for missing runtimes. For example: .Net, .Net Core, Java, Silverlight,
Direct X (used even for applications now), VC++ Runtime, MS-XML (legacy), etc.... Remember that they come in different versions and some can not co-exist on the box whilst others
can run side-by-side.
Error Code: Looking up error codes and exception messages.
"The Magic Number Database" - online lookup.
Checking Error Codes - several tools and approaches.
Debugging Tools: Some information on debugging tools.
Tools to debug dependency issues - ProcMon.exe, VS, Dependency Walker, etc...
COM dependency errors
Essential service debugging tools:
Event Viewer, Task Manager, Services.msc
Process Explorer, NET command, SC.exe
Windows Services Frequently Asked Questions (FAQ)
ProcMon.exe: The tool of the trade. The one-size-fits-all
tool. The bee's knees, the topper-most, the quantum leap, the cat's
pajamas (yes, it is a Top Gear Hamster allusion). It can be a challenge to use it effectively, but it is the
best general-purpose debugging tool that is free.
Quick, Rudimentary Sample
Hanselman's longer video sample
Other Ideas:
Configuration Settings?
Dev-box sins: Hard coded references? Test Servers / UAT links?
Manifests, INI files and XMLfiles?
Registry settings? HKLM / HKCU
Connection strings. See Authentication & Authorization section below as well.
Platform & Bitness? (ARM, Intel 32 / 64, etc...).
Very common to read from wrong registry hive (the classic time waster):
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\MyApp\MySettings (32-bit)
HKEY_LOCAL_MACHINE\SOFTWARE\MyApp\MySettings (64-bit)
Prerequisites & Dependencies?
On the topic of dependency scanning and debugging.
Dependency Walker: Types of dependencies.
Does Fuslogvw.exe tell you anything? (.NET assembly binding failures for a .NET application). How the Runtime Locates Assemblies
Quick check: Visual Studio modules view
Missing / Broken Registration (indirect dependencies)
Missing COM, COM Interop (regasm.exe), registrationless COM (manifest based)
Calling a .NET Component from a COM Component
Calling COM Components from .NET Clients
Broken Side-By-Side Win32 Assembly Manifest (obscure, can be caused by sloppy corporate application repackaging, may strike seemingly random PCs)
GAC installation?
Two GACs exist.
GAC / WinSxS Commit Issues: GAC / WinSXS files don't get installed into the GAC until the commit phase which is after StartServices.
Permissions & Privilege? - local - ACL permissions and NT privileges?
ProcMon.exe
Resolving Permission Denied:
System.UnauthorizedAccessException while running .exe under program files
WiX after installation my exe file doesn't work by double click, only run as administrator work
Authentication / Authorization - network related
Local user, domain user, Active Directory: group membership, group policy, etc...
Launching User: User profile issues? Maybe try with another user logged on where it fails?
Authentication Mode: Windows Authentication. SQL Server Authentication, etc...
General Network & Proxy issues? (proxies, WINS, DNS and all the complexities involved in networking. UNC paths reachable?)
Licensing? (conceivably related to hardware dongles and drivers)
Security software interference? (software / hardware firewall, anti-virus, encryption tools and suites, etc...)
OS version or edition? (Windows 7 problems)
Localization? Non-English systems?
Drivers?
Hardware?
Encoding?
System corruption? (wrong time, disk errors, file and path names are too long, disk full, "wrong something")
Target Machine Nature? Virtuals? SOE? Are the target machines real machines? Test machines?
Locking / Blocking / In-Use files and registry keys?
Malware? Can cause practically anything in terms of problems.
Links:
WiX Toolset PermissionEx Problem - App Does Not Run After Installation
EXE file is not working
make sure that the 4.6.1 .net framework is installed on the client system.Because the application requires .net frame work installed on the computer
To successfully deploy an application, you must also deploy all components that are referenced by the application.View the Deployment Process
Users might need administrative permissions or similar user permissions on the computer to install bootstrapped components. For ClickOnce applications, this means that the user might need administrative permissions to install the application regardless of the security level specified by the application. After the application is installed, the user can run the application without administrative permissions.
I am assuming you and your client are running install and application run as Administrator.
Possible root cause:
System prerequisite is not meet, you should check all dependencies is ready on the target client system, or add the prerequisite to your installation guide
Privilege issues, you might copy files or change registry locally with administrator rights, but the client is not. If so, you need change files to "C:\Users{username}\AppData\Roaming" or install with administrator privilege on the client system.
In such a situation, app possibly crashed in client system:
Check your application log if any errors
Check windows Log if any errors
Dump system info using WinDbg.exe and debug it
I also faced that kind of problem before.
Just try to install another location not inside the program file of C:\ Drive. You may choose different drive or you may install in C drive also but not inside the program files.

Analyzing with SonarQube Scanner for MSBuild on Windows 10

Two weeks ago I was able to run and analyse .net projects on windows 10 but after some times, it stopped. I am getting this app can't run on your PC , To find the version for your PC, Check with the software publisher.
I was following this url Scanning using Ms Build
I have also changed my local security option, the option of allow UIAccess applications to prompt for elevation without using the secure desktop to Enabled.
I am using windows 10.0.16299 x64 and there is no recent updates done on the computer.
I am running the command from sonar-scanner-msbuild-4.0.2.892\SonarQube.Scanner.MSBuild.exe and I have sonarqube-7 installed and running.
What Am I missing, I am not sure what caused the execution to stop and I checked there is no antivirus or firewall blocking and there is no error .

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

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

Install application in window 7 without UAC using C#

When I install my C# app in windows 7, UAC always shows. I'm not logged in as Administrator but I want my application to be installed without the UAC.
Can you give me ways on how to do it?
The UAC prompt shows for any number of reasons, none of which is "the code inside the exe calls function X or tries to write to place Y." These include:
the name contains setup, patch, update etc (eg setup21.exe) and there is no manifest
you embedded a manifest that asks for requireAdministrator. You would have done this on purpose in Visual Studio.
there is an external manifest (for NewApp.exe it would be NewApp.exe.manifest) in the same folder that asks for requireAdministrator. You would have done this on purpose too.
you have right-clicked the exe, and on the Properties Compatibility you have chosen to elevate it, or to run as XPSP2 which for 7 also elevates
someone in your company has applied a Group Policy that this installation app should run elevated (unlikely)
you once ran it, got a dialog from Windows saying "that may not have worked right" and agreed to try again with "recommended settings"
Do any of these seem likely? If so, correct them and see if the UAC prompt goes away.
Single Package Authoring link text
You'll want to use Windows Installer / Windows Installer XML to make this install behave the way you request.
If you want to install an app without UAC then you can only touch folders that the currently logged in user can write to. Google Chrome does this--it installs the entire application to the user's local application data folder.
It's very non-standard and I would argue MS should prohibit running code from this location, but it's a working solution to requiring administrator/UAC access to install applications.
Incidentally, Google Chrome more recently made a traditional installer available so one user can install it to be used by all users on the computer.
If you want your application to be installed without triggering the UAC, install to %APPDATA% (instead of installing to %ProgramFiles%) and write to the HKCU hive only in the registry (i.e. don't try to write to HKLM, HKCR, etc.)

Categories

Resources