Thread: responding to system prompt?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    Unhappy responding to system prompt?

    I'm having trouble figuring out how to respond to a system prompt in a console application.

    I need to run a setup.exe on users PCs under the admin context.

    If I do something like:
    system("runas /user:computername\administrator setup.exe");

    the system then prompts me with:
    "enter password for administrator"

    I thought I could send the password to the keyboard buffer, but the problem is that the console app stops processing until a response is typed at the command prompt.

    I'm not sure how to get around this. I used to use su, which allows you to supply a password as a parameter but microsoft has taken this functionality away with runas.

    Any help appreciated.
    Thanks,
    CMG

  2. #2
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    You can't, since RunAs traps it. Use the API functions to do it. Try CreateProcessWithLogonW, or LogonUser and CreateProcessAsUser (on NT 4).
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    using CreateProcessAsUser and LogonUser

    OK so I'm trying to use CreateProcessAsUser and LogonUser but I'm having problems with the Process_Information and StartupInfo structs that CreateProcessAsUser uses.

    I've included Winbase.h and Windows.h but when I try to declare a struct of either type, I get a message:

    "error C2079: 'P_INFO' uses undefined struct 'PROCESS_INFORMATION' "

    However, If I try to typedef the struct myself I get an error:

    error C2371: 'STARTUPINFO' : redefinition; different basic types
    c:\program files\microsoft visual studio\vc98\include\winbase.h(3818) : see declaration of 'STARTUPINFO'

    So it seems to see the struct in winbase.h after all. I'm not sure whats happening here.

    Thanks,
    CMG

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    OOPS

    Hahah looks like it was just a syntax error. my bad

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    Damn, I still can get this think working. Here is a sniipet of the code:

    PHANDLE thandle;
    HANDLE prochandle;
    HANDLE threadhandle;

    STARTUPINFO StartInf;
    StartInf.cb=1000;
    StartInf.lpReserved=NULL;
    StartInf.lpDesktop=NULL;
    StartInf.lpTitle="CMG";
    StartInf.dwFlags=NULL;
    StartInf.cbReserved2=0;
    StartInf.lpReserved2=NULL;
    LPSTARTUPINFO StartInfPtr = &StartInf;

    PROCESS_INFORMATION ProcInf;
    ProcInf.dwProcessId=NULL;
    ProcInf.dwThreadId=NULL;
    ProcInf.prochandle=NULL;
    ProcInf.threadhandle=NULL;
    PROCESS_INFORMATION *ProcInfptr = &ProcInf;


    LogonUser(
    "administrator", // user name
    "computername", // domain or server
    "password", // password
    LOGON32_LOGON_BATCH, // type of logon operation
    LOGON32_PROVIDER_DEFAULT, // logon provider
    thandle // receive tokens handle
    );

    CreateProcessAsUser(
    thandle, // handle to user token
    "C:\\setup.exe", // name of executable module
    NULL, // command-line string
    NULL, // SD
    NULL, // SD
    TRUE, // inheritance option
    NORMAL_PRIORITY_CLASS, // creation flags
    NULL, // new environment block
    NULL, // current directory name
    StartInfPtr, // startup information
    ProcInfptr // process information
    );


    Any ideas? I don't get an error, it just doesn't launch setup. Argh.

    CMG

  6. #6
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > LPSTARTUPINFO StartInfPtr = &StartInf;

    Why?

    > LOGON32_LOGON_BATCH, // type of logon operation

    Do you really intend for no UI at all?

    You're not reading the output values from LogonUser or CreateProcessAsUser. Are they failing? If they do, what does GetLastError() tell you?
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    error messages

    OK,
    LogonUser is returning "a required privilege is not held by the client"

    CMG

  8. #8
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    From MSDN:

    "In Windows 2000, the process calling LogonUser requires the SE_TCB_NAME privilege." This is 'Act as part of the operating system', and not really something you want to give normal users.

    If you're running 2k, you should use the CreateProcessWithLogonW function. I can't speak for NT 4, since I'm not running it any more...
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    Dude,
    I don't have the CreateProcessWithLogonW function!? I'm using Visual Studio 6/Service pack 5. Do you know where I can get this?

    CMG

  10. #10
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > Dude,

    Who's that?

    > I don't have the CreateProcessWithLogonW function

    You need the latest version of the Platform SDK, which you can get from http://www.microsoft.com/msdownload/...sdk/sdkupdate/.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  11. #11
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    I installed the platform SDK and I now see the CreateProcessWithLogonW in the newer winbase.h, however I still get the unknown procedure error when I try to use it? Is there a trick to updating the platform sdk?

    CMG

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing System time and 30 minute alarm
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-17-2006, 05:10 AM
  2. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  3. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  4. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 06:58 AM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM