对于那些具有提升权限的人(尤其是在浏览器中),我提出了一个半功能性的解决方案来确定路径。不幸的是,如果您从 dev 切换到 live,您将看到不同的文件夹路径,因此您必须在此处包含它,您还应该通过传入的页面参数或主机网址左右
private string GetProfilePath() {
var fullname = string.Empty;
try
{
// ReSharper disable IdentifierTypo
// ReSharper disable CommentTypo
var profilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
profilePath = Path.GetDirectoryName(profilePath);
profilePath = Path.Combine(profilePath, @"LocalLow\Microsoft\Silverlight\is");
//profilePath = Path.Combine(profilePath, IsoPathStaging + "\\");
var directoryInfo = new DirectoryInfo(profilePath); // C:\Users\<username>\AppData\LocalLow\Microsoft\Silverlight\is --constant
var dirs = directoryInfo.EnumerateDirectories();
// ReSharper disable PossibleMultipleEnumeration
fullname = "1: " + dirs.First().FullName;
dirs = dirs.First().EnumerateDirectories(); // \ir5ffeej.4of --random
fullname = "2: " + dirs.First().FullName;
dirs = dirs.First().EnumerateDirectories(); // \lfab1wva.xmb --random
fullname = "3: " + dirs.First().FullName;
dirs = dirs.First().EnumerateDirectories(); // \1 --constant
fullname = "4: " + dirs.First().FullName;
dirs = dirs.Where(d => d.Name == "s"); // \s --constant
fullname = "5: " + dirs.First().FullName;
var dirs2 = dirs.First().EnumerateDirectories()
.Where(d => d.Name == "sbudlbc2oqx0eo0odi5nzpo2qppp3zmxxxxxxxxxxxxxxxxxxxxxxxxx").ToList(); // \<dev dir> --constant-ish
if (!dirs2.Any())
{
dirs2 = dirs.First().EnumerateDirectories()
.Where(d => d.Name == "2gbsxl5no1wzqebnzbj2wglhi33za1rxxxxxxxxxxxxxxxxxxxxxxxxx").ToList(); // \<live dir> --constant-ish
}
if (!dirs2.Any())
{
throw new Exception("Unable to locate silverlight storage");
}
fullname = "6: " + dirs2.First().FullName;
dirs = dirs2.First().EnumerateDirectories().Where(d => d.Name == "f"); // \f --constant
fullname = "7: " + dirs.First().FullName;
var dir = dirs.First(); // final
fullname = dir.FullName;
// ReSharper restore CommentTypo
// ReSharper restore PossibleMultipleEnumeration
return fullname;
// ReSharper restore IdentifierTypo
}
catch (NotSupportedException ex)
{
Debug.WriteLine(ex);
MessageBox.Show(
"Failed to run (Not Supported):"
+ Environment.NewLine + fullname
+ Environment.NewLine + ex.Message,
messageBoxTitle,
MessageBoxButton.OK);
CheckElevatedPermissions();
return string.Empty;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
MessageBox.Show(
"Failed to run:"
+ Environment.NewLine + fullname
+ Environment.NewLine + ex.Message,
messageBoxTitle,
MessageBoxButton.OK);
return string.Empty;
}
}
同样,您必须拥有提升的权限才能使其正常工作,稍后我将使用此路径来定位文件以供其他用途:
var fullPath = Path.Combine(GetProfilePath(), FileName);
Run(fullPath.Replace("\\\\", "\\"));
private static void Run(string fullPath)
{
try
{
CheckElevatedPermissions();
var shell = AutomationFactory.CreateObject("WScript.Shell");
shell.Run("\"" + fullPath + "\"");
}
catch (NotSupportedException ex)
{
Debug.WriteLine(ex);
MessageBox.Show(
"Failed to run (Not Supported):"
+ Environment.NewLine + fullPath
+ Environment.NewLine + ex.Message,
messageBoxTitle,
MessageBoxButton.OK);
CheckElevatedPermissions();
}
catch (Exception ex)
{
Debug.WriteLine(ex);
MessageBox.Show(
"Failed to run:"
+ Environment.NewLine + fullPath
+ Environment.NewLine + ex.Message,
messageBoxTitle,
MessageBoxButton.OK);
}
}