×

security_attributes

SECURITY_ATTRIBUTES的描述?调用exe 程序,如何获取返回的字符串

admin admin 发表于2022-06-24 01:53:17 浏览94 评论0

抢沙发发表评论

SECURITY_ATTRIBUTES的描述


lpSecurityDescriptor
A pointer to a security descriptor for the object that controls the sharing of it. If NULL is specified for this member, the object is assigned the default security descriptor of the calling process. This is not the same as granting access to everyone by assigning a NULL discretionary access control list (DACL). The default security descriptor is based on the default DACL of the access token belonging to the calling process. By default, the default DACL in the access token of a process allows access only to the user represented by the access token. If other users must access the object, you can either create a security descriptor with the appropriate access, or add ACEs to the DACL that grants access to a group of users.
Windows Me/98/95: The lpSecurityDescriptor member of this structure is ignored.


调用exe 程序,如何获取返回的字符串


// start.cpp : Defines the entry point for the console application.// #include “stdafx.h“ #include 《iostream》#include 《windows.h》using namespace std; bool Ccmd(char * pDir,char * fileOut){ SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; HANDLE hStdOutput=CreateFile(fileOut,GENERIC_WRITE,0,&sa,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);//打开输出文件 STARTUPINFO si; PROCESS_INFORMATION pi; si.cb = sizeof(STARTUPINFO); GetStartupInfo(&si); si.hStdOutput=(HANDLE)hStdOutput; si.hStdError=(HANDLE)hStdOutput; si.wShowWindow = SW_HIDE; si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; // DWORD dw = CREATE_NO_WINDOW; CreateProcess(NULL,pDir,NULL,NULL,TRUE,NULL,NULL,NULL,&si,π); CloseHandle(hStdOutput); return true;} int main(int argc, char* argv){ char * fileOut =“d:\\1000\\out.txt“; char * pir=“cl d:\\1000\\add.cpp“; Ccmd(pir,fileOut); return 0;}

1 dos命令的输出可以按楼上横秋朋友的方法把输出重定向到文件,然后自己去读文件中内容来得到字符串;2 如果那个“别的应用程序”不是dos命令,也不是源程序(即只有exe文件),那只好在你的程序中捕捉它的输出窗口中的内容;3 如果那个“别的应用程序”是你的另一个源程序的话,那就好办了,用snakebite2008(唢呐科比特)朋友说的方法随便选一个就行。

SECURITY_ATTRIBUTES的简介


SECURITY_ATTRIBUTES结构包含一个对象的安全描述符,并指定检索到指定这个结构的句柄是否是可继承的。这个结构为很多函数创建对象是提供安全性设置。如:CreateFile,CreatePipe,CreateProcess,RegCreateKeyEx,RegSaveKeyEx。
typedef struct _SECURITY_ATTRIBUTES {
DWORD nLength; / /结构体的大小,可用SIZEOF取得
LPVOID lpSecurityDescriptor; / /安全描述符
BOOL bInheritHandle ;/ /安全描述的对象能否被新创建ÆÆ的进程继承
} SECURITY_ATTRIBUTES,* PSECURITY_ATTRIBUTES;-security_attributes