相关疑难解决方法(0)

System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)拒绝访问

我试图上传文件并将其转换为另一种格式,然后将其保存在我的Web服务器上,但是我收到以下错误:System.ComponentModel.Win32Exception(0x80004005):在System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)中拒绝访问)在System.Diagnostics.Process.Start()

当我尝试在本地计算机的Web服务器(Windows 7)上执行此操作时没有问题,但是在将我的网站部署到具有Windows Server 2008 R2的Web托管提供商后,我收到此错误.

我正在使用ASP.NET c#.我猜这是一个权限问题,但我不知道如何提升任何权限.请帮忙!

c# asp.net permissions iis-7

6
推荐指数
2
解决办法
2万
查看次数

使用LOGON32_LOGON_NEW_CREDENTIALS进行Windows模拟的魔力是什么?

从我在Windows上的用户模拟阅读中,应该正确使用LOGON32_LOGON_NEW_CREDENTIALS登录类型来模拟用户到数据库.使用马特约翰逊漂亮的冒充包装(最初发布在这里,然后擦亮了这里),我尝试测试了这一点-这里除了我的定义特定领域,USER,PWD和CONN_STRING常数我的整个程序.

using System;
using System.Data.SqlClient;
using SimpleImpersonation;

namespace ImpersonationDemo
{
    class Program
    {
        private static SqlConnection _connection;

        static void Main(string[] args)
        {
            using (Impersonation.LogonUser(
                    DOMAIN, USER, PWD, LogonType.NewCredentials))
            {
                GetOpenConnection();
                CheckDbCredentials();
                CloseConnection();
            }
            Console.WriteLine("Press return to exit");
            Console.ReadLine();
        }

        private static void CheckDbCredentials()
        {
            using (
                var command = new SqlCommand(
                    "SELECT nt_user_name, SUSER_SNAME() "
                    +"FROM sys.dm_exec_sessions WHERE session_id = @@SPID",
                    _connection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Console.WriteLine("{0}, {1}",
                            reader.GetString(0), reader.GetString(1)); …
Run Code Online (Sandbox Code Playgroud)

c# windows impersonation

6
推荐指数
1
解决办法
5999
查看次数

核心 2.0 - 模拟 Windows 用户的最佳方式?

使用 .NET Web 应用程序,我可以使用此类轻松地模拟 Windows 用户:

/// <summary>
///  TOOLS IMPERSONATION
/// </summary>
namespace Tools
{
    #region Using directives.
    // ----------------------------------------------------------------------

    using System;
    using System.Security.Principal;
    using System.Runtime.InteropServices;
    using System.ComponentModel;

    // ----------------------------------------------------------------------
    #endregion

    /////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Impersonation of a user. Allows to execute code under another
    /// user context.
    /// Please note that the account that instantiates the Impersonator class
    /// needs to have the 'Act as part of operating system' privilege set.
    /// </summary>
    /// <remarks>   
    /// This class …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc impersonation asp.net-core-2.0

6
推荐指数
1
解决办法
9908
查看次数

写入文件为不同的用户

我正在尝试写入我的本地用户帐户无权访问的文件,如何以管理员身份打开和写入文件?

impersonation file-io vba admin

5
推荐指数
1
解决办法
825
查看次数

检查共享目录权限 - C#

我想编写一个检查共享目录权限的代码,我检查多个解决方案但是在尝试获取本地目录权限时它运行良好但是当我为共享目录创建测试用例时它失败了.

我在这个问题中尝试了一些例子: SOF:check-for-directory-and-file-write-permissions-in-net

但它只适用于本地目录.

例如,我使用了这个类:

 public class CurrentUserSecurity
{
    WindowsIdentity _currentUser;
    WindowsPrincipal _currentPrincipal;

    public CurrentUserSecurity()
    {
        _currentUser = WindowsIdentity.GetCurrent();
        _currentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
    }

    public bool HasAccess(DirectoryInfo directory, FileSystemRights right)
    {
        // Get the collection of authorization rules that apply to the directory.
        AuthorizationRuleCollection acl = directory.GetAccessControl()
            .GetAccessRules(true, true, typeof(SecurityIdentifier));
        return HasFileOrDirectoryAccess(right, acl);
    }

    public bool HasAccess(FileInfo file, FileSystemRights right)
    {
        // Get the collection of authorization rules that apply to the file.
        AuthorizationRuleCollection acl = file.GetAccessControl()
            .GetAccessRules(true, true, typeof(SecurityIdentifier)); …
Run Code Online (Sandbox Code Playgroud)

.net c# acl access-control winforms

5
推荐指数
1
解决办法
1420
查看次数

什么是RevertToSelf()? - C#.net

我不明白RevertToSelf().net应用程序中有什么用.检查MSDN定义,它将定义读取为

The RevertToSelf function terminates the impersonation of a client application.
Run Code Online (Sandbox Code Playgroud)

那么,通过停止客户端的上下文,当前用户上下文是否会更改为sysadmin上下文?通过调用RevertToSelf(),我的代码将在sys管理模式下运行吗?

更新

好的,如果我在ASP.NET应用程序中调用RevertToSelf()会发生什么?让我们考虑一下我不会开始任何模仿.所以如果我调用RevertToSelf()它会恢复到应用程序池标识吗?

.net c# impersonation advapi32

4
推荐指数
1
解决办法
5941
查看次数

线程可以作为另一个用户执行吗?(.NET 2.0/3.5)

我有一个 C# 应用程序,它对包含计算的源文件执行一些运行时编译到动态程序集中。显然,这是一个严重的安全问题。

从下面的“公式”,将生成下面的代码,并创建一个动态程序集:

公式:

Int32 _index = value.LastIndexOf('.');
String _retVal = value.Substring(_index + 1);
return _retVal;
Run Code Online (Sandbox Code Playgroud)

生成的代码:

using System;
namespace Dynamics
{
  public class Evaluator
  {
    public Object Evaluate(String value)
    {
      // Begin external code
      Int32 _index = value.LastIndexOf('.');
      String _retVal = value.Substring(_index + 1);
      return _retVal;
      // End external code
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

然后加载动态程序集并通过反射执行 Evaluate 方法。这很好用。

问题是恶意代码注入的可能性很大,所以我想在“沙盒”线程(没有任何非托管 API 调用)中运行 Evaluate 方法。出于测试目的,我使用内置的匿名 Windows 用户,并提供了以下代码:

Thread tSandbox = new Thread(
    new ParameterizedThreadStart(this.DoSandboxedEvaluation));
WindowsIdentity tIdentity = WindowsIdentity.GetAnonymous();
WindowsPrincipal tPrincipal = new …
Run Code Online (Sandbox Code Playgroud)

.net c# security reflection sandbox

3
推荐指数
1
解决办法
5484
查看次数

在程序文件下运行 .exe 时出现 System.UnauthorizedAccessException

c:\ProgramFiles通过 WiX 安装程序,我安装了 Windows 应用程序,并使用 .exe 和所需的 dll创建了文件夹。

运行 .exe 时,我得到了System.UnauthorizedAccessException.

如果有任何有用的建议,请告诉我。

请查找以下事件日志以供参考。

Application: xxxxxxx.exe
Framework Version: v1.0.0
Description: The process was terminated due to an unhandled exception.
Exception Info: System.UnauthorizedAccessException
   at System.IO.__Error.WinIOError(Int32, System.String)
   at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
   at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)
   at System.IO.StreamWriter.CreateFile(System.String, Boolean, Boolean)
   at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding, Int32, Boolean)
   at System.IO.StreamWriter..ctor(System.String, Boolean)
   at System.IO.File.AppendText(System.String)
Run Code Online (Sandbox Code Playgroud)

c# windows windows-installer wix

2
推荐指数
1
解决办法
5979
查看次数

模拟另一台计算机上的本地用户

我需要将控制器登录到另一台计算机并在其上复制文件;我必须在远程计算机上使用本地用户。

目前,我正在使用以下代码:

    private Impersonate(bool active, string domain, string username, string password, LogonType logonType)
    {
        if (active)
        {
            IntPtr handle;
            var ok = NativeMethods.LogonUser(username, domain, password, (int)logonType, 0, out handle);
            if (!ok)
            {
                var errorCode = Marshal.GetLastWin32Error();
                throw new ApplicationException(string.Format("Could not impersonate the elevated user.  LogonUser returned error code {0}.", errorCode));
            }

            _handle = new SafeTokenHandle(handle);
            _context = WindowsIdentity.Impersonate(_handle.DangerousGetHandle());
        }
    }
Run Code Online (Sandbox Code Playgroud)

通过这些参数:

    using (Impersonate.LogonUser(true,
        ".",
        "todev1.domain.com\admin",
        "Test123_",
        LogonType.Interactive))
    {

    }  
Run Code Online (Sandbox Code Playgroud)

和这个胜利的API:

[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern …
Run Code Online (Sandbox Code Playgroud)

c# impersonation dllimport

1
推荐指数
1
解决办法
2544
查看次数

如何在 C# 中以另一个用户身份创建一个没有密码的进程?

我正在尝试用 C# 创建一些类似于 Linux 的 sudo 的东西。我找到了一种使用密码以其他用户身份运行该进程的方法,但我想在没有密码的情况下执行此操作。

另外,我的 C# 软件以管理员身份运行并且已通过 UAC。

我当前的代码:

static void CreateProcessAsUser(string name, string path, SecureString password)
{
    Process proc = new Process();

    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.FileName = path;
    proc.StartInfo.UserName = name;
    proc.StartInfo.Password = password;

    proc.Start();
}
Run Code Online (Sandbox Code Playgroud)

谢谢。

c# windows uac process

0
推荐指数
1
解决办法
1048
查看次数