Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- at System.ServiceModel.Activation.SharedMemory.Read(String name, String& content)
- at System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.ReadEndpoint(String sharedMemoryName, String& listenerEndpoint)
- private static ImpersonationResult ImpersonateUser(string domain, string username, string password)
- {
- IntPtr token = IntPtr.Zero;
- IntPtr primaryToken = IntPtr.Zero;
- try
- {
- // Get token
- bool bImpersonated = LogonUser(
- username,
- domain,
- password,
- (int)LogonType.NetworkClearText,
- (int)LogonProvider.Default,
- ref token);
- if (!bImpersonated)
- {
- throw new Exception(string.Format("Failed to impersonate identity. Error code: {0}", Marshal.GetLastWin32Error()));
- }
- SecurityDescriptor sd = new SecurityDescriptor();
- IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(sd));
- Marshal.StructureToPtr(sd, ptr, false);
- InitializeSecurityDescriptor(ptr, 1);
- sd = (SecurityDescriptor)Marshal.PtrToStructure(ptr, typeof(SecurityDescriptor));
- // Set up security
- bool bDecriptorSet = SetSecurityDescriptorDacl(
- ref sd,
- true,
- IntPtr.Zero,
- false);
- if (!bDecriptorSet)
- {
- throw new Exception(string.Format("Failed to set security descriptor. Error code: {0}", Marshal.GetLastWin32Error()));
- }
- SecurityAttributes processAttributes = new SecurityAttributes();
- processAttributes.lpSecurityDescriptor = ptr;
- processAttributes.nLength = (uint)Marshal.SizeOf(sd);
- processAttributes.bInheritHandle = true;
- // Duplicate token
- bool bTokenDuplicated = DuplicateTokenEx(
- token,
- 0,
- ref processAttributes,
- (int)SecurityImpersonationLevel.SecurityImpersonation,
- (int)TokenType.TokenPrimary,
- ref primaryToken);
- if (!bTokenDuplicated)
- {
- throw new Exception(string.Format("Failed to duplicate identity token. Error code: {0}", Marshal.GetLastWin32Error()));
- }
- SecurityAttributes threadAttributes = new SecurityAttributes();
- threadAttributes.lpSecurityDescriptor = IntPtr.Zero;
- threadAttributes.nLength = 0;
- threadAttributes.bInheritHandle = false;
- // Got the token
- return new ImpersonationResult()
- {
- Token = primaryToken,
- ProcessAttributes = processAttributes,
- ThreadAttributes = threadAttributes
- };
- }
- finally
- {
- FreeToken(token);
- }
- }
- private static void FreeToken(IntPtr token)
- {
- if (token != IntPtr.Zero)
- {
- CloseHandle(token);
- }
- }
- <configuration>
- <system.serviceModel.activation>
- <net.tcp listenBacklog="16" <!—16 * # of processors -->
- maxPendingAccepts="4"<!— 4 * # of processors -->
- maxPendingConnections="100"
- receiveTimeout="00:00:30" <!—30 seconds -->
- teredoEnabled="false">
- <allowAccounts>
- <!-- LocalSystem account -->
- <add securityIdentifier="S-1-5-18"/>
- <!-- LocalService account -->
- <add securityIdentifier="S-1-5-19"/>
- <!-- Administrators account -->
- <add securityIdentifier="S-1-5-20"/>
- <!-- Network Service account -->
- <add securityIdentifier="S-1-5-32-544" />
- <!-- IIS_IUSRS account (Vista only) -->
- <add securityIdentifier="S-1-5-32-568"/>
- </allowAccounts>
- </net.tcp>
- </system.serviceModel.activation>
- C:Windowssystem32>net user Administrator /active:yes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement