How to programmatically emulate battery in Windows workstation without battery device? - windows

For testing purposes I need to force Windows to think that it has battery on workstation PC.
Is there the way to fake/mock/emulate/simulate battery state/low level/charging/discharging in Windows workstation without battery device?
Can I set battery level programmatically on Windows?

tl;dr: Use Windows Driver Testing Framework (WDTF) Runtime Libraries from Windows Driver Kit (WDK)
Long instruction:
Install Visual Studio with Windows Driver Kit (WDK)
Create virtual machine
Seach for WDK Test Target Setup x64-x64_en-us.msi in C:\Program Files (x86)\Windows Kits
Install WDK Test Target Setup x64-x64_en-us.msi on virtual machine.
In Visual Studio, in main menu Driver > Test > Configure Devices add virtual machine to install (WDTF) Runtime Libraries.
From virtual machine copy folder C:\Program Files (x86)\Windows Kits\10\Testing\Runtimes\WDTF\RunTime on your workstation
From RunTime folder run as administrator RegisterWDTF.exe
Output:
C:\RunTime>RegisterWDTF.exe
-Delete registry state.
-Get registry path.
-Register COM DLLs.
Process "C:\RunTime\Actions\Deprecated\DeviceManagement.dll".
Process "C:\RunTime\Actions\DeviceSupport\WDTFDeviceSupportAction.dll".
Process "C:\RunTime\Actions\DrvPkgLibExt.dll".
Not a COM DLL
Process "C:\RunTime\Actions\EDT\WDTFEDTAction.dll".
Process "C:\RunTime\Actions\IoSpy\WDTFIoAttackAction.dll".
Process "C:\RunTime\Actions\IoSpy\WDTFIoSpyAction.dll".
Process "C:\RunTime\Actions\SimpleIO\SimpleIO_D3DTest.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFAnySimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFAudioSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFBluetoothSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFCDROMSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFMobileBroadbandSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFMUTT2STRESSSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFMUTT2TCDSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFNetworkSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFVolumeSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFWebcamSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFWirelessSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFWPDSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimulatedBattery\WDTFSimulatedBatterySystemAction.dll".
Process "C:\RunTime\Actions\System\WDTFSystemAction.dll".
Process "C:\RunTime\Actions\WDTFConcurrentIOAction.dll".
Process "C:\RunTime\Actions\WDTFCpuUtilizationSystemAction.dll".
Process "C:\RunTime\Actions\WDTFDriverPackageAction.dll".
Process "C:\RunTime\Actions\WDTFDriverSetupDeviceAction.dll".
Process "C:\RunTime\Actions\WDTFDriverSetupSystemAction.dll".
Process "C:\RunTime\Actions\WDTFDriverVerifierSystemAction.dll".
Process "C:\RunTime\Actions\WDTFFuzzTestAction.dll".
Process "C:\RunTime\Actions\WDTFInterfaces\WDTFInterfaces.dll".
Process "C:\RunTime\Actions\WDTFPNPAction.dll".
Process "C:\RunTime\Actions\WDTFSUPAction.dll".
Process "C:\WDTF.DLL".
-Update registry state.
-Install Drivers.
-Done
WDTF Registration Successful
Now you can use COM object "WDTF2.WDTF" in your program language like in this VBScript example:
'
' Variable defenition
'
Dim WDTF
Dim SimulatedBatterySystemSystemAction
'
' Create WDTF object
'
Set WDTF = CreateObject("WDTF2.WDTF")
'
' Get your newly created SimulatedBatterySystem action interface
'
Set SimulatedBatterySystemSystemAction = WDTF.SystemDepot.ThisSystem.GetInterface("SimulatedBatterySystem")
' enable the simulated battery
SimulatedBatterySystemSystemAction.EnableSimulatedBattery()
' disable real batteries
SimulatedBatterySystemSystemAction.DisableRealBatteries()
' set to DC power status
SimulatedBatterySystemSystemAction.SetSimulatedBatteryToDC()
' set to 50% charge level
SimulatedBatterySystemSystemAction.SetSimulatedBatteryChargePercentage(50)
WScript.Sleep 10000
' set to AC power status
SimulatedBatterySystemSystemAction.SetSimulatedBatteryToAC()
' enable real batteries
SimulatedBatterySystemSystemAction.EnableRealBatteries()
' disable the simulated battery
SimulatedBatterySystemSystemAction.DisableSimulatedBattery()
Here all WDTF reference: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/content/_dtf/
Just in case, Linux Fake battery module: https://github.com/hoelzro/linux-fake-battery-module

Oleg's answer was fairly straightforward to follow but I was unable to make it simulate a battery - the actions to disable and enable the real battery did succeed.
PS C:\RunTime> .\RegisterWDTF.exe
This version of WDTF is compatible with Windows Build 17763.
-Delete registry state.
-Get registry path.
-Register COM DLLs.
Process "C:\RunTime\Actions\Deprecated\DeviceManagement.dll".
Process "C:\RunTime\Actions\DeviceSupport\WDTFDeviceSupportAction.dll".
Process "C:\RunTime\Actions\DrvPkgLibExt.dll".
Not a COM DLL
Process "C:\RunTime\Actions\EDT\WDTFEDTAction.dll".
Process "C:\RunTime\Actions\IoSpy\WDTFIoAttackAction.dll".
Process "C:\RunTime\Actions\IoSpy\WDTFIoSpyAction.dll".
Process "C:\RunTime\Actions\SimpleIO\SimpleIO_D3DTest.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFAnySimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFAudioSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFBluetoothSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFCDROMSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFMobileBroadbandSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFMUTT2STRESSSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFMUTT2TCDSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFNetworkSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\wdtfsensorsiosimpleioaction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFVolumeSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFWebcamSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFWirelessSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimpleIO\WDTFWPDSimpleIoAction.dll".
Process "C:\RunTime\Actions\SimulatedBattery\WDTFSimulatedBatterySystemAction.dll".
Process "C:\RunTime\Actions\System\WDTFSystemAction.dll".
Process "C:\RunTime\Actions\WDTFConcurrentIOAction.dll".
Process "C:\RunTime\Actions\WDTFCpuUtilizationSystemAction.dll".
Process "C:\RunTime\Actions\WDTFDriverPackageAction.dll".
Process "C:\RunTime\Actions\WDTFDriverSetupDeviceAction.dll".
Process "C:\RunTime\Actions\WDTFDriverSetupSystemAction.dll".
Process "C:\RunTime\Actions\WDTFDriverVerifierSystemAction.dll".
Process "C:\RunTime\Actions\WDTFFuzzTestAction.dll".
Process "C:\RunTime\Actions\WDTFInterfaces\WDTFInterfaces.dll".
Process "C:\RunTime\Actions\WDTFPNPAction.dll".
Process "C:\RunTime\Actions\WDTFSUPAction.dll".
Process "C:\RunTime\WDTF.DLL".
-Update registry state.
-Install Drivers.
-Done
WDTF Registration Successful
PS C:\RunTime> cscript.exe .\fake-battery.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
Loading Wex.Logger.dll from systemdata.cpp linep 922 failed.
WDTF_TARGET : INFO : - GetInterface("SimulatedBatterySystem")
WDTF_TARGET : INFO : Target: ORANGE
WDTF_SIMBATT : INFO : DisableRealBatteries()
WDTF_SIMBATT : INFO : EnableSimulatedBattery()
WDTF_SIMBATT : ERROR : SimulatedBatterySystem critical error installing battbus device. HRESULT=0xE0000203
C:\RunTime\fake-battery.vbs(22, 1) WDTF.SimulatedBatterySystem.1: SimulatedBatterySystem critical error installing battbus device. HRESULT=0xE0000203
Unfortunately there is no information that I could find on the public Internet about these errors. Hopefully someone out there comes across this and knows what to do next!
--
edit: it appears as though Visual Studio installs various drivers in addition to the testing framework so simply copying RunTime folder is insufficient. I ended up adding my workstation as a full target using VS from another workstation. This then let me simulate the battery.

