How to get the list of scheduled tasks using c#? - c#

I need to get the list of scheduled tasks that are present in the local computer.
How can I achieve that using c# for Windows XP?

1 alternative...:
1) you can read from the folder where task are saved ( Ive just tested it - win7)
c:\Windows\System32\Tasks\
this is simple xml file like this :
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2012-04-05T13:28:54.2106589</Date>
<Author>DAVIDDOM\RoyiN</Author>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2012-04-05T13:28:43.2046589</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<RunLevel>LeastPrivilege</RunLevel>
<UserId>DAVIDDOM\RoyiN</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Windows\system32\charmap.exe</Command>
</Exec>
</Actions>
</Task>

Related

Why is heat causing my Windows Service to not be added to windows registry/windows services

Is there any reason that Heat would be causing my windows service to not be added to the registry? I am going through two different commits in my branch and the only difference between the two commits is that the latest one has heat to include dlls from the project that Wix is referencing.
I've looked through the logs using msiexec and /l*v but there isn't anything about the service in there for some reason.
Sorry about the xxx in some of the context of the code as I must remove some of the keywords for security purposes. This is my first time dealing with heat so I am unfamiliar with it and after googling questions about heat I have come to realize that the docs aren't very helpful either.
Product
<?xml version="1.0" encoding="UTF-8"?>
<!-- The name of the product -->
<?define Name = "xxx xxx Agent" ?>
<!-- The manufacturer, for setup package publisher and folder info -->
<?define Manufacturer = "xxx" ?>
<!-- The version number of this setup package-->
<?define Version = "1.0.0" ?>
<!-- UpgradeCode must be unique and not changed once the first version of the program is installed. -->
<?define UpgradeCode = "{145ED92C-BA1B-4257-8791-2337A012EEE7}" ?>
<?if $(var.Platform) = x64?>
<?define bitness = "(64 bit)"?>
<?define Win64 = "yes"?>
<?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
<?else ?>
<?define bitness = "(32 bit)"?>
<?define Win64 = "no"?>
<?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="$(var.Name) $(var.bitness)" Manufacturer="$(var.Manufacturer)" UpgradeCode="$(var.UpgradeCode)" Version="$(var.Version)" Language="1033">
<Package InstallerVersion="300" Compressed="yes"/>
<Media Id="1" Cabinet="xxx.xxx.Agent.WindowsService.cab" EmbedCab="yes" />
<MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.PlatformProgramFilesFolder)">
<Directory Id="ROOTDIRECTORY" Name="$(var.Manufacturer)">
<Directory Id="INSTALLFOLDER" Name="$(var.Name)" />
</Directory>
</Directory>
</Directory>
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="$(var.xxx.xxx.Agent.WindowsService.TargetFileName)" Win64="$(var.Win64)" Guid="FD94EF3C-4A0B-4102-AF1E-2A489B4DB7DF">
<RemoveFile Id="ALLFILES" Name="*.*" On="both" />
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="xxx.xxx.Agent.WindowsService"
Account="LocalSystem"
DisplayName="$(var.Name)"
Description="Deployment agent for xxx xxx"
Start="auto"
Interactive="yes"
Vital="yes"
ErrorControl="critical"
Arguments="/start xxx.xxx.Agent.WindowsService"/>
<ServiceControl Id="ServiceUninstaller"
Name="xxx.xxx.Agent.WindowsService"
Stop="uninstall"
Remove="uninstall"
Wait="yes" />-
</Component>
</DirectoryRef>
<Feature Id="MainApplication" Title="Main Application" Level="1">
<ComponentRef Id="$(var.xxx.xxx.Agent.WindowsService.TargetFileName)" />
<ComponentGroupRef Id="HeatGenerated"/>
</Feature>
</Product>
</Wix>
Filter
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes" />
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, '.pdb')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, '.xml')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, '.dll.config')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, '.exe')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, 'app.config')]" use="#Id" />
<xsl:key name="service-search" match="wix:Component[wix:File/#Source = '$(var.xxx.xxx.xxx.WindowsService.TargetDir)\xxx.xxx.xxx.WindowsService.exe']" use="#Id" />
<xsl:template match="wix:Component[key('service-search', #Id)]" />
<xsl:template match="wix:ComponentRef[key('service-search', #Id)]" />
</xsl:stylesheet>
From the WiX documentation on ServiceInstall, I believe you require a File element:
The service executable installed will point to the KeyPath for the Component. Therefore, you must ensure that the correct executable is either the first child File element under this Component or explicitly mark the appropriate File element as KeyPath='yes'.
So I think you would simply need to add under the service Component:
<File Id="WindowsServiceExe", KeyPath="yes" Source="$(var.xxx.xxx.xxx.WindowsService.TargetDir)\xxx.xxx.xxx.WindowsService.exe" />
Also looking at your transform, I suggest you create separate key names for the "filters" instead of re-using service-search.

