如何利用C++ Builder获取系统的sid信息?
发布日期:2021-07-28 20:33:28 浏览次数:1 分类:技术文章

本文共 2549 字,大约阅读时间需要 8 分钟。

 
 
头文件代码:
//---------------------------------------------------------------------------#ifndef Unit1H#define Unit1H//---------------------------------------------------------------------------#include 
#include
#include
#include
//---------------------------------------------------------------------------class TForm1 : public TForm{__published: // IDE-managed Components TButton *Button1; TEdit *Edit1; TLabel *Label1; void __fastcall Button1Click(TObject *Sender);private: // User declarationspublic: // User declarations __fastcall TForm1(TComponent* Owner);};//---------------------------------------------------------------------------extern PACKAGE TForm1 *Form1;//---------------------------------------------------------------------------#endif
实现文件代码:
//---------------------------------------------------------------------------#include 
#pragma hdrstop#include
#include "Unit1.h"#define MAX_NAME 256//---------------------------------------------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TForm1 *Form1;//---------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){}//---------------------------------------------------------------------------void ConvertSid(PSID pSid, LPTSTR TextualSid){ PSID_IDENTIFIER_AUTHORITY psia = GetSidIdentifierAuthority(pSid); DWORD sidLen = sprintf(TextualSid, TEXT("S-%lu-"), SID_REVISION); sidLen += sprintf(TextualSid + strlen(TextualSid), TEXT("%lu"), psia->Value[5]); int i = 0; int subAuthorities = *GetSidSubAuthorityCount(pSid); for (i = 0; i < subAuthorities; i++) { sidLen += sprintf(TextualSid + sidLen, TEXT("-%lu"), *GetSidSubAuthority(pSid, i)); }}void GetLocalSid(LPTSTR szSid){ char szUserName[MAX_NAME] = {0}; DWORD nameSize = sizeof(szUserName) ; GetUserName(szUserName, &nameSize); char szUserSid[MAX_NAME] = {0}; char szUserDomain[MAX_NAME] = {0}; DWORD sidSize = sizeof(szUserSid); DWORD domainSize = sizeof(szUserDomain); SID_NAME_USE snu; LookupAccountName( NULL, szUserName, (PSID)szUserSid, &sidSize, szUserDomain, &domainSize, &snu ); ConvertSid(szUserSid, szSid); }void __fastcall TForm1::Button1Click(TObject *Sender){ char szSid[MAX_NAME] = {0}; GetLocalSid(szSid); Edit1->Text = szSid; Edit1->SetFocus();}//---------------------------------------------------------------------------
 
 

转载地址:https://blog.csdn.net/stpeace/article/details/12895211 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:find 函数和string :: npos 的用法
下一篇:如何用C语言获取系统的sid信息?

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月08日 22时04分48秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

人工智能实践:Tensorflow笔记(五):卷积网络基础与实践 2019-04-28
编译原理 1.1 2019-04-28
win10磁盘如何解锁bitlocker,解决分区助手无法调整分区问题 2019-04-28
Github生成ssh 密钥和怎样向gitHub上传文件(详细教程) 2019-04-28
cmd更换默认编码 2019-04-28
MySQL 之使用uuid_short 报错 Out of range value for column 'id' at row 1 问题 2019-04-28
Could not initialize class sun.awt.X11GraphicsEnvironment异常处理 2019-04-28
redis缓存雪崩、穿透、击穿概念、布隆过滤器小结及解决办法 2019-04-28
用idea新建maven项目,创建Scala项目--做个记录 2019-04-28
【pom.xml 依赖】使用net.sf.json-lib-2.4-jdk15.jar所需要的其他依赖架包 以及其一直在pom.xml报错的问题 2019-04-28
Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String' 2019-04-28
Eclipse中通过Tomcat运行JavaWeb项目报错:java.lang.OutOfMemoryError: PermGen space 错误的解决方案 2019-04-28
Tomcat运行 报错:Error configuring application listener of class org.springframework.web.cont 2019-04-28
struts2框架总结:(二) 2019-04-28
struts2框架总结:(三) 2019-04-28
关于hibernate查询数据时报错java.lang.StringIndexOutOfBoundsException: String index out of range: 0 2019-04-28
[cn.itheima.web.action.CustomerAction] not found - action 的解决办法 2019-04-28
struts2框架总结:(四) 2019-04-28
谈一谈JUnit神奇的报错 java.lang.Exception:No tests found matching 2019-04-28
@PreDestroy 为什么不执行 2019-04-28