Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. System.ServiceModel.CommunicationException: The service endpoint failed to listen on the URI 'net.tcp://localhost:5400/Agent/384' because access was denied. Verify that the current user is granted access in the appropriate allowAccounts section of SMSvcHost.exe.config. ---> System.ComponentModel.Win32Exception: Access is denied
  2. at System.ServiceModel.Activation.SharedMemory.Read(String name, String& content)
  3. at System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.ReadEndpoint(String sharedMemoryName, String& listenerEndpoint)
  4.  
  5. private static ImpersonationResult ImpersonateUser(string domain, string username, string password)
  6. {
  7. IntPtr token = IntPtr.Zero;
  8. IntPtr primaryToken = IntPtr.Zero;
  9.  
  10. try
  11. {
  12. // Get token
  13. bool bImpersonated = LogonUser(
  14. username,
  15. domain,
  16. password,
  17. (int)LogonType.NetworkClearText,
  18. (int)LogonProvider.Default,
  19. ref token);
  20.  
  21. if (!bImpersonated)
  22. {
  23. throw new Exception(string.Format("Failed to impersonate identity. Error code: {0}", Marshal.GetLastWin32Error()));
  24. }
  25.  
  26. SecurityDescriptor sd = new SecurityDescriptor();
  27. IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(sd));
  28. Marshal.StructureToPtr(sd, ptr, false);
  29. InitializeSecurityDescriptor(ptr, 1);
  30. sd = (SecurityDescriptor)Marshal.PtrToStructure(ptr, typeof(SecurityDescriptor));
  31.  
  32. // Set up security
  33. bool bDecriptorSet = SetSecurityDescriptorDacl(
  34. ref sd,
  35. true,
  36. IntPtr.Zero,
  37. false);
  38.  
  39. if (!bDecriptorSet)
  40. {
  41. throw new Exception(string.Format("Failed to set security descriptor. Error code: {0}", Marshal.GetLastWin32Error()));
  42. }
  43.  
  44. SecurityAttributes processAttributes = new SecurityAttributes();
  45. processAttributes.lpSecurityDescriptor = ptr;
  46. processAttributes.nLength = (uint)Marshal.SizeOf(sd);
  47. processAttributes.bInheritHandle = true;
  48.  
  49. // Duplicate token
  50. bool bTokenDuplicated = DuplicateTokenEx(
  51. token,
  52. 0,
  53. ref processAttributes,
  54. (int)SecurityImpersonationLevel.SecurityImpersonation,
  55. (int)TokenType.TokenPrimary,
  56. ref primaryToken);
  57.  
  58. if (!bTokenDuplicated)
  59. {
  60. throw new Exception(string.Format("Failed to duplicate identity token. Error code: {0}", Marshal.GetLastWin32Error()));
  61. }
  62.  
  63. SecurityAttributes threadAttributes = new SecurityAttributes();
  64. threadAttributes.lpSecurityDescriptor = IntPtr.Zero;
  65. threadAttributes.nLength = 0;
  66. threadAttributes.bInheritHandle = false;
  67.  
  68. // Got the token
  69. return new ImpersonationResult()
  70. {
  71. Token = primaryToken,
  72. ProcessAttributes = processAttributes,
  73. ThreadAttributes = threadAttributes
  74. };
  75. }
  76. finally
  77. {
  78. FreeToken(token);
  79. }
  80. }
  81.  
  82. private static void FreeToken(IntPtr token)
  83. {
  84. if (token != IntPtr.Zero)
  85. {
  86. CloseHandle(token);
  87. }
  88. }
  89.  
  90. <configuration>
  91. <system.serviceModel.activation>
  92. <net.tcp listenBacklog="16" <!—16 * # of processors -->
  93. maxPendingAccepts="4"<!— 4 * # of processors -->
  94. maxPendingConnections="100"
  95. receiveTimeout="00:00:30" <!—30 seconds -->
  96. teredoEnabled="false">
  97. <allowAccounts>
  98. <!-- LocalSystem account -->
  99. <add securityIdentifier="S-1-5-18"/>
  100. <!-- LocalService account -->
  101. <add securityIdentifier="S-1-5-19"/>
  102. <!-- Administrators account -->
  103. <add securityIdentifier="S-1-5-20"/>
  104. <!-- Network Service account -->
  105. <add securityIdentifier="S-1-5-32-544" />
  106. <!-- IIS_IUSRS account (Vista only) -->
  107. <add securityIdentifier="S-1-5-32-568"/>
  108. </allowAccounts>
  109. </net.tcp>
  110. </system.serviceModel.activation>
  111.  
  112. C:Windowssystem32>net user Administrator /active:yes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement