本地系统pipe理员的CreateProcessAsUser不应用Windows样式【JAVA教程】

!
也想出现在这里? 联系我们
信息

本地系统pipe理员的CreateProcessAsUser不应用Windows样式,第1张

概述本地系统pipe理员的CreateProcessAsUser不应用Windows样式

我在使用本地系统pipe理员的windows API CreateProcessAsUser的应用程序中遇到问题,以便以不同的用户身份运行应用程序。 到目前为止一切正常,但windows窗口和框架样式不应用某种方式。 该窗口总是看起来像一个巨大的框架的windows 2000窗口。 我还附上了一些截图

我还写了一些示例代码,说明如何在C ++中完成所有的魔术,而不需要考虑句柄和东西。

只要确保你有本地的一些用户“testing”与密码“testing”设置,并尝试运行公布的源代码作为本地系统pipe理员。 如果您尝试执行代码,其他用户将导致错误代码1413。

selenium作为本地系统用户运行时与铬问题

从以本地系统帐户启动的服务中,以login用户身份运行程序

pyhook用户键盘

从以本地系统帐户启动的程序获取当前用户名

该问题主要发生在VirtualBox中的windows 7虚拟机,某些windows 7系统和所有windows 8.1系统上。 很奇怪。 任何人都可以帮我解决这个问题吗? 谢谢!

#include <iostream> #include <windows.h> #include <UserEnv.h> #include <WinWlx.h> int AddAcetowindowstation( HWINSTA hwinsta,PSID psID ) { DWORD lengthNeeded; Security_informatION secInfo = DACL_Security_informatION; if( !GetUserObjectSecurity( hwinsta,&secInfo,NulL,&lengthNeeded ) ) { if ( GetLastError() != 122 ) { std::cout << \”GetUserObjectSecurity1 error: \” << GetLastError() << std::endl; return 0; } } PSecurity_DESCRIPTOR pSecDescriptor = ( PSecurity_DESCRIPTOR ) HeapAlloc( GetProcessHeap(),HEAP_ZERO_MEMORY,lengthNeeded ); if ( pSecDescriptor == NulL ) { std::cout << \”Allocating memory for pSecDescriptor Failed: \” << GetLastError() << std::endl; return 0; } PSecurity_DESCRIPTOR pSecDescriptorNew = ( PSecurity_DESCRIPTOR ) HeapAlloc( GetProcessHeap(),lengthNeeded ); if ( pSecDescriptorNew == NulL ) { std::cout << \”Allocating memory for pSecDescriptorNew Failed: \” << GetLastError() << std::endl; return 0; } if ( !GetUserObjectSecurity( hwinsta,pSecDescriptor,lengthNeeded,&lengthNeeded ) ) { std::cout << \”GetUserObjectSecurity2 error: \” << GetLastError() << std::endl; return 0; } if ( !InitializeSecurityDescriptor( pSecDescriptorNew,Security_DESCRIPTOR_REVISION ) ) { std::cout << \”InitializeSecurityDescriptor error: \” << GetLastError() << std::endl; return 0; } BOol DaclPresent; PACL poldDacl; BOol DaclDefaulted; if ( !GetSecurityDescriptorDacl( pSecDescriptor,&DaclPresent,&poldDacl,&DaclDefaulted ) ) { std::cout << \”GetSecurityDescriptorDacl error: \” << GetLastError() << std::endl; return 0; } // Get size information for DACL ACL_SIZE_informatION Aclinfo; Aclinfo.AceCount = 0; // Assume NulL DACL. Aclinfo.AclBytesFree = 0; Aclinfo.AclBytesInUse = sizeof( ACL ); if ( poldDacl == NulL ) DaclPresent = FALSE; // If not NulL DACL,gather size information from DACL. if ( DaclPresent ) { if ( !GetAclinformation( poldDacl,&Aclinfo,sizeof( ACL_SIZE_informatION ),AclSizeinformation ) ) { std::cout << \”GetAclinformation error: \” << GetLastError() << std::endl; return 0; } } DWORD cbNewACL = Aclinfo.AclBytesInUse + sizeof( ACCESS_ALLOWED_ACE ) + sizeof( ACL ) + sizeof( ACL ) + sizeof( ACCESS_ALLOWED_ACE ) + sizeof( ACL ) + sizeof( ACL ); PACL pNewACL = ( PACL ) HeapAlloc( GetProcessHeap(),cbNewACL ); if ( !InitializeAcl( pNewACL,cbNewACL,ACL_REVISION ) ) { std::cout << \”InitializeAcl error: \” << GetLastError() << std::endl; return 0; } LPVOID pTempAce = NulL; // copy old Ace to new DACL if ( DaclPresent && Aclinfo.AceCount ) { std::cout << \”Aclinfo.AceCount:\” << Aclinfo.AceCount << std::endl; for ( int i = 0; i < Aclinfo.AceCount; ++i ) { if ( !GetAce( poldDacl,i,&pTempAce ) ) { std::cout << \”GetAce[\” << i << \”] error: \” << GetLastError() << std::endl; return 0; } if ( !AddAce( pNewACL,ACL_REVISION,MAXDWORD,pTempAce,( ( PACE_header ) pTempAce )->AceSize ) ) { std::cout << \”AddAce[\” << i << \”] error: \” << GetLastError() << std::endl; return 0; } } } if ( !AddAccessAllowedAceEx( pNewACL,CONTAINER_inherit_ACE | inherit_ONLY_ACE | OBJECT_inherit_ACE,GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL,psID ) ) { std::cout << \”AddAccessAllowedAceEx1 error: \” << GetLastError() << std::endl; return 0; } if ( !AddAccessAllowedAceEx( pNewACL,NO_PROPAGATE_inherit_ACE,WINSTA_ENUMDESKtopS | WINSTA_READATTRIBUTES | WINSTA_ACCESSCliPBOARD | WINSTA_CREATEDESKtop | WINSTA_WRITEATTRIBUTES | WINSTA_ACCESSGLOBALATOMS | WINSTA_EXITwindows | WINSTA_ENUMERATE | WINSTA_READSCREEN | STANDARD_RIGHTS_required,psID ) ) { std::cout << \”AddAccessAllowedAceEx2 error: \” << GetLastError() << std::endl; return 0; } if ( !SetSecurityDescriptorDacl( pSecDescriptorNew,TRUE,pNewACL,FALSE ) ) { std::cout << \”SetSecurityDescriptorDacl error: \” << GetLastError() << std::endl; return 0; } if ( !SetUserObjectSecurity( hwinsta,pSecDescriptorNew ) ) { std::cout << \”SetUserObjectSecurity error: \” << GetLastError() << std::endl; return 0; } return 1; } int AddAcetoDesktop( HDESK hdesk,PSID psID ) { DWORD lengthNeeded; Security_informatION secInfo = DACL_Security_informatION; if ( !GetUserObjectSecurity( hdesk,lengthNeeded ); if ( pSecDescriptorNew == NulL ) { std::cout << \”Allocating memory for pSecDescriptorNew Failed: \” << GetLastError() << std::endl; return 0; } if ( !GetUserObjectSecurity( hdesk,AclSizeinformation ) ) { std::cout << \”GetAclinformation error: \” << GetLastError() << std::endl; return 0; } } DWORD cbNewACL = Aclinfo.AclBytesInUse + sizeof( ACCESS_ALLOWED_ACE ) + sizeof( ACL ) + sizeof( ACL ); PACL pNewACL = ( PACL ) HeapAlloc( GetProcessHeap(),( ( PACE_header ) pTempAce )->AceSize ) ) { std::cout << \”AddAce[\” << i << \”] error: \” << GetLastError() << std::endl; return 0; } } } if ( !AddAccessAllowedAce( pNewACL,DESKtop_REAdobJECTS | DESKtop_CREATEWINDOW | DESKtop_CREATEMENU | DESKtop_HOOKCONTRol | DESKtop_JOURNALRECORD | DESKtop_JOURNALPLAYBACK | DESKtop_ENUMERATE | DESKtop_WRITEOBJECTS | DESKtop_SWITCHDESKtop | STANDARD_RIGHTS_required,psID ) ) { std::cout << \”AddAccessAllowedAce error: \” << GetLastError() << std::endl; return 0; } if ( !SetSecurityDescriptorDacl( pSecDescriptorNew,FALSE ) ) { std::cout << \”SetSecurityDescriptorDacl error: \” << GetLastError() << std::endl; return 0; } if ( !SetUserObjectSecurity( hdesk,pSecDescriptorNew ) ) { std::cout << \”SetUserObjectSecurity error: \” << GetLastError() << std::endl; return 0; } return 1; } int AddAcetoBasenameObjectsDirectory( PSID psID,TOKEN_informatION_CLASS tClass ) { return 0; } int main( int argc,TCHAR *argv[] ) { HANDLE userToken; if ( !logonUser( L\”test\”,L\”\”,L\”test\”,logoN32_logoN_INteraCTIVE,logoN32_PROVIDER_DEFAulT,&userToken ) ) { std::cout << \”logonUser error: \” << GetLastError() << std::endl; return -1; } HANDLE token; if ( !DuplicatetokenEx( userToken,MAXIMUM_ALLOWED,SecurityImpersonation,TokenPrimary,&token ) ) { std::cout << \”DuplicatetokenEx error: \” << GetLastError() << std::endl; return -1; } PROfileINFO profileInfo; profileInfo.lpUsername = L\”test\”; profileInfo.DWFlags = NulL; profileInfo.lpProfilePath = L\”C:\\Users\\test\”; LoadUserProfile( token,&profileInfo ); LUID tcb_privilege_flag; if ( !LookupPrivilegeValue( NulL,SE_Security_name,&tcb_privilege_flag ) ) { std::cout << \”LookupPrivilegeValue error: \” << GetLastError() << std::endl; return -1; } TOKEN_PRIVILEGES tp; tp.PrivilegeCount = 1; tp.Privileges[0].LuID = tcb_privilege_flag; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if ( !AdjustTokenPrivileges( token,FALSE,&tp,sizeof( TOKEN_PRIVILEGES ),( PTOKEN_PRIVILEGES ) NulL,( PDWORD ) NulL ) ) { std::cout << \”AdjustTokenPrivileges error: \” << GetLastError() << std::endl; return -1; } HWINSTA hwinstasave = GetProcesswindowstation(); HWINSTA hwinsta = Openwindowstation( L\”winsta0\”,READ_CONTRol | WRITE_DAC ); HDESK hdesk = OpenDesktop( L\”default\”,READ_CONTRol | WRITE_DAC | DESKtop_WRITEOBJECTS | DESKtop_REAdobJECTS ); DWORD token_group_size; if ( !GetTokeninformation( token,TokenGroups,&token_group_size ) ) { if ( GetLastError() != 122 ) { std::cout << \”GetTokeninformation1 error: \” << GetLastError() << std::endl; return -1; } } PTOKEN_GROUPS pTokenGroup = ( PTOKEN_GROUPS ) new BYTE[token_group_size]; memset( pTokenGroup,token_group_size ); if ( !GetTokeninformation( token,pTokenGroup,token_group_size,&token_group_size ) ) { std::cout << \”GetTokeninformation2 error: \” << GetLastError() << std::endl; return -1; } PSID pSID = NulL; for ( int i = 0; i < pTokenGroup->GroupCount; ++i ) { if ( ( pTokenGroup->Groups[i].Attributes & SE_GROUP_logoN_ID ) == SE_GROUP_logoN_ID ) { pSID = pTokenGroup->Groups[i].SID; } } if ( pSID == NulL ) { std::cout << \”Unable to get logonSID error! No entry found!!!\” << std::endl; return -1; } if ( !AddAcetowindowstation( hwinsta,pSID ) ) { std::cout << \”AddAcetowindowstation error: \” << GetLastError() << std::endl; return -1; } if ( !AddAcetoDesktop( hdesk,pSID ) ) { std::cout << \”AddAcetoDesktop error: \” << GetLastError() << std::endl; return -1; } //if ( !AddAcetoBasenameObjectsDirectory( pSID,TokenSessionID ) ) //{ // std::cout << \”AddAcetoBasenameObjectsDirectory error: \” << GetLastError() << std::endl; // return -1; //} if ( !ImpersonateLoggedOnUser( token ) ) { std::cout << \”ImpersonateLoggedOnUser error: \” << GetLastError() << std::endl; return -1; } STARTUPINFO startupInfo; memset( &startupInfo,sizeof( startupInfo ) ); startupInfo.DWFlags = STARTF_USESHOWWINDOW; startupInfo.wShowWindow = SW_SHOWnorMAL; startupInfo.lpDesktop = L\”winsta0\\default\”; startupInfo.cb = sizeof( startupInfo ); PROCESS_informatION procInfo; memset( &procInfo,sizeof( procInfo ) ); if ( !SetCurrentDirectory( L\”C:\\windows\” ) ) { std::cout << \”SetCurrentDirectory error: \” << GetLastError() << std::endl; return -1; } if ( !CreateProcessAsUserW( token,L\”Notepad.exe\”,DETACHED_PROCESS,&startupInfo,&procInfo ) ) { std::cout << \”CreateProcessAsUser error: \” << GetLastError() << std::endl; return -1; } if ( !WaitForSingleObject( token,INFINITE ) ) { std::cout << \”WaitForSingleObject error: \” << GetLastError() << std::endl; return -1; } }

总结

以上是内存溢出为你收集整理的本地系统pipe理员的CreateProcessAsUser不应用Windows样式全部内容,希望文章能够帮你解决本地系统pipe理员的CreateProcessAsUser不应用Windows样式所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

© 版权声明
THE END
喜欢就支持一下吧
点赞149 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容