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

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

Related

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

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.

Gradle ExecTask and Windows start

This question requires an understanding of both the Window's start command's behavior and a custom gradle ExecTask's handling of it.
Question
Why does start, with an application as a parameter, wait for the application to exit, only when being executed within a gradle ExecTask?
Explanation
From the command line, this works as expected (starts the application and returns, without waiting for the application to exit):
cmd /c myBuildEnvironment.cmd && start "some title for start" devenv.exe my.sln
Pretty simple, it calls a windows batch script to setup the environment and then launches my.sln in Visual Studio. Works just fine, not waiting for Visual Studio to be closed. And, this is what my gradle task is meant to achieve.
The same works "somewhat", using the following gradle ExecTask with start:
/**
* I know that the executable + args is replaced by commandLine. They're
* just there for readability.
*/
task openVsSolution(type: Exec, dependsOn: setupVsSln) {
description 'Opens the VS solution, in the appropriate version of Visual Studio.'
executable 'start'
environment = taskEnv
workingDir '../../src/solution'
args = [vsDevEnv, 'my.sln']
commandLine winCmdPrefix + executable + args
}
Gradle happily reports Build Successful, while Visual Studio remains open.
However, I say "somewhat" because start will actually ignore the executable argument and open my.sln with the default application for it, Microsoft Visual Studio Version Selector. So, after some research, I found that start assumes that the first parameter is the window title, then application, and lastly, the application arguments. So, I tried this:
task openVsSolution(type: Exec, dependsOn: setupVsSln) {
executable 'start'
environment = taskEnv
workingDir '../../src/solution'
args = ['some title for start', vsDevEnv, 'my.sln']
commandLine winCmdPrefix + executable + args
}
Everything works, start used the correct version of Visual Studio's devenv.exe, which varies based on the VC PlatformToolset, but...gradle sits in the background waiting for Visual Studio to close.
Why? How can I achieve all of the desired behavior?
Update
This might be an environmental problem. Apparently, on one dev's machine, the original gradle start task does stay open, as well. So, any invocation of start through gradle waits for it to complete, in a certain environment. The plot thickens...
Gradle is waiting for start to return is my guess, see this post - Run a background job from Gradle. Read also the comment after the answer, this is started from Java so if there is equivalent of & (run in background) for windows, it wouldn't work.
You can also try and wrapping it in a bat file, execute what you want in the bat file in the background then return right away so that gradle would be happy.
Hope this helps.

Portable Browser Issues when deploying R Shiny App