Related

Under what conditions does RmGetList return 2 for the lpdwRebootReasons output parameter?

Background
I am designing an Inno Setup installer to install a Cygwin service, and I am puzzled by the behavior I'm seeing from the Windows Restart Manager APIs.
Specifically, when the service is running (started using the cygrunsrv utility), the RmGetList API function returns 2 (RmRebootReasonSessionMismatch) for its lpdwRebootReasons output parameter. This output parameter is an enumeration of type RM_REBOOT_REASON, and the description on MSDN for the RmRebootReasonSessionMismatch value is:
One or more processes are running in another Terminal Services session.
The Inno Setup log file contains lines like the following:
RestartManager found an application using one of our files: <executable name>
RestartManager found an application using one of our files: <service name>
Can use RestartManager to avoid reboot? No (2: Session Mismatch)
Inno Setup then proceeds trying to replace in-use files, as if Restart Manager was not used at all.
I am puzzled by this output value, because on two different machines I tested (Windows 10 1909 x64 and Windows Server 2012 R2), no terminal server/remote desktop users are logged on.
If I stop the service and start another executable (in the set of files to be replaced by the installer), RmGetList returns 0 (RmRebootReasonNone) for lpdwRebootReasons, and Inno Setup displays the normal dialog for in-use files and allows the user to select to automatically close them.
Process Explorer shows both processes (cygrunsrv.exe and the process it starts) running in session 0 and at System integrity level. Both are console subsystem executables.
Questions
Under what conditions does RmGetList return 2 (RmRebootReasonSessionMismatch) for its lpdwRebootReasons output parameter? (I'm trying to understand why this happens when the service is running.)
Does this value cause the entire Restart Manager session to fail, or can Restart Manager proceed even though it thinks applications are running in one or more different sessions?
For question 2, in the document RM_PROCESS_INFO
bRestartable
TRUE if the application can be restarted by the Restart Manager;
otherwise, FALSE. This member is always TRUE if the process is a
service. This member is always FALSE if the process is a critical
system process.
This value indicates if the application can be restarted by the Restart Manager.
For question 1, Note that services are running in session 0. If the process occupying the resource (registered in RmRegisterResources) is a service A, the RmGetList function which also running in the service process B will return lpdwRebootReasons = RmRebootReasonNone, bRestartable = TRUE.
But if A is not a service, then A & B are running in different sessions, lpdwRebootReasons = RmRebootReasonSessionMismatch and bRestartable = FALSE
other results:(B run with elevated privileges)
A & B is a console and in the same session:lpdwRebootReasons = RmRebootReasonNone, bRestartable = TRUE, ApplicationType = RmConsole.
A & B is a console and in the different session:lpdwRebootReasons = RmRebootReasonSessionMismatch, bRestartable = FALSE, ApplicationType = RmConsole.
A: service, B: console: lpdwRebootReasons = RmRebootReasonNone, bRestartable = TRUE, ApplicationType = RmService
(B not run with elevated privileges):
A & B is a console and in the different session:lpdwRebootReasons = RmRebootReasonCriticalProcess, bRestartable = FALSE, ApplicationType = RmCritical.
A: service, B: console: lpdwRebootReasons = RmRebootReasonPermissionDenied, bRestartable = FALSE, ApplicationType = RmCritical
According the document bRestartable depends on ApplicationType. And then, we can see that if the bRestartable = TRUE, then the lpdwRebootReasons = RmRebootReasonNone. But when bRestartable = FALSE, It depends on the other members RM_PROCESS_INFO.
A Clue from the RestartManager PowerShell Module
The RestartManager PowerShell module (special thanks to Heath Stewart) provides a simple PowerShell interface for the Restart Manager. My commands are as follows:
Set-Location <path to Cygwin root directory>
Start-RestartManagerSession
Get-ChildItem . -File -Include *.exe,*.dll -Recurse | RegisterRestartManagerResource
Get-RestartManagerProcess
Stop-RestartManagerProcess
These commands produce the following output:
Id : <process ID>
StartTime : <process start time>
Description : <executable started by cygrunsrv>
ServiceName :
ApplicationType : Console
ApplicationStatus : Running
IsRestartable : False
RebootReason : SessionMismatch
Id : <cygrunsrv process id>
StartTime : <cygrunsrv process start time>
Description : <description of service>
ServiceName : <service name>
ApplicationType : Service
ApplicationStatus : Running
IsRestartable : True
RebootReason : SessionMismatch
For some reason, Restart Manager sees the cygrunsrv.exe service process as restartable, but the executable it spawns as not restartable. (I am still curious about why this happens in the first place.)
An Imperfect Workaround Attempt
Based on this observed behavior, I first attempted the following workaround:
In the Inno Setup script's [Setup] section, set the following:
CloseApplications=yes
CloseApplicationsFilter=*.chm,*.pdf
RestartApplications=yes
The CloseApplicationsFilter directive specifies what files get registered with the Restart Manager. Note I do not specify *.exe or *.dll here; I want to manually specify only certain .exe files in the [Code] section.
Call the Inno Setup RegisterExtraCloseApplicationsResource function once for each .exe file in the setup that will NOT be spawned by cygrunsrv and put them in the RegisterExtraCloseApplicationsResources event procedure. Example:
[Code]
procedure RegisterExtraCloseApplicationsResources();
begin
RegisterExtraCloseApplicationsResource(false, ExpandConstant('{app}\bin\cygrunsrv.exe'));
end;
It's important not to register any executable spawned by cygrunsrv.exe or any of the Cygwin DLL files, because this will prevent the Restart Manager from taking effect in Inno Setup.
This solution is far from perfect, because executables normally started by cygrunsrv, if started separately, are not detected by Restart Manager (e.g., sshd.exe). For example, new SSH sessions are spawned in executables that the Restart Manager are not restartable.
A Better Solution
I've decided that a better solution is to detect any running executables from code and prompt the user apart from the Restart Manager functionality (which, simply put, doesn't work for Cygwin services).

PowerShell Script execution hangs in Windows Server 2012R2

One of my script hangs during one of our product installation. Hangs is happening while executing some of the common PowerShell and native ExEs from PowerShell.
more details in below question which is actually logged in Windows PowerShell Forums.
we use msdeploy,iisreset,appcmd here during web packages installation, this is the place where it hangs, but hang happens after successful execution of msdeploy.exe. I tried using latest available version of msdeploy, is still hangs some times.
We have around 7 web packages, hang happens after deploying a package as well as before deploying a package.
Code logic here.
Step 1: Test msdeploy exists, if not install it
Step 2 : iisreset (hangs here sometimes)
Step 3 : check if the app pool is available, if so Stop-WebAppPool (hangs here sometimes)
Step 4: install web package using msdeploy
Step 5: get the app pool state and start if it is not started – (some times hangs here)
Step 6: do some app pool settings using appcmd.exe (hangs some times after this execution)
Step 7: some other app pool settings like Set-ItemProperty IIS:\AppPools\$appPoolName -Name recycling.periodicRestart.memory -Value $appPoolRestartMemory
Step 8 : get the next package and go to Step 1
Sometimes, hang happens after executing
netsh http delete urlacl url=$url
Note: None of the hangs are consistent, each and every time, hang happens in either one place.
I did procdump analysis of the powershell process and ended up in ntdll!ZwWaitForMultipleObjectsroutine for all hangs.
same is being shown by the proc explorer threads view as well.
PFB the hanging handle's stack
ntdll.dll!ZwWaitForMultipleObjects+0xa
KERNELBASE.dll!WaitForMultipleObjectsEx+0xed
clr.dll!GetMetaDataPublicInterfaceFromInternal+0x3a95e
clr.dll!GetMetaDataPublicInterfaceFromInternal+0x3a7f8
clr.dll!GetMetaDataPublicInterfaceFromInternal+0x3a5f1
clr.dll!GetMetaDataPublicInterfaceFromInternal+0x3eeb5
[Managed to Unmanaged Transition]
mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne+0x21
mscorlib.dll!System.Threading.WaitHandle.WaitOne+0x31
System.Management.Automation.dll!
System.Management.Automation.Runspaces.PipelineBase.Invoke+0x34
Microsoft.PowerShell.ConsoleHost.dll!
Microsoft.PowerShell.Executor.ExecuteCommandHelper+0x154
Microsoft.PowerShell.ConsoleHost.dll!
Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization+0x7ed
Microsoft.PowerShell.ConsoleHost.dll!
Microsoft.PowerShell.ConsoleHost.DoCreateRunspace+0x1d3
Microsoft.PowerShell.ConsoleHost.dll!
Microsoft.PowerShell.ConsoleHost.CreateRunspace+0x49
Microsoft.PowerShell.ConsoleHost.dll!
Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop+0xc3
Microsoft.PowerShell.ConsoleHost.dll!
Microsoft.PowerShell.ConsoleHost.Run+0x14c
Microsoft.PowerShell.ConsoleHost.dll!
Microsoft.PowerShell.ConsoleHost.Start+0x1aa
Microsoft.PowerShell.ConsoleHost.dll!
Microsoft.PowerShell.UnmanagedPSEntry.Start+0x33c
[Unmanaged to Managed Transition]
clr.dll!DllCanUnloadNowInternal+0xbe3
clr.dll!DllCanUnloadNowInternal+0xaa3
clr.dll!GetMetaDataInternalInterfaceFromPublic+0x1abde
clr.dll!GetMetaDataInternalInterfaceFromPublic+0x1aa87
[Managed to Unmanaged Transition]
mscorlib.dll!System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal+0x80
mscorlib.dll!System.Reflection.RuntimeMethodInfo.Invoke+0x92
[Unmanaged to Managed Transition]
clr.dll!DllCanUnloadNowInternal+0xbe3
clr.dll!DllCanUnloadNowInternal+0xaa3
clr.dll!DllCanUnloadNowInternal+0x12f5
clr.dll!SetRuntimeInfo+0x20b4
clr.dll!SetRuntimeInfo+0x1c16
clr.dll!SetRuntimeInfo+0x253d
clr.dll!SetRuntimeInfo+0x2906
clr.dll!SetRuntimeInfo+0x276d
clr.dll!SetRuntimeInfo+0x26ae
powershell.exe+0x8663
powershell.exe+0x7c67
powershell.exe+0xa6cc
KERNEL32.DLL!BaseThreadInitThunk+0x22
ntdll.dll!RtlUserThreadStart+0x34

Windows Driver Kit - inf2cat error

I am running a sample code from windows driver samples and it gives me the following error :
1>------ Rebuild All started: Project: ObCallbackTestCtrl, Configuration: Release x64 ------
2>------ Rebuild All started: Project: ObCallbackTest, Configuration: Release x64 ------
1> Building 'ObCallbackTestCtrl' with toolset 'WindowsApplicationForDrivers10.0' and the 'Desktop' target platform.
1> pchsrc.cpp
2> Building 'ObCallbackTest' with toolset 'WindowsKernelModeDriver10.0' and the 'Desktop' target platform.
2> pchsrc.c
2> callback.c
1> main.cpp
2> tdriver.c
2> util.c
2> Generating Code...
1> utils.cpp
1> Generating Code...
2> ObCallbackTest.vcxproj -> C:\Users\me\Desktop\obcallback\driver\x64\Release\ObCallbackTest.sys
1> ObCallbackTestCtrl.vcxproj -> C:\Users\me\Desktop\obcallback\control\x64\Release\ObCallbackTestCtrl.exe
2> Done Adding Additional Store
2> Successfully signed: C:\Users\me\Desktop\obcallback\driver\x64\Release\ObCallbackTest.sys
2>
2> Inf2Cat task was skipped as there were no inf files to process
2>
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========
I am not sure if its a warning or intended to be, but nothing happens when I run the program. I run the program with "-install" arguments and it doesn't give any error. Then no other commands have any effect. "-reject xyz" doesn't stop the execution of the xyz process, and "-name" "-deprotect" don't seem to work either. They don't work or throw any error either.
I have read the other related thread on the same issue but I don't have that update installed on my system.
I am running Windows 7 and VS 2015.
Would appreciate any help, thanks!
You need to load the kernel-mode device driver which is used for the kernel-mode callback; the user-mode program is nothing but a a console program which will communicate with the kernel-mode device driver via IOCTL. The kernel-mode device driver is responsible for actually providing the functionality.
ObCallbackTest.sys was successfully built according to the log you posted, therefore go into your analysis environment, copy across ObCallbackTest.sys and ObCallbackTestCtrl.exe and then load ObCallbackTest.sys with the Service Manager (e.g. OSRLOADER will be fine for testing). After the kernel-mode device driver is active, run ObCallbackTestCtrl.exe with administrator rights and see if it then works.
Don't do it on your Host environment because BSOD crashes can cause data corruption, and that can have devastating effects on your real Host environment. Instead, use a physical machine for testing kernel-mode software, or a Virtual Machine. You also need to setup remote kernel debugging support so you can debug your kernel-mode software for investigation to ensure things are working as they should, and to help you diagnose the source of bugs in your device driver projects.

gpg2.exe and gpg.exe exit code 255

I have the following system configuration:
Windows 2008 Server 64-bit with Service Pack 1
Gpg4win, version 2.1.0
Included Gpg4win components in Version 2.1.0 are:
GnuPG: 2.0.17
Kleopatra: 2.1.0 (2011-02-04)
GPA: 0.9.1-svn1024
GpgOL: 1.1.2
GpgEX: 0.9.7
Claws-Mail: 3.7.8cvs47
Kompendium DE: 3.0.0
Kompendium EN: 3.0.0-beta1
What I'm trying to do is to decrypt a local file using GnuPG with Process.Start from a .NET 3.5 web service.
This command below is working just fine when ran from cmd.exe on that very machine.
"c:\Program Files (x86)\GNU\GnuPG\pub\" --charset utf8 --no-tty --output c:\decrypted_file.txt" --batch -r "name_for_secret_key"
--passphrase-file "C:\path_to_passphrase_file.txt"
--decrypt "c:\encrypted_file.gpg"
However it's not working when executed from the web service that is deployed under IIS 7.5.
Tried the following:
- impersonated user with admin rights (in the application pool or in the code itself) to run the process under
- ran the cmd.exe process directly with Process.Start and passed in the arguments as described above (by redirecting standard input)
Results
- exit code for gpg2.exe is 255 and nothing else happened
- in event viewer / application found errors like: Faulting application gpg2.exe, version 0.0.0.0, time stamp 0x4d6e6194, faulting module unknown, version 0.0.0.0, time stamp 0x00000000, exception code 0xc0000005, fault offset 0x00000000, process id 0x1a914, application start time 0x01cd3f46059b0031.
- by redirecting standarderror I only got the same 255 exit code
- ran Process Monitor on that machine but that hasn't helped either, there were some "Name Not Found" issues, no access denied problems and both gpg.exe and gpg2.exe results were SUCCESS and exit codes were 255.
- DEP has default settings, it's on on essential windows programs and services
Could you think of something different than what I've already tried which might get this working?

Delphi XE2 Firemonkey sample app not running on a MAC

I am trying to run a sample Firemonkey app on a Mac, but I am getting this message in the mac:
dyld: Library not loaded: #rpath/libcgunwind.1.0.dylib
Referenced from: /Users/nobre/Applications/Embarcadero/PAServer/scratch-dir/rafael_colucci-Nobre/Project37.app/Contents/MacOS/Project37
Reason: image not found
dyld: Library not loaded: #rpath/libcgunwind.1.0.dylib
Referenced from: /Users/nobre/Applications/Embarcadero/PAServer/scratch-dir/rafael_colucci-Nobre/Project37.app/Contents/MacOS/Project37
Reason: image not found
dyld: Library not loaded: #rpath/libcgunwind.1.0.dylib
Referenced from: /Users/nobre/Applications/Embarcadero/PAServer/scratch-dir/rafael_colucci-Nobre/Project37.app/Contents/MacOS/Project37
Reason: image not found
I used this tutorial to add a OSX platform:
New Mac and Rad Studio XE2
EDIT
More info about the error:
Process: Teste2 [34270]
Path: /Users/User/Applications/Embarcadero/PAServer/scratch-dir/rafael_colucci-VM/Teste2.app/Contents/MacOS/Teste2
Identifier: Teste2
Version: ??? (???)
Code Type: X86 (Native)
Parent Process: launchd [94]
Date/Time: 2011-09-01 19:36:26.246 +0100
OS Version: Mac OS X 10.6.8 (10K540)
Report Version: 6
Interval Since Last Report: 3908 sec
Crashes Since Last Report: 4
Per-App Crashes Since Last Report: 4
Anonymous UUID: 58C242CA-C324-4A23-86ED-96D93C7C1A84
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0
Dyld Error Message:
Library not loaded: #rpath/libcgunwind.1.0.dylib
Referenced from: /Users/User/Applications/Embarcadero/PAServer/scratch-dir/rafael_colucci-VM/Teste2.app/Contents/MacOS/Teste2
Reason: image not found
Binary Images:
0x8fe00000 - 0x8fe4163b dyld 132.1 (???) <4CDE4F04-0DD6-224E-ACE5-3C06E169A801> /usr/lib/dyld
Model: VMware Virtual Platform, BootROM 6.00, 1 processor, 30 GHz, 1 GB, SMC 1.30f3
Graphics: VMware SVGA II, VMware SVGA II, PCI, 16 MB
Network Service: Ethernet, Ethernet, en0
Parallel ATA Device: VMware Virtual IDE CDROM Drive
SCSI Device: SCSI Target Device # 0
USB Device: VMware Virtual USB Hub, 0x0e0f (VMWare, Inc.), 0x0002, 0x00200000 / 3
USB Device: VMware Virtual USB Keyboard, 0x05ac (Apple Inc.), 0x020b, 0x00210000 / 4
USB Device: VMware Virtual USB Mouse, 0x0e0f (VMWare, Inc.), 0x0003, 0x00100000 / 2
EDIT
Some screenshots:
I just installed the Delphi XE2 Trial and I'm getting the same issue - unable to start a FireMonkey application on Mac OS X because of the missing libcgunwind.1.0.dylib.
However, I believe I know what the problem is. This file should be inside the ($BDS)\Redist\osx32 folder ready to be deployed with your Delphi OSX application. But, if you only installed the Delphi XE2 product instead of the complete RAD Studio XE2, these redistributable files will be missing, e.g. not installed at all.
Wherever this specific file is mentioned in the documents, it's in relation to C++Builder. So if this really is the issue, it's probably a (not so small) oversight on Embarcadero side.
To answer your question - I believe if you install the C++Builder XE2 trial, or the whole RAD Studio XE2 package, you should get these redistributable files.
If you go to the directory where PAServer was installed on you Mac, you should see that libcgunwind.1.0.dylib is present there.
The installer tries to help by creating a paserver.command file. If you launch using this, it should set your library path correctly so the above file is found.
If you've moved your PAServer location, just manually update the paserver.command file with the appropriate paths and run.
Runtime error 231 at 000169AD
this is a problem under VMWare, see
https://forums.embarcadero.com/message.jspa?messageID=393962
Workaround is copy FMX.Filter.pas to your project directory and modify:
function FilterByName(const AName: string): TFilter;
var
i: Integer;
begin
Result := nil;
if Filters = nil then
Exit;
if GlobalUseHWEffects then
begin
for i := 0 to Filters.Count - 1 do
if CompareText(TFilterClass(Filters.Objects[i]).FilterAttr.Name, AName) = 0
then
begin
Result := TFilterClass(Filters.Objects[i]).Create;
Exit;
end;
end;
end;
function FilterClassByName(const AName: string): TFilterClass;
var
i: Integer;
begin
Result := nil;
if Filters = nil then
Exit;
if GlobalUseHWEffects then
begin
for i := 0 to Filters.Count - 1 do
if CompareText(TFilterClass(Filters.Objects[i]).FilterAttr.Name, AName) = 0
then
begin
Result := TFilterClass(Filters.Objects[i]);
Exit;
end;
end;
end;
and in dpr set GlobalUseHWEffects := False;
This is because VMWare and emulating graphics hardware
You have to install the PA Server here follow these instructions
Installing and Running the PA on Mac OS X
Embarcadero's instructions on starting the remote server seem to be incorrect. Use the paserver.copmmand file to start the server. Then my project ran fine.
Then Deploying. Change the build configuration to Release instead of Debug. You have to copy the libcgunwind.1.0.dylib to the Redist\osx32 directory or the release will fail. Then tried build/release again. The "project".rsm file is in the debug directory and not in the release directory. I copied the .rsm file to the release directory, Deployed and it worked. This was the case with my own demo project and the controlsDemo project. Either one worked the same way.
A bit rough start but everything is working. Don't know why they put a menubar on the controls demo since it is not very mac-like. Change it to a main menu and everything works great.
Bill
I have solved this for me. I was clicking the green run button in the ide which is 'run without debugging'.
Click the run button next to it, which in XE2 is the run button us older people are used to.
If think you need to open a cmd window and do the following command to populate the Redist folder, after that the the Deployment Manager will locate the necessary files:
C:\Program Files (x86)\Embarcadero\RAD Studio\9.0\Redist> redistsetup default
Deployment Manager has a "Reconcile" button to refresh the list.
console "Hello, World"
release - works fine (Hello, World) appears in Platform Assistant
terminal window
debug - same as release
empty 2D Form
release - Runtime error 231 at 000169AD
debug - seems to run (bouncing Spartan Helmet icon in dock) but
the form never appears
empty 3D Form
release - Platform Assistant terminal window shows "invalid pixel
format" and "invalid context" messages but form appears and menu bar
has "Project1" in it
debug - same as release
These errors mean that you run your application under MacOS that was installed on Virtual Machine. Installation of MacOS on VM conflicts with license, and therefore Embarcadero does not plan to support the VM environment.
Just click paserver.command instead of just paserver..
It works!
U can even add -password=(your password) , at the end of the last line inside paserver.command (after the last " . then it starts without asking for password.
Make sure there is a space after the path to the paserver in your paserver. Command before the -password part. For instance, my password is firemonkey and the line is as follows:
"/Users/firemonkey/Applications/Embarcadero/PAServer/paserver" -password=firemonkey
Then, make sure you run the paserver from the paserver.command file.
Check the new "Redist" folder in the RAD Studio installation path. Your application needs some files from it.
Running the paserver.command helped with the first problem but most of it is the I think a missing file.
Checking deploy, the file libcgunwind.1.0.dylib in ($BDS)\Redist\osx32 folder was greyed out so I copied the file from the PAServer on the mac and refreshed now the app runs fine stand alone :)
Just copy and run the application from the PAServer folder. Remember that to install and run PAServer you should do this http://docwiki.embarcadero.com/RADStudio/XE2/en/Installing_and_Running_the_Platform_Assistant_on_the_Target_Platform#Mac%3a_Installing_and_Running_the_Platform_Assistant_.28paserver.29_on_a_Mac

Resources