[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

How do I include a file, then save the file to c:\windows

I need to update a .vxd file on many machines.
How can I take the updated file and include it in my c++ program, than run the program so that it copies and saves that file to C:\windows\system

Thanks for any help
Pat
0
pote
Asked:
pote
1 Solution
 
TriskelionCommented:
What do you mean by INCLUDE?
0
 
nietodCommented:
Your can write an "install" program that copies the file the the system directory using CopyFile().  

If the file you want to copy over is open by the system, it will fail.  In that case you can use MoveFileEx() to copy the file on an NT machine.  The documenation for MoveFileEx() explains how to achieve this on a windows 9x machine.
0
 
poteAuthor Commented:
By include I mean to distribute a new file, and have the exe rogram copy that file to the windows dir.
How do I reference the new file from within the C++ program, or where do I store the file, and how do I tell the program to copy the file to windows?


0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
nietodCommented:
Just store the new file somewhere on the instillation disk.  One common way to handle this is to just place the new file in the same directory as the installation program.  Then the instillation program can use GetModuleFileName() to get the path to itself, and then it can use this to get the path to the file to be installed.
0
 
cpopinCommented:
Are you trying to actually include the file in the EXE as data, then create the new VXD in the C:\Windows\System directory and and write out the data to the new file?  That way you can distribute one file.

If so, this is possible by converting the original VXD file to a CPP file in hex:

// NewVXD.CPP
unsigned char sVXD[] = {0xFE, 0xBE, ...};

Then create the file and write sVXD[] out to it.

You'd have to write (or find) a small utility program that converts the VXD to a CPP though.

Is this what you're asking for?
0
 
nietodCommented:
For that sort of approach you could just place the program to be installed inside the installation program as a binary resource.
0
 
KesslerCommented:
I am working with a similar situation that might clear up what pote is trying to do.  I would like to Import a binary file into the VS C++ 6.0 project Resource area so it is included in my executable.  Then, I would like to extract that file from the Resource area and save the file to a directory on the user's machine.  I don't know how to extract the file from the Resource area of the executable and save the file to the user's machine.  

pote, is this similare to what you are trying to accomplish?
0
 
cpopinCommented:
What I did was create a custom "EXECUTEABLE" type of resource named "TEST.EXE" and imported the file.  Then I used the following code to write it back out:

    const char sFileName[] = "TEST.EXE";
    HRSRC hrExe = FindResource(NULL, sFileName, "EXECUTEABLE");
    DWORD cExe = SizeofResource(NULL, hrExe);
    HGLOBAL hExe = LoadResource(NULL, hrExe);
    char *spExe = (char *)LockResource(hExe);
    CFile fExe;
    CFileException e;
    if (!fExe.Open(sFileName, CFile::modeCreate | CFile::modeWrite, &e)) {
#ifdef _DEBUG
        afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
    }
    fExe.Write(spExe, cExe);
    fExe.Close();
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now