Powershell脚本在计划任务中处理产生的Excel文件失败的解决方法 2021-02-04 Website News 暂无评论 7351 次阅读 PowerShell脚本在PowerShell ISE中执行一切都正常,但是将脚本加入到Windows的计划任务中就出现无法处理Excel文件的问题,最后在网上找到一个方法,在system32目录下创建Destop目录就可以解决相关问题,遇到这样问题的朋友可以试试。 ```csharp (32位系统&64位系统) C:\Windows\System32\config\systemprofile\Desktop (64位系统) C:\Windows\SysWOW64\config\systemprofile\Desktop ``` [原文:](http://troyvssharepoint.blogspot.com/2012/07/stumbled-upon-interesting-one-today.html "原文:") Interactive Excel permissions Stumbled upon an interesting one today, where I had a legacy application that needs to open excel to generate some excel spreadsheets. But when this happened i got the usual error: System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file 'c:\temp\test.xls'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook. For this example the application is running under an application pool account called ExcelAppPoolAct Obviously the first step is to grant the correct permissions in component services. To do this: 1. Navigation to Adminstrative Tools->Component Services->MyComputer->DCOM->Microsoft Excel Application 2. Right Click on Microsoft Excel Application and select Properties 3. Click the Security tab 4. Change Launch and Activation Permissions to Customize 5. Click Edit 6. Add ExcelAppPoolAct 7. Check Local Launch and Local Activation Next we need to configure the systemprofile directory. You need to create a Desktop folder in one of the following paths, dependant on which version (32-bit or 64-bit) of Microsoft Office you are running. |Office Version|Folder| | ------------ | ------------ | |32-bit|C:\Windows\System32\config\ systemprofile\| |64-bit|C:\Windows\SysWOW64\config\systemprofile\| The next step is to configure the appropriate permissions to thefolders for the Application Pool account, ExcelAppPoolAct. Again the folder is dependent on your version (32-bit or 64-bit) of Microsoft Office. |Folder | Required Permission | | ------------ | ------------ | |C:\Windows\System32\config\systemprofile\Desktop |Read & Execute, List folder contents, Read | |C:\Windows\System32\config\systemprofile\AppData\Roaming\Microsoft |Modify, Read & Execute, List Folder Content, Read, Write | |C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft |Modify, Read & Execute, List Folder Content, Read, Write | |Folder |Required Permission | | ------------ | ------------ | |C:\Windows\SysWOW64\config\systemprofile\Desktop |Read & Execute, List folder contents, Read | |C:\Windows\SysWOW64\config\systemprofile\AppData\Roaming\Microsoft |Modify, Read & Execute, List Folder Content, Read, Write | |C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft |Modify, Read & Execute, List Folder Content, Read, Write | I've got a nice piece of powershell that does all of this during installation. 标签: PowerShell, excel, 计划任务 本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