Total New Guy

Our company has Visaul C++, we hack our way through.  I would be the closest thing to a programmer here, I'm more of a Access/SQL or web guy than a real programmer.  Eitherway.

I need to write a program in C++, probally a Console application I guess from reading that will look up  a couple values(path to files) in the registry, create subdirectory there, copy file there, then run seperate program.  

This doesn't have to be flashy or anything, just functional.

Help with the code please. Quicker the better

Jay
LVL 4
CrossWiredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
To look up values in the registry, you'll have to use the APIs that are made for that, e.g. like

    HKEY hKey = NULL;
    char szDesiredKey[MAX_PATH];
    char szDesiredValue[MAX_PATH];
    long lResult = ERROR_SUCCESS;
    DWORD dwType = REG_SZ;
    DWORD dwSize = MAX_PATH;

    strcpy( szDesiredKey, "Software\\Company\\Application" );

    lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, szDesiredKey, 0, KEY_QUERY_VALUE, &hKey );

    if( ERROR_SUCCESS != lResult )
    {
        return( FALSE );
    }

    lResult = RegQueryValueEx( hKey, "SomeValue", NULL, &dwType, ( LPBYTE )szDesiredValue, &dwSize );

    if( ERROR_SUCCESS != lResult )
    {
        return( FALSE );
    }

   RegCloseKey( hKey );


To create a subdirectory, you can use 'CreateDirectory()', to start a program, 'ShellExecute()' will come in handy. Or, in a nutshell:

#include <windows.h>
#include <stdio.h>

int main () {

    HKEY hKey = NULL;
    char szDesiredKey[MAX_PATH];
    char szDesiredValue[MAX_PATH];
    long lResult = ERROR_SUCCESS;
    DWORD dwType = REG_SZ;
    DWORD dwSize = MAX_PATH;

    // read subdirectory to create from the registry
    strcpy( szDesiredKey, "Software\\Company\\Application" );

    lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, szDesiredKey, 0, KEY_QUERY_VALUE, &hKey );

    if( ERROR_SUCCESS != lResult )
    {
        return( -1 );
    }

    lResult = RegQueryValueEx( hKey, "NewSubdir", NULL, &dwType, ( LPBYTE )szDesiredValue, &dwSize );

    if( ERROR_SUCCESS != lResult )
    {
        return( -2 );
    }

    RegCloseKey( hKey );

    printf("Creating Subdirectory %s\n", szDesiredValue);
    CreateDirectory ( szDesiredValue);

    // launch external program
    ShellExecute(NULL, "open", "notepad.exe", NULL, NULL, SW_SHOW);

    return 0;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteHCommented:
For accessing the registry you should have a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/registry_functions.asp
Functions to use are
RegOpenKey(Ex)
RegGetValue
RegCloseKey

For simple file operations you have the choice of using the system command:
system ("cd yourPath");
system ("mkdir newdir");

0
CrossWiredAuthor Commented:
jkr:

Got this:
\mdlx.cpp(40) : fatal error C1010: unexpected end of file while looking for precompiled header directive
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

SteHCommented:
You need to change the options of your project either to not used precompiled headers or add the files stdafx.h and stdafx.cpp to your project and use stdafx.h as precompiled header file.
0
jkrCommented:
>> C1010: unexpected end of file while looking for precompiled header directive

Sorry, that's one of the problems with VC - create an empty file named 'StdAfx.h' and place

#include "StdAfx.h"

as the 1st line in the source file. VC uses that for these so called 'precompiled headers'
0
SteHCommented:
For the header you can choose in the project options to create it, use a specified one or automatically use a specified file.
0
rstaveleyCommented:
With your skills, I'd go for JScript for this kind of task (i.e. using the Windows Scriping Host).

e.g. reading the registry

http://msdn.microsoft.com/library/en-us/script56/html/wsmthregread.asp

Your web-head should feel at home with the JavaScriptishness of it.
0
CrossWiredAuthor Commented:
Actually this is coming together quite nice, thanks for the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.