?
Solved

SYSTEM function problem

Posted on 2006-04-30
8
Medium Priority
?
262 Views
Last Modified: 2010-04-01
hi

why is only half this command executed !!! I mean it create the user but didn't create the logs?


  system("NET USER NewUSER XXXX /add /domain >>c:\new.log");




0
Comment
Question by:ALNMOO
8 Comments
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 1500 total points
ID: 16576103
>> system("NET USER NewUSER XXXX /add /domain >>c:\new.log");
This should be modified to
 system("NET USER NewUSER XXXX /add /domain >>c:\\new.log");
0
 
LVL 12

Assisted Solution

by:rajeev_devin
rajeev_devin earned 1500 total points
ID: 16576105
>> "NET USER NewUSER XXXX /add /domain >>c:\new.log"
In you string \n will  be taken as escape char new-line.
Since you want \ in your string make it \\
0
 
LVL 7

Author Comment

by:ALNMOO
ID: 16576266
still it didn't work.

I think system funaction cann't except parameters like this
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:Dariusz Dziara
ID: 16576686
Strange - I've tested (Windows XP) it and it works - log file is created.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16577079
Are you looking for the logfile in same directory or in C: ?
0
 
LVL 86

Expert Comment

by:jkr
ID: 16577409
The file redirection is done by the shell, not, so that should be

system("cmd.exe /c NET USER NewUSER XXXX /add /domain >> c:\\new.log");

But, why using 'system()' if there's an API?

0
 
LVL 86

Expert Comment

by:jkr
ID: 16577453
Speaking of that API - use

#include <tchar.h>
#include <lmcons.h>
#include <lmerr.h>
#include <lmaccess.h>
#include <lmapibuf.h>

NET_API_STATUS  AddNewUser  (   LPWSTR  pwstrName, LPWSTR   pwstrPwd)
{
    NET_API_STATUS              rc;
    USER_INFO_1                 ui1;

    wchar_t                     awcDomUsrName       [   LM20_DNLEN  +   LM20_UNLEN  +   1];
    wchar_t                     awcWkSta            [   MAX_COMPUTERNAME_LENGTH + 2];
    DWORD                       dwBufSiz            =   MAX_COMPUTERNAME_LENGTH + 1;

    ZeroMemory  (   &ui1,   sizeof (    USER_INFO_1));

    ui1.usri1_name          =   pwstrName;
    ui1.usri1_password      =   pwstrPwd;
    ui1.usri1_password_age  =   0;
    ui1.usri1_priv          =   USER_PRIV_USER;
    ui1.usri1_flags         =   UF_DONT_EXPIRE_PASSWD | UF_NORMAL_ACCOUNT | UF_SCRIPT;
    ui1.usri1_home_dir      =   L"";
    ui1.usri1_comment       =   L"";
    ui1.usri1_script_path   =   L"";


    GetComputerName (   awcWkSta,   &dwBufSiz);

    wsprintf    (   awcDomUsrName,  
                    L"%s\\%s",  
                    awcWkSta,
                    pwstrName
                );  

    rc  =   NetUserAdd  (   NULL,   1,  ( LPBYTE) &ui1, &dwParmErr);

    return rc;
}

NOTE that both the user name and the password need to be UNICODE.
0
 
LVL 86

Expert Comment

by:jkr
ID: 16648935
May I point out that the answer you accepted is partially incorrect in that context?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question