将Windows环境变量与xml文件一起使用 [英] Use Windows environment variables with xml file
本文介绍了将Windows环境变量与xml文件一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在xml文件中使用像%username%这样的环境变量?我需要从.xml文件创建一个计划任务,但我需要将当前登录的用户放入.xml文件。
我将不胜感激任何建议。
问候。
<?xml version =" 1.0"编码= QUOT; UTF-16"?>
< Task version =" 1.2"的xmlns = QUOT; HTTP://schemas.microsoft.com/windows/2004/02/mit/task">
< RegistrationInfo>
< Date> 2015-02-06T07:38:03< / Date>
< Author> NEEDLOGGEDUSERHERE< / Author>
< / RegistrationInfo>
<触发器>
< CalendarTrigger>
< StartBoundary> 2015-02-06T07:45:00< / StartBoundary>
<已启用> true< /已启用>
< ScheduleByWeek>
< DaysOfWeek>
< Friday />
< / DaysOfWeek>
< WeeksInterval> 1< / WeeksInterval>
< / ScheduleByWeek>
< / CalendarTrigger>
< CalendarTrigger>
< StartBoundary> 2015-02-06T19:30:00< / StartBoundary>
<已启用> true< /已启用>
< ScheduleByWeek>
< DaysOfWeek>
< Friday />
< / DaysOfWeek>
< WeeksInterval> 1< / WeeksInterval>
< / ScheduleByWeek>
< / CalendarTrigger>
< CalendarTrigger>
< StartBoundary> 2015-02-06T02:00:00< / StartBoundary>
<已启用> true< /已启用>
< ScheduleByWeek>
< DaysOfWeek>
< Friday />
< / DaysOfWeek>
< WeeksInterval> 1< / WeeksInterval>
< / ScheduleByWeek>
< / CalendarTrigger>
< /触发器>
< Principals>
< Principal id =" Author">
< UserId> NEEDLOGGEDUSERHER< / UserId>
< LogonType> InteractiveToken< / LogonType>
< RunLevel> LeastPrivilege< / RunLevel>
< / Principal>
< / Principals>
<设置>
< MultipleInstancesPolicy> IgnoreNew< / MultipleInstancesPolicy>
< DisallowStartIfOnBatteries> true< / DisallowStartIfOnBatteries>
< StopIfGoingOnBatteries> true< / StopIfGoingOnBatteries>
< AllowHardTerminate> true< / AllowHardTerminate>
< StartWhenAvailable> false< / StartWhenAvailable>
< RunOnlyIfNetworkAvailable> false< / RunOnlyIfNetworkAvailable>
< IdleSettings>
< StopOnIdleEnd> true< / StopOnIdleEnd>
< RestartOnIdle> false< / RestartOnIdle>
< / IdleSettings>
< AllowStartOnDemand> true< / AllowStartOnDemand>
<已启用> true< /已启用>
<隐藏> false< /隐藏>
< RunOnlyIfIdle> false< / RunOnlyIfIdle>
< WakeToRun> false< / WakeToRun>
< ExecutionTimeLimit> P3D< / ExecutionTimeLimit>
<优先级> 7< /优先级>
< /设置>
< Actions Context =" Author">
< Exec>
< Command> \\ apptorun\app.exe< / Command>
< / Exec>
< / Actions>
< /任务>
解决方案
Carlos,希望这个powershell脚本有效..
< blockquote> xml = New-Object XML
path =" c:\ temp\input.xml"
Hi,
Is there a way to use an environment variable like %username%, into a xml file? I need to create a scheduled task from .xml file but I need to get the current logged user into the .xml file.
I'll appreciate any suggestion.
Regards.
<?xml version="1.0" encoding="UTF-16"?> <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2015-02-06T07:38:03</Date> <Author>NEEDLOGGEDUSERHERE</Author> </RegistrationInfo> <Triggers> <CalendarTrigger> <StartBoundary>2015-02-06T07:45:00</StartBoundary> <Enabled>true</Enabled> <ScheduleByWeek> <DaysOfWeek> <Friday /> </DaysOfWeek> <WeeksInterval>1</WeeksInterval> </ScheduleByWeek> </CalendarTrigger> <CalendarTrigger> <StartBoundary>2015-02-06T19:30:00</StartBoundary> <Enabled>true</Enabled> <ScheduleByWeek> <DaysOfWeek> <Friday /> </DaysOfWeek> <WeeksInterval>1</WeeksInterval> </ScheduleByWeek> </CalendarTrigger> <CalendarTrigger> <StartBoundary>2015-02-06T02:00:00</StartBoundary> <Enabled>true</Enabled> <ScheduleByWeek> <DaysOfWeek> <Friday /> </DaysOfWeek> <WeeksInterval>1</WeeksInterval> </ScheduleByWeek> </CalendarTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId>NEEDLOGGEDUSERHERE</UserId> <LogonType>InteractiveToken</LogonType> <RunLevel>LeastPrivilege</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> <AllowHardTerminate>true</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <IdleSettings> <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>\\apptorun\app.exe</Command> </Exec> </Actions> </Task>
解决方案
Carlos , Hope this powershell script works..
xml = New-Object XML
path = "c:\temp\input.xml"
这篇关于将Windows环境变量与xml文件一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文