简体   繁体   English

有没有办法以管理员权限运行UWP应用程序?

[英]Is there Any way to Run UWP Application with Administrator Rights?

I have created an application using Windows Universal Platform Tools in Visual Studio. 我在Visual Studio中使用Windows通用平台工具创建了一个应用程序。 In this application I have to rename files selected by user, but I am getting Permission denied exception while debugging. 在这个应用程序中,我必须重命名用户选择的文件,但我在调试时收到Permission denied异常。

After packing it & installing on machine I am not getting option to run it as administrator. 打包并安装到机器上后,我无法选择以管理员身份运行它。

I have searched as much as I could but there doesn't seem to be any solution available on internet or I missed any query that could possibly solve this issue. 我尽可能多地搜索,但似乎没有任何解决方案可用于互联网或我错过任何可能解决此问题的查询。

I can't see any type of permissions related to Storage as well in manifest file :( 我在清单文件中看不到与存储相关的任何类型的权限:(

Code: (Edit: This is now working Code) 代码:(编辑:这是现在正在运行的代码)

            FolderPicker folderPicker = new FolderPicker();
        folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
        folderPicker.FileTypeFilter.Add("*");
        folderPicker.ViewMode = PickerViewMode.List;
        StorageFolder folderPicked = await folderPicker.PickSingleFolderAsync();

        if (folderPicked != null)
        {

            t_output.Text = folderPicked.Path.ToString();
            StringBuilder outputText = new StringBuilder();
            IReadOnlyList<StorageFile> fileList =
            await folderPicked.GetFilesAsync();
            int i=0;
             foreach (StorageFile file in fileList)
            {
                outputText.Append(file.Name + "\n");
                StorageFile fs = await folderPicked.GetFileAsync(file.Name);
                await fs.RenameAsync("tanitani0" + i + ".jpg");
                i++;

            }

I am using t_output.Text TextBox to verify each & everything is going as I expect, if I don't use File.Copy then every file is being listed from the selected folder just like I want. 我正在使用t_output.Text TextBox来验证每个和所有内容正如我所期望的那样,如果我不使用File.Copy,那么就像我想要的那样从所选文件夹中列出每个文件。 But getting Permission Denied issue with File.Copy :( if I directly Use File.Move I am getting File Not Found Exception then. 但是使用File.Copy得到Permission Denied问题:(如果我直接使用File.Move我得到File Not Found Exception然后。

What can be the way to solve this type of problem? 有什么办法可以解决这类问题?

There are a few filesystem limitations in UWP, and you just ran into one of them. UWP中存在一些文件系统限制,您刚刚碰到其中一个。 By getting access to the folder, you have to continue using that StorageFolder instance to make modifications. 通过访问该文件夹,您必须继续使用该StorageFolder实例进行修改。

To create a copy of the file, use folderPicked.CreateFileAsync(path) and use that StorageFile returned from that method to copy the stream data. 要创建文件的副本,请使用folderPicked.CreateFileAsync(path)并使用从该方法返回的StorageFile来复制流数据。 But since you have access to the individual files inside the directory, you can take advantage of the StorageFile interface and perform your operations asynchronously. 但由于您可以访问目录中的各个文件,因此可以利用StorageFile接口并异步执行操作。 Here's a list of methods permitted: 以下是允许的方法列表:

https://docs.microsoft.com/en-us/uwp/api/windows.storage.storagefile https://docs.microsoft.com/en-us/uwp/api/windows.storage.storagefile

Using File.Copy(...) will only work in your isolated storage / application data directories. 使用File.Copy(...)只能在隔离的存储/应用程序数据目录中使用。 Just because you have folderPicked does not mean File.Copy(...) has access. 仅仅因为你有folderPicked并不意味着File.Copy(...)有权访问。

Code sample: 代码示例:

foreach (StorageFile file in fileList)
{
    outputText.Append(file.Name + "\n");
    int i = 0;

    await file.CopyAsync(pickedFolder, "tani" + i + ".jpg");
    i++;
}

On a side note, your int i value will always be zero. 另外,您的int i值始终为零。 Just make sure it's outside the loop to continue incrementing. 只需确保它在循环外继续递增。

int i = 0;

foreach (StorageFile file in fileList)
{
    outputText.Append(file.Name + "\n");        
    await file.CopyAsync(pickedFolder, "tani" + i + ".jpg");
    i++;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在没有管理员权限的情况下运行WinForms应用程序? - Run WinForms application without administrator rights? 有什么办法以系统用户/管理员身份运行可执行文件? - Any way to run an executable as a system user / administrator? 在运行时授予管理员权限 - Granting Administrator Rights During Run-Time 当应用程序以管理员身份运行时,是否可以在打开第二个表单时要求用户权限? - Is it possible to require user rights when opening second form ,when application run as administrator? WPF 应用程序 - 在运行时请求管理员权限 - WPF application - ask for administrator rights in runtime 我的应用程序将以管理员身份运行吗? - Will my application run as administrator? Visual Studio 安装项目:在没有管理员权限的情况下运行 msi 安装程序 - Visual Studio Setup Project: Run the msi installer without administrator rights 使用app.manifest [ExecutionLevel]以管理员权限运行Visual Studio - Run Visual Studio with Administrator Rights using app.manifest [ExecutionLevel] 如何使用具有管理员权限的MSBUILD构建VSNET 2008应用程序 - how to build a VSNET 2008 application using MSBUILD with Administrator rights 在运行时请求管理员权限 - Request Administrator Rights at Runtime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM