2011-07-05 2 views
1

다른 Windows 사용자 ID로 실행하려면 내 코드를 가장해야합니다. 지금은 웹에서 일부 기본 라이브러리를 호출하는 일부 코드를 사용하고 있습니다.Windows 7에서 C# 코드를 가장합니다

코드 목적은 파일 서버 사용자 디렉토리 권한에 대한 권한을 변경하는 것입니다.

내 폴더 권한을 변경할 수는 있지만 다른 사용자의 자격 증명이 있어야 자신의 폴더에 대한 권한을 변경할 수 있습니다. 하지만 나는 그를 흉내내어 컴퓨터에서 코드를 실행하고 있습니다.

하지만 승인되지 않은 예외가 발생합니다.

내가 사용하고있는 코드는 다음과 같습니다

[DllImport("advapi32.dll", SetLastError = true)] 
     private static extern int LogonUser(
      string lpszUserName, 
      string lpszDomain, 
      string lpszPassword, 
      int dwLogonType, 
      int dwLogonProvider, 
      ref IntPtr phToken); 

나는이 Windows 7에서 작동되지 않았거나 확실하지 않다. 이런 문제에 직면 한 사람이 있습니까?

예외 난 점점 오전 :

Messagee:"{"Attempted to perform an unauthorized operation."}" 
stack trace: 
at System.Security.AccessControl.Win32.SetSecurityInfo(ResourceType type, String name, SafeHandle handle, SecurityInfos securityInformation, SecurityIdentifier owner, SecurityIdentifier group, GenericAcl sacl, GenericAcl dacl) 
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext) 
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections, Object exceptionContext) 
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections) 
at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath) 
at System.IO.Directory.SetAccessControl(String path, DirectorySecurity directorySecurity) 
at FolderAccessManager.Program.Main(String[] args) in 

당신이 몇 가지 솔루션을 공유 시겠어요 ..?

+0

예외에 대한 자세한 내용을 알려주십시오. –

+0

예외 메시지와 함께 편집하십시오. – sbmandav

+0

'runas'를 쓰지 않는 이유는 무엇입니까? –

답변

1

WindowsIdentity.Impersonate을 살펴보십시오. 거기에서 당신은 어떻게 가야하는지의 예를 보게 될 것입니다.

+0

동일한 코드를 사용했습니다 ... 내가 가장하고있는 사용자가 충분한 권한을 갖고 있지 않은 것처럼 보입니다. – sbmandav

1

ASP.NET과 도메인 가입 컴퓨터를 사용하고 있습니까?

기본 apppool ID로 실행할 때 asp.net 응용 프로그램에서이 코드를 사용하는 것과 똑같은 메시지가 나타납니다. apppool 사용자를 'domain admin'권한을 가진 도메인 사용자로 변경하면이 문제가 해결됩니다 (Windows 7).

관련 문제