Click here to Skip to main content
15,887,267 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: convert File Path form DOS to Windows type Pin
_AnsHUMAN_ 27-Aug-06 19:53
_AnsHUMAN_ 27-Aug-06 19:53 
GeneralRe: convert File Path form DOS to Windows type Pin
sunit527-Aug-06 20:08
sunit527-Aug-06 20:08 
AnswerRe: convert File Path form DOS to Windows type Pin
ThatsAlok28-Aug-06 1:29
ThatsAlok28-Aug-06 1:29 
QuestionPrinting the view Pin
Anu_Bala27-Aug-06 19:44
Anu_Bala27-Aug-06 19:44 
AnswerRe: Printing the view Pin
velayudhan_raj27-Aug-06 20:18
velayudhan_raj27-Aug-06 20:18 
AnswerRe: Printing the view Pin
Hamid_RT27-Aug-06 20:57
Hamid_RT27-Aug-06 20:57 
QuestionCopyFile Problem! Pin
sach!!27-Aug-06 19:20
sach!!27-Aug-06 19:20 
AnswerRe: CopyFile Problem! Pin
_AnsHUMAN_ 27-Aug-06 20:11
_AnsHUMAN_ 27-Aug-06 20:11 
sach!! wrote:
How can I copy file to a readonly folder?

Did this in a console based application.
#include "windows.h"
DWORD CreateDirWithSecurity(LPCTSTR lpPath)
{
    SECURITY_ATTRIBUTES  mySecAttrib;
    SECURITY_DESCRIPTOR  mySecDesc;
    PACL                 pAcl = NULL;
    DWORD                cbAcl = 0,dwNeeded = 0,dwError = 0;
    HANDLE               hToken;
    PTOKEN_USER          ptu = NULL;
    
    if(!OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hToken))
        return GetLastError();
    

    GetTokenInformation( hToken, TokenUser, NULL, 0, &dwNeeded);
    if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) 
    {
        dwError = GetLastError();
        goto clearAll;
    }

    ptu = (TOKEN_USER*)malloc(dwNeeded);
    if (!GetTokenInformation(hToken, TokenUser, ptu, dwNeeded, &dwNeeded))
    {
        dwError = GetLastError();
        goto clearAll;
    }
    
    cbAcl = sizeof(ACL) + ((sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + GetLengthSid(ptu->User.Sid));
    pAcl = (ACL*) malloc (cbAcl);

    if(!InitializeAcl(pAcl, cbAcl, ACL_REVISION))
    {
        dwError = GetLastError();
        goto clearAll;
    }

    if(!AddAccessAllowedAce(pAcl,ACL_REVISION,GENERIC_ALL|STANDARD_RIGHTS_ALL|SPECIFIC_RIGHTS_ALL,ptu->User.Sid))
    {
        dwError = GetLastError();
        goto clearAll;
    }

    InitializeSecurityDescriptor(&mySecDesc,SECURITY_DESCRIPTOR_REVISION);

    SetSecurityDescriptorDacl(&mySecDesc,TRUE,pAcl,FALSE);
    SetSecurityDescriptorOwner(&mySecDesc,ptu->User.Sid,FALSE);
    SetSecurityDescriptorGroup(&mySecDesc,NULL,FALSE); 
    SetSecurityDescriptorSacl(&mySecDesc, FALSE,NULL,FALSE);

    mySecAttrib.nLength = sizeof(SECURITY_ATTRIBUTES);
    mySecAttrib.lpSecurityDescriptor = &mySecDesc;
    mySecAttrib.bInheritHandle = TRUE;

    CreateDirectory(lpPath, &mySecAttrib);

    dwError = GetLastError();

clearAll:
    if(ptu) free(ptu);
    if(pAcl) free(pAcl);

    CloseHandle(hToken);
    return dwError;
}

int _tmain(int argc, _TCHAR* argv[])
{
	CreateDirWithSecurity ("C:\\TestDir");
	FILE *fp;
	fp=fopen ("C:\\TestDir\\TestMe.txt","a+");
	fclose (fp);
	CopyFile ("C:\\TestDir\\TestMe.txt","C:\\TestDir\\TestMe1.txt",true);
	return 0;
}



Somethings seem HARD to do, until we know how to do them.
Wink | ;-) _AnShUmAn_

QuestionVC++ GUI App - Using Registry access functions Pin
dipuks27-Aug-06 19:01
dipuks27-Aug-06 19:01 
AnswerRe: VC++ GUI App - Using Registry access functions Pin
ThatsAlok28-Aug-06 0:54
ThatsAlok28-Aug-06 0:54 
AnswerRe: VC++ GUI App - Using Registry access functions Pin
David Crow28-Aug-06 4:06
David Crow28-Aug-06 4:06 
QuestionMaximize Application Pin
BlitzPackage27-Aug-06 15:34
BlitzPackage27-Aug-06 15:34 
AnswerRe: Maximize Application [modified] Pin
prasad_som27-Aug-06 20:10
prasad_som27-Aug-06 20:10 
GeneralRe: Maximize Application Pin
BlitzPackage28-Aug-06 2:38
BlitzPackage28-Aug-06 2:38 
Questionview the picture in other path by picture viewer Pin
sdhtyjnniutnbjnhbghb27-Aug-06 15:23
sdhtyjnniutnbjnhbghb27-Aug-06 15:23 
AnswerRe: view the picture in other path by picture viewer Pin
_AnsHUMAN_ 27-Aug-06 17:58
_AnsHUMAN_ 27-Aug-06 17:58 
GeneralRe: view the picture in other path by picture viewer Pin
sdhtyjnniutnbjnhbghb27-Aug-06 19:35
sdhtyjnniutnbjnhbghb27-Aug-06 19:35 
GeneralRe: view the picture in other path by picture viewer Pin
Hamid_RT27-Aug-06 21:14
Hamid_RT27-Aug-06 21:14 
GeneralRe: view the picture in other path by picture viewer Pin
sdhtyjnniutnbjnhbghb27-Aug-06 21:40
sdhtyjnniutnbjnhbghb27-Aug-06 21:40 
QuestionRe: view the picture in other path by picture viewer Pin
David Crow28-Aug-06 4:07
David Crow28-Aug-06 4:07 
AnswerRe: view the picture in other path by picture viewer Pin
sdhtyjnniutnbjnhbghb28-Aug-06 15:38
sdhtyjnniutnbjnhbghb28-Aug-06 15:38 
GeneralRe: view the picture in other path by picture viewer Pin
David Crow29-Aug-06 2:45
David Crow29-Aug-06 2:45 
QuestionNeed to end a string with null instead of \r\n Pin
samkook27-Aug-06 11:26
samkook27-Aug-06 11:26 
AnswerRe: Need to end a string with null instead of \r\n [modified] Pin
Waldermort27-Aug-06 11:41
Waldermort27-Aug-06 11:41 
GeneralRe: Need to end a string with null instead of \r\n [modified] Pin
samkook27-Aug-06 11:52
samkook27-Aug-06 11:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.