Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 写入Azure localStorage错误“;访问路径';C:\Resources\directory\..';被拒绝_C#_Powershell_Azure Storage_Azure Web Roles - Fatal编程技术网

C# 写入Azure localStorage错误“;访问路径';C:\Resources\directory\..';被拒绝

C# 写入Azure localStorage错误“;访问路径';C:\Resources\directory\..';被拒绝,c#,powershell,azure-storage,azure-web-roles,C#,Powershell,Azure Storage,Azure Web Roles,当我尝试将文件从azure blob下载到azure localstorage时,它会显示一条消息,告诉我“对路径“C:\Resources\directory…”的访问被拒绝作为一种解决方法,我添加了一个带有powershell命令的statup任务来启用权限。但在这之后,我的网络角色被发现需要更多的时间来开始并最终开始。但我在尝试写入时仍收到拒绝访问错误消息感谢您提出的解决此问题的建议 我还尝试将powershell脚本的编码更改为Unicode(不带签名的UTF-8)-代码页65001。如

当我尝试将文件从azure blob下载到azure localstorage时,它会显示一条消息,告诉我“对路径“C:\Resources\directory…”的访问被拒绝作为一种解决方法,我添加了一个带有powershell命令的statup任务来启用权限。但在这之后,我的网络角色被发现需要更多的时间来开始并最终开始。但我在尝试写入时仍收到拒绝访问错误消息
感谢您提出的解决此问题的建议

我还尝试将powershell脚本的编码更改为Unicode(不带签名的UTF-8)-代码页65001。如前所述。但是运气不好,请帮忙

这是我的StartUp.Cmd文件

    @echo off


REM   Attempt to set the execution policy by using PowerShell version 2.0 syntax.
PowerShell -Version 2.0 -ExecutionPolicy Unrestricted .\fixfolderaccess.ps1 >> "%TEMP%\StartupLog.txt" 2>&1

IF %ERRORLEVEL% EQU -393216 (
   REM   PowerShell version 2.0 isn't available. Set the execution policy by using the PowerShell version 1.0 calling method.

   PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
   PowerShell .\fixfolderaccess.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
)
这是我的powershell脚本--fixpermission.ps1

Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime

while (!$?)
{
    echo "Failed, retrying after five seconds..."
    sleep 5

    Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime
}

echo "Added WA snapin."

$localresource = Get-LocalResource "Resources"
$folder = $localresource.RootPath

$acl = Get-Acl $folder

$rule1 = New-Object System.Security.AccessControl.FileSystemAccessRule(
  "Administrators", "FullControl", "ContainerInherit, ObjectInherit", 
  "None", "Allow")
$rule2 = New-Object System.Security.AccessControl.FileSystemAccessRule(
  "Everyone", "FullControl", "ContainerInherit, ObjectInherit", 
  "None", "Allow")

$acl.AddAccessRule($rule1)
$acl.AddAccessRule($rule2)

Set-Acl $folder $acl

echo "Done changing ACLs."

my.cmd文件和fixpermission.ps1文件都位于web项目目录中,并设置属性copy always=true

如果在本地计算机上手动运行startup.cmd,则会出现以下错误

.\fixfolderaccess.ps1 : The term '.\fixfolderaccess.ps1' is not recognized as t
he name of a cmdlet, function, script file, or operable program. Check the spel
ling of the name, or if a path was included, verify that the path is correct an
d try again.
At line:1 char:22
+ .\fixfolderaccess.ps1 <<<< 
    + CategoryInfo          : ObjectNotFound: (.\fixfolderaccess.ps1:String) [ 
   ], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
\fixfolderaccess.ps1:术语'.\fixfolderaccess.ps1'不能识别为t
cmdlet、函数、脚本文件或可操作程序的名称。检查spel
如果包含路径,请验证路径是否正确
我会再试一次。
第1行字符:22

+.\fixfolderaccess.ps1请尝试
powershell-执行策略旁路。\fixpermission.ps1
。您是否将包含
fixpermission.ps1
的文件夹定义为任务的工作目录?手动运行
startup.cmd
时的结果是什么?您为任务配置了哪个帐户?任务是否正在运行?任务历史记录和事件日志显示了什么?my.cmd文件和fixpermission.ps1文件都位于web项目目录中,并设置属性copy always=true。如果手动运行startup.cmd,则会出现错误“TheTerm.”\fixfolderaccess.ps1“未被识别为cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的大小,或者如果包含路径,请验证路径是否正确,然后重试。”
\fixfolderaccess.ps1
表示当前目录(
)中的文件
fixfolderaccess.ps1
)。错误消息表示当前目录中没有此类文件。尝试使用完整路径运行脚本(或者作为
%~dp0fixfolderaccess.ps1
,如果它与批处理脚本位于同一文件夹中)。当我远程访问我的webrole时,我可以在bin文件夹中看到我的.cmd文件和.ps1文件。因此,这次我右键单击脚本文件并以管理员身份执行脚本,我得到了错误(错误消息与我的帖子一起粘贴)
C a n n o t   s t a r t   W i n d o w s   P o w e r S h e l l   v e r s i o n   2 . 0   b e c a u s e   i t   i s   n o t   c o r r e c t l y   i n s t a l l e d . 

 Add-PSSnapin : Cannot load Windows PowerShell snap-in Microsoft.WindowsAzure.Se
rviceRuntime because of the following error: The Windows PowerShell snap-in mod
ule F:\plugins\RemoteAccess\Microsoft.WindowsAzure.ServiceRuntime.Commands.dll 
does not have required Windows PowerShell snap-in strong name Microsoft.Windows
Azure.ServiceRuntime.Commands, Version=1.0.0.0, Culture=neutral, PublicKeyToken
=31bf3856ad364e35.
At F:\approot\bin\fixfolderaccess.ps1:1 char:13
+ Add-PSSnapin  <<<< Microsoft.WindowsAzure.ServiceRuntime
Failed, retrying after five seconds...
out-lineoutput : The OS handle's position is not what FileStream expected. Do n
ot use a handle simultaneously in one FileStream and in Win32 code or another F
ileStream. This may cause data loss.