I've built a complex Shiny interface that pulls from an internally networked ODBC table and allows a user to interact with the data through their browser. The company is on Windows 7 Enterprise and IT only supports IE 9. Some users have chrome installed in their user folders, some have firefox, some use IE 9. I followed a tutorial from R-Bloggers (here: http://www.r-bloggers.com/deploying-desktop-apps-with-r/) and it runs on my machine using a portable Chrome browser downloaded from PortableApps.com. Great. Unfortunately the interface has not started on ANYONE else's machine that has their own local Chrome browser installed.
Following the tutorial, I use the following vb script:
Rexe = "R-Portable\App\R-Portable\bin\Rscript.exe"
Ropts = "--no-save --no-environ --no-init-file --no-restore --no-Rconsole"
RScriptFile = "runShinyApp.R"
Outfile = "ShinyApp.log"
strCommand = Rexe & " " & Ropts & " " & RScriptFile & " 1> " & Outfile & " 2>&1"
intWindowStyle = 0 ' Hide the window and activate another window.'
bWaitOnReturn = False ' continue running script after launching R '
CreateObject("Wscript.Shell").Run strCommand, intWindowStyle, bWaitOnReturn
This script calls the following code in my R file:
message('library paths:\n', paste('... ', .libPaths(), sep='', collapse='\n'))
chrome.portable = file.path(getwd(),'GoogleChromePortable/App/Chrome-bin/chrome.exe')
launch.browser = function(appUrl, browser.path=chrome.portable) {
message('Browser path: ', browser.path)
shell(sprintf('"%s" --app=%s', browser.path, appUrl))
}
shiny::runApp('shiny', launch.browser=launch.browser)
It works on my computer just fine... I DO have chrome installed locally, but I'm calling the Portable Chrome executable. It worries me that the two are sharing prefs or something, e.g. I notice that a hash from the Preferences file in my installed version, specifically:
"chrome_url_overrides": {
"bookmarks": [ "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno/main.html" ]
},
...matches the same json entry from the Portable Chrome installation:
"chrome_url_overrides": {
"bookmarks": [ "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno/main.html" ]
}
Why do these long random strings match? Am I barking up the wrong tree for wondering about this? I don't know why these strings match if they are two separate installations of Chrome executables, one of which is supposed to run completely independently from anything on the machine.
Here's a set of errors from one machine:
.../Desktop/TestApp3/GoogleChromePortable/App/Chrome-bin/chrome.exe[9100:9408:0716/141934:ERROR:gpu_info_collector_win.cc(103)] Can't retrieve a valid WinSAT assessment.
[9100:9408:0716/141934:ERROR:component_loader.cc(138)] Failed to parse extension manifest.
[9100:1716:0716/141946:ERROR:get_updates_processor.cc(214)] PostClientToServerMessage() failed during GetUpdates
Here's a set of errors from a second machine:
.../Documents/TestApp3/GoogleChromePortable/App/Chrome-bin/chrome.exe
[5220:3384:0714/142128:ERROR:component_loader.cc(138)] Failed to parse extension manifest.
[5220:7600:0714/142130:ERROR:external_registry_loader_win.cc(136)] File C:\Program Files\Coupons.com CouponBar\chrome\Coupons.com.crx for key
Software\Google\Chrome\Extensions\cnpkmcjgpcihgfnkcjapiaabbbplkcmf does not exist or is not readable.
[5220:2120:0714/142140:ERROR:get_updates_processor.cc(214)] PostClientToServerMessage() failed during GetUpdates
[5220:3384:0714/142413:ERROR:CONSOLE(122)] "Could not find value for secondaryUser", source: chrome://resources/js/load_time_data.js (122)
[5220:3384:0714/142413:ERROR:CONSOLE(122)] "[undefined] (secondaryUser) is not a boolean", source: chrome://resources/js/load_time_data.js (122)
[5220:3384:0714/142425:ERROR:CONSOLE(122)] "Could not find value for secondaryUser", source: chrome://resources/js/load_time_data.js (122)
[5220:3384:0714/142425:ERROR:CONSOLE(122)] "[undefined] (secondaryUser) is not a boolean", source: chrome://resources/js/load_time_data.js (122)
[5220:3384:0714/142442:ERROR:navigation_entry_screenshot_manager.cc(167)] Invalid entry with unique id: 12
It seems like Chrome is doing different things on different computers and is not actually acting as a standalone browser... but likely interacting with the browser installed on their respective computers via the registry or some other "under the hood, active" communication. Maybe, since I installed the portable executable on my machine, a bunch of my local extensions or preferences were automatically updated to the portable's preferences, etc. and subsequently this is causing a conflict on every other machine??
Can I shutdown Chrome's extensions or extra functions like the calls to the updater? Is there a better standalone portable browser that functions well with Shiny for this type of "deployment" purpose? Can I fix this or is this a lost cause?? This should be obvious but I'll say it anyway: it is definitely not economically efficient to ask the non-technical types to install R, then RStudio, then confirm their working directory structure, then call the runApp() command via the Script window...
I started with those same articles, but developed the RInno package to solve this exact problem, i.e. when you want to share your desktop Shiny app with non-technical users who can't be expected to mess around with all those details.
To get started:
install.packages("RInno")
require(RInno)
RInno::install_inno()
Then you just need to call two functions to create an installation framework:
create_app(app_name = "myapp", app_dir = "path/to/myapp")
compile_iss()
This will create an installation wizard that runs like any other program, but installs your shiny app on a Windows desktop computer. If you would like to include R for your co-workers who don't have it installed, add include_R = TRUE to create_app:
create_app(app_name = "myapp", app_dir = "path/to/myapp", include_R = TRUE)
It defaults to include shiny, magrittr and jsonlite, so if you are using other packages like ggplot2 or plotly, just add them to the pkgs argument. You can also include GitHub packages to the remotes argument:
create_app(
app_name = "myapp",
app_dir = "path/to/myapp"
pkgs = c("shiny", "jsonlite", "magrittr", "plotly", "ggplot2"),
remotes = c("talgalili/installr", "daattali/shinyjs"))
If you are interested in other features, check out FI Labs - RInno

Active component cant create obj error

I am trying to script for file transferring ,its works fine when am clicking manually the script.But when am trying to run as Scheduling task i receiving an error "Active component cant create obj",i don't know what went wrong in my script?
For your reference i have my script below.
Dim Mysite
Set MySite = CreateObject("CuteFTPPro.TEConnection")
Set fso = CreateObject("Scripting.FileSystemObject")
MySite.Protocol = "FTP"
MySite.Host = "www.domainname.com"
MySite.Login = "xxxxx"
MySite.Password = "xxx"
MySite.UseProxy = "BOTH"
MySite.Connect
MySite.UploadAsync "C:\sampletest\abc.flv"
MySite.RemoteFolder = "/test/abc.flv"
MySite.Disconnect
MySite.Close
FYI my machine is windows 2008 64 bit system
In most cases issue raised by one of the following:
User does not have proper permission to run a scheduler
User does not have proper access to the folders/files listed
Application you are using running under different permission set for logged in user and system account which is used by Task Scheduler.
OS is not recognizing what application version it have to execute 32 or 64 bit when attempt to execute scheduled task.
Take a closer look on those situations, make adjustments and it will work.

What causes ClickOnce URLDownloadToCacheFile failed during installation?

I'm getting the following error when installing my ClickOnce application via firefox. It doesn't happen with IE on the same computer. I swear I've installed it via firefox before. This is a Windows 7 machine.
The following properties have been set:
Property: [AdminUser] = true {boolean}
Property: [ProcessorArchitecture] = Intel {string}
Property: [VersionNT] = 6.1.0 {version}
Running checks for package '.NET Framework 2.0 (x86)', phase BuildList
Running external check with command 'C:\Users\luke\AppData\Local\Temp\VSDEF1A.tmp\DotNetFX\dotnetchk.exe' and parameters ''
Process exited with code 1
Setting value '1 {int}' for property 'DotNetInstalled'
Reading value 'Version' of registry key 'HKLM\Software\Microsoft\Internet Explorer'
Read string value '8.0.7600.16385'
Setting value '8.0.7600.16385 {string}' for property 'IEVersion'
The following properties have been set for package '.NET Framework 2.0 (x86)':
Property: [DotNetInstalled] = 1 {int}
Property: [IEVersion] = 8.0.7600.16385 {string}
Running checks for command 'DotNetFX\instmsia.exe'
Result of running operator 'ValueExists' on property 'VersionNT': true
Result of checks for command 'DotNetFX\instmsia.exe' is 'Bypass'
Running checks for command 'DotNetFX\WindowsInstaller-KB893803-v2-x86.exe'
Result of running operator 'ValueExists' on property 'Version9x': false
Result of running operator 'VersionLessThan' on property 'VersionNT' and value '5.0.3': false
Result of running operator 'VersionGreaterThanOrEqualTo' on property 'VersionMsi' and value '3.0': true
Result of checks for command 'DotNetFX\WindowsInstaller-KB893803-v2-x86.exe' is 'Bypass'
Running checks for command 'DotNetFX\dotnetfx.exe'
Result of running operator 'ValueNotEqualTo' on property 'DotNetInstalled' and value '0': true
Result of checks for command 'DotNetFX\dotnetfx.exe' is 'Bypass'
'.NET Framework 2.0 (x86)' RunCheck result: No Install Needed
Launching Application.
URLDownloadToCacheFile failed with HRESULT '-2146697211'
Error: An error occurred trying to download 'http://croppy.lukehunter.net/download/croppy.application'.
The following is the howto from Microsoft, but this doesn't apply to firefox. There is no redirection happening either.
If a user has set Internet Explorer
Advanced Security option "Warn if
changing between secure and not secure
mode" on the deployment target
computer, and if the setup URL of the
ClickOnce application being installed
is redirected from a non-secure to a
secure site (or vice-versa), the
installation will fail because the
Internet Explorer warning interrupts
it.
Internet Explorer calls either LaunchApplication or ShOpenVerbApplication procedure from dfshim.dll behind the scenes, whereas Firefox plug-in (as well as a standard bootstrapper created by Visual Studio 2008-2010, which could also produce this rare error) uses a different, out of date technique to launch ClickOnce applications. (Note, that LaunchApplication requires at least .NET Framework 2 SP 2.)
To avoid such error one could redirect Internet Explorer to a deployment manifest (.application) and all other browsers to a custom installer (.exe) that would install .NET Framework if necessary and then call ShOpenVerbApplication.
Hmm, after using IE to install, then uninstalling, I was able to install via firefox again. Odd.
The following worked for me:
Within the local distribution package CLICK ONCE a web.config file was generated on line clientCache that was the problem, in which altered as follows for CHROME and IE8 and now run the file:
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
I've had this and it to resolve it was to disable the firewall. I sadly don't know what Firewall settings it was, I just disabled the lot and it ran/installed without issue.
After exhausting firewall options on this issue, I found that my excutable was pointing to the IP Address of the Application Server. When I changed the site deployment and consequently the executable to the FQDN of the server instead of the IP Address, the installer worked first time.
Simple Solution, on cmd execute setup.exe /URL=http://< Production  URL>/
Easy!

Resources