C# Web Reference - ArrayOfString not serialising

I am using Web References in C# to interface with Magento, which uses a SOAP API. The WSDL contains lots of definitions as you can imagine, but I'm having a problem with this particular one:
<complexType name="ArrayOfString">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
</restriction>
</complexContent>
</complexType>
Any propertes of a method that are an ArrayOfString are being brought back to my code as string[], which is fine, but when serialising it back to Magento it's serialising it as below
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:Magento" xmlns:types="urn:Magento/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:catalogProductCreate>
<sessionId xsi:type="xsd:string">xxxxxxxxxxxxxxxxxxxxxxx</sessionId>
<type xsi:type="xsd:string">simple</type>
<set xsi:type="xsd:string">63</set>
<sku xsi:type="xsd:string">CHRISTEST</sku>
<productData href="#id1" />
</tns:catalogProductCreate>
<tns:catalogProductCreateEntity id="id1" xsi:type="tns:catalogProductCreateEntity">
<categories href="#id2" />
<websites href="#id3" />
<name xsi:type="xsd:string">Chris Test 8</name>
<description xsi:type="xsd:string">fsd</description>
<short_description xsi:type="xsd:string">Chris Test 8</short_description>
<weight xsi:type="xsd:string">0.0000</weight>
<status xsi:type="xsd:string">1</status>
<visibility xsi:type="xsd:string">1</visibility>
<category_ids href="#id4" />
<website_ids href="#id5" />
<price xsi:type="xsd:string">0.00000</price>
<tax_class_id xsi:type="xsd:string">4</tax_class_id>
<tier_price href="#id6" />
</tns:catalogProductCreateEntity>
<soapenc:Array id="id2" soapenc:arrayType="xsd:string[0]" />
<soapenc:Array id="id3" soapenc:arrayType="xsd:string[0]" />
<soapenc:Array id="id4" soapenc:arrayType="xsd:string[1]">
<Item>35</Item>
</soapenc:Array>
<soapenc:Array id="id5" soapenc:arrayType="xsd:string[1]">
<Item>1</Item>
</soapenc:Array>
<soapenc:Array id="id6" soapenc:arrayType="tns:catalogProductTierPriceEntity[0]" />
</soap:Body>
</soap:Envelope>
And this is resulting in the arrays being ignored. I believe the reason the ArrayOfString entity isn't being added to my service model is because it has a 'restriction', but I'm going to need this to get the data back to Magento. Any ideas guys?

Generating class file from xsd file using vs command prompt issue

I have this following xsd file. I try to generate class using vs command line like:
command line word = xsd test.xsd /c
"Data at the root level is invalid. Line2, position1.". I am not sure why I having this error. Please advise.
<?xml version="1.0" ?>
- <ResultSet>
- <DataRow>
<Mailing>CCACCL0030</Mailing>
<MailingDesc>'other response' chelsea CA</MailingDesc>
<Notes />
<Direction>O</Direction>
<HistoryOnly>N</HistoryOnly>
</DataRow>
- <DataRow>
<Mailing>VOUCHER20</Mailing>
<MailingDesc>£20 T&M Voucher</MailingDesc>
<Notes />
<Direction>O</Direction>
<HistoryOnly>N</HistoryOnly>
</DataRow>
-
</ResultSet>
To generate code:
Edit the example file so that the & character is encoded. Specifically, swap it for &
Rename the file to test.xml
Run xsd.exe test.xml to generate a schema e.g. test.xsd
Run xsd.exe /c test.xsd to generate classes from the schema
EDIT: This worked fine for me. Here's the contents of my test.xml:
<?xml version="1.0" ?>
<ResultSet>
<DataRow>
<Mailing>CCACCL0030</Mailing>
<MailingDesc>'other response' chelsea CA</MailingDesc>
<Notes />
<Direction>O</Direction>
<HistoryOnly>N</HistoryOnly>
</DataRow>
<DataRow>
<Mailing>VOUCHER20</Mailing>
<MailingDesc>£20 T&M Voucher</MailingDesc>
<Notes />
<Direction>O</Direction>
<HistoryOnly>N</HistoryOnly>
</DataRow>
</ResultSet>

Product LaunchCondition in WiX if no RegistryValue or RegistryValue is below 1.3.44

(I need to get this to work for the Product / .msi directly, not by using Bundle / Burn.)
(I am using WiX 3.6.)
Fragment that puts a registry value into a variable
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<?include $(sys.CURRENTDIR)Deployment\Data\Statics.wxi ?>
<Fragment>
<util:RegistrySearch Root="HKCU" Key="$(var.Line.Reg.Path)" Value="Version" Variable="AppAlreadyInstalled" />
</Fragment>
</Wix>
Main product with non-working condition
<Product Name="$(var.App.Title)" Manufacturer="!(loc.Company)" Language="!(loc.Lang)" Id="*" Version="$(var.VersionNumber)" UpgradeCode="$(var.App.UpgradeCode)">
<Package Id="*" InstallerVersion="300" Compressed="yes" InstallScope="$(var.App.Elevation)" InstallPrivileges="limited" />
<DirectoryRef Id="TARGETDIR" />
<MajorUpgrade Schedule="afterInstallValidate" DowngradeErrorMessage="!(loc.Msi.NewerVersionInstalled)" />
<Property Id='DiskPrompt' Value="$(var.App.Title) Installation Media" />
<Media Id="1" Cabinet="Media.cab" EmbedCab="yes" DiskPrompt="#1" />
<Icon Id="AppIcon" SourceFile="$(var.Icon.Path)" />
<Condition Message="Newer version already installed.">
<![CDATA[Installed OR AppAlreadyInstalled]]>
</Condition>
<Feature Id="ProductFeature" Level="1">
...
</Feature>
</Product>
I believe AppAlreadyInstalled is never set at the moment because it is in a fragment in a different file.
Then I actually want the installation to proceed if the registry value is NOT found at all / does not exist.
But if it does it exist, I would like the installation to proceed only if the registry value is below a certain value e.g. proceed with installation only if AppAlreadyInstalled < 1.3.44; this sounds hard to achieve because the registry value is stored as a string with two full-stops / periods.
Note the registry check is not of the application to-be-installed, which is already taken care of by DowngradeErrorMessage.
WixUtilExtension:RegistrySearch is only for bundles. You need a plain RegistrySearch in the WiX namespace. You can use RegistrySearchRef to pull in a RegistrySearch from a separate fragment.
However, you're right that a version comparison is problematic: MSI does ordinal string comparisons so 1.2 > 1.10. If the install directory is in the registry, you might be better off using a RegistrySearch combined with a DirectorySearch and a FileSearch. FileSearch can search by version using the MinVersion attribute so if there's a file with a version you can use to detect the product, it'll be more reliable than string comparisons.

How to setup custom api for Magento with SOAP V2?

I am on Magento 1.4.1.1 and I am trying to setup a custom function in the API using SOAP v2. I have it working for SOAP v1 but I need v2 so that C# can use it. For v2 the function shows up in the WSDL but alwasy returns this error: Procedure 'testFoo' not present.
Here are my files:
/app/etc/modules/ABT_Test.xml
<?xml version="1.0"?>
<config>
<modules>
<ABT_Test>
<active>true</active>
<codePool>local</codePool>
</ABT_Test>
</modules>
</config>
/app/code/local/ABT/Test/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<ABT_Test>
<active>true</active>
<codePool>local</codePool>
<version>1.0</version>
</ABT_Test>
</modules>
<global>
<models>
<test>
<class>ABT_Test_Model</class>
</test>
</models>
</global>
</config>
/app/code/local/ABT/Test/etc/api.xml
<?xml version="1.0"?>
<config>
<api>
<resources>
<test>
<model>test/api</model>
<title>ABT Test Api</title>
<methods>
<foo translate="title" module="test">
<title>Foo Test</title>
<method>foo</method>
<acl>test/foo</acl>
</foo>
</methods>
</test>
</resources>
<v2>
<resources_function_prefix>
<test>test</test>
</resources_function_prefix>
</v2>
</api>
</config>
/app/code/local/ABT/Test/etc/wsdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
</schema>
</types>
<message name="testFooRequest">
<part name="sessionId" type="xsd:string" />
</message>
<message name="testFooResponse">
<part name="result" type="typens:boolean" />
</message>
<portType name="{{var wsdl.handler}}PortType">
<operation name="testFoo">
<documentation>Test Foo</documentation>
<input message="typens:testFooRequest" />
<output message="typens:testFooResponse" />
</operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="testFoo">
<soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
<input>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
</definitions>
/app/code/local/ABT/Test/Model/API.php
<?php
class ABT_Test_Model_Api extends Mage_Api_Model_Resource_Abstract
{
public function foo()
{
return true;
}
}
?>
/app/code/local/ABT/Test/Model/API/V2.php
<?php
class ABT_Test_Model_Api_V2 extends ABT_Test_Model_Api
{
}
?>
And here is the code I use to test the API:
<?php
$mageUser = '########';
$mageApiKey = '########';
//SOAP V1
echo "SOAP V1 <br />";
$mageUrl = 'http://www.########.com/api/soap/?wsdl';
$soap = new SoapClient($mageUrl, array('cache_wsdl' => 0));
try {
$sessionID = $soap->login($mageUser, $mageApiKey);
var_dump($soap->call($sessionID, 'test.foo', array()));
} catch (Exception $e) {
echo 'Exception: ' . $e->getMessage() . '<br />';
}
//SOAP V2
echo "SOAP V2 <br />";
$mageUrl2 = 'http://www.########.com/api/v2_soap/?wsdl';
$soap2 = new SoapClient($mageUrl2, array('cache_wsdl' => 0));
try {
$sessionID2 = $soap2->login($mageUser, $mageApiKey);
var_dump($soap2->testFoo($sessionID2));
} catch (Exception $e) {
echo 'Exception: ' . $e->getMessage() . '<br />';
}
?>
I obscured the username, password and url. The function shows up in the v2 WSDL and the php code recognizes that it is in the WSDL but I still get the error: Procedure 'testFoo' not present.
So what am I missing?
EDIT:
I did what Zyava suggested and it got my example working. I then copied the folder and did an exact (case sensitive) find and replace to use a meaningful Module name and function name. I was careful to pick names that I didn't think would be reserve words. On the new module the call on the v1 WSDL works fine but the v2 gives the same "Procedure 'xxx' not present" message. I then went and renamed the method on the test from 'Foo' to 'Fooz' and I got this message: "Resource path is not callable." I find it interesting that I get a different message. This leads me to believe there is some cache/configuration/something that is causing the problem. Any ideas?
At first I should warn you that Magento doesn't support SOAP v2 format for now, api/v2_soap/?wsdl is just second version of soap api.
1.
<models>
<test>
<class>ABT_Test_Model</class>
</test>
</models>
Because you are writing module which isn't core, you should write <abt_test>
2.<model>test/api</model>. Should be <model>abt_test/api</model> in your case.
3.<acl>test/foo</acl>.
Does this acl section exist in your adminhtml.xml?
bygrace,
your code is so perfect!
add
....
<resources_alias>
<test>test</test>
</resources_alias>
.....
same level with
<resources> and <v2>
on Api.xml
and it'll be working good.
I has having the same issue and i tried clearing the tmp file as i had hosted it using xampp it didnt work i was getting Procedure ххх not present exception, I had to disable the cache management in the admin page of the server.
How to disable Cache in Admin page
In the admin page under the system there is a section called cache management disable everything during the development phase or else any change you do wont be reflected in the wsdl.

Categories

Resources