close

Вход

Забыли?

вход по аккаунту

?

Re: How to run a program silently with

код для вставки
Re: How to run a program silently with CreateProcessWithLogonW()?
Re: How to run a program silently with
CreateProcessWithLogonW()?
Source:
http://www.techтИТarchive.net/Archive/Development/microsoft.public.win32.programmer.kernel/2005тИТ05/msg00435.htm
тАв From: "Alex Hong" <hctiaa@xxxxxxxx>
тАв Date: Tue, 17 May 2005 21:01:59 +0800
"Hector Santos" <nospamhere@xxxxxxxxxxxxxx> ????
news:eYlXs8sWFHA.3176@xxxxxxxxxxxxxxxxxxxxxxx
> > Well, the CREATE_NEW_CONSOL is off by default for CreateProcess, but it
is
> > on by default in the case of CreateProcessWithLogonW.
> > With the same setting, I don't have a window showing up when I used
> > CreateProcess.
>>
>
> Good Morning (atleast for me :тИТ)
>
> I don't have the experience with CreateProcessWithLogonW(). It only
within
> the last week that I have begun to explore it for implementation.
>
> The first thing was that I didn't see any console window and per our
> implementation it was not expected. So I didn't see a problem in this
area
> when I began to use this function within the last week.
>
> But now that I get into the details on this function, I see it has some
> default characteristics from that of CreateProcess().
>
> I wrote a simple console application to test it, I can not reproduce the
> problem you are seeing. In fact, as long as you have
STARTF_USESHOWWINDOWS
> and SW_HIDE, it will not show any console whatsoever. In fact, the only
> time I can get a console window was to uncomment both statements:
>
> STARTUPINFOW si;
> ZeroMemory(&si, sizeof(si));
> si.cb=sizeof(si);
> //si.dwFlags = STARTF_USESHOWWINDOW;
> //si.wShowWindow = SW_HIDE;
>
> I didn't matter what process creation flag I had.
Re: How to run a program silently with CreateProcessWithLogonW()?
1
Re: How to run a program silently with CreateProcessWithLogonW()?
>
> So this is different from CreateProcess() behavior.
>
> I plan to be doing more researching on this function since we do need to
> implement it into our package. I don't see a problem atleast under test
> system Windows 2000. But if you see something under Windows 2003, I'm
sure
> there is something there going on.
>
> Try this program.
>
> RunCP() uses CreateProcess. RunCPW() uses CreateProcessWithLogonW.
>
> // File : TestSpawn12.cpp
> // Author : Hector Santos, Santronics Software, Inc.
> // Compile: cl testspawn12.cpp /MT
>
> #define _WIN32_WINNT 0x0500
>
> #include <stdio.h>
> #include <afx.h>
> #include <conio.h>
>
> #define PRINTF cprintf
>
> BOOL RunCP(const char *fn)
>{
> PROCESS_INFORMATION pi;
> ZeroMemory(&pi, sizeof(pi));
>
> STARTUPINFO si;
> ZeroMemory(&si, sizeof(si));
> si.cb=sizeof(si);
> si.dwFlags = STARTF_USESHOWWINDOW;
> si.wShowWindow = SW_HIDE;
>
> DWORD dwFlags = 0;
> dwFlags |= CREATE_NO_WINDOW; // NT/2000 only
> //dwFlags |= CREATE_NEW_CONSOLE;
> //dwFlags |= DETACHED_PROCESS;
> //dwFlags |= CREATE_NEW_CONSOLE;
> dwFlags |= CREATE_NEW_PROCESS_GROUP;
>
> if (!CreateProcess(NULL, (char *)fn,
> NULL, NULL, FALSE,
> dwFlags,
> NULL, NULL, &si, &pi)) {
> return FALSE;
>}
> CloseHandle(pi.hThread);
>
Re: How to run a program silently with CreateProcessWithLogonW()?
2
Re: How to run a program silently with CreateProcessWithLogonW()?
> do {
> if (kbhit()) {
> int ch = getch();
> switch(ch) {
> case 'c':
> if (GenerateConsoleCtrlEvent(CTRL_C_EVENT, pi.dwProcessId))
{
> printf("Successfully sent signal\n");
> } else {
> printf("ERROR: %d Failed to send signal to
> app.\n",GetLastError());
>}
> break;
> case 'b':
> if (GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,
> pi.dwProcessId)) {
> printf("Successfully sent signal\n");
> } else {
> printf("ERROR: %d Failed to send signal to
> app.\n",GetLastError());
>}
> break;
>}
>}
> } while (WaitForSingleObject(pi.hProcess, 13) != WAIT_OBJECT_0);
> CloseHandle(pi.hProcess);
> return TRUE;
>}
>
> #define AnsiToWide(src,tar) MultiByteToWideChar(CP_ACP, 0,
> src,strlen(src)+1, tar, sizeof(tar)/sizeof(tar[0]))
>
> BOOL RunCPW(const char *fn)
>{
>
> PROCESS_INFORMATION pi;
> ZeroMemory(&pi, sizeof(pi));
>
> STARTUPINFOW si;
> ZeroMemory(&si, sizeof(si));
> si.cb=sizeof(si);
> si.dwFlags = STARTF_USESHOWWINDOW;
> si.wShowWindow = SW_HIDE;
> si.lpDesktop = L"winsta0\\default";
>
>
> DWORD dwFlags = 0;
> //dwFlags |= CREATE_NO_WINDOW; // NT/2000 only
> //dwFlags |= CREATE_NEW_CONSOLE;
> //dwFlags |= DETACHED_PROCESS;
> //dwFlags |= CREATE_NEW_PROCESS_GROUP;
Re: How to run a program silently with CreateProcessWithLogonW()?
3
Re: How to run a program silently with CreateProcessWithLogonW()?
>
>
> dwFlags = CREATE_DEFAULT_ERROR_MODE |
> CREATE_NEW_CONSOLE |
> CREATE_NEW_PROCESS_GROUP;
>
>
> dwFlags &= ~CREATE_NEW_CONSOLE;
>
> wchar_t *wszUserName = L"USERNAME";
> wchar_t *wszUserDomain = L"DOMAIN";
> wchar_t *wszUserPwd = L"PASSWORD";
> wchar_t wszProcessCmd[MAX_PATH];
> AnsiToWide(fn,wszProcessCmd);
>
> if (!CreateProcessWithLogonW(wszUserName,
> wszUserDomain,
> wszUserPwd,
> LOGON_WITH_PROFILE,
> NULL,
> wszProcessCmd,
> dwFlags,
> NULL,
> NULL, &si, &pi)) {
> return FALSE;
>}
> CloseHandle(pi.hThread);
>
> do {
> if (kbhit()) {
> int ch = getch();
> switch(ch) {
> case 'c':
> if (GenerateConsoleCtrlEvent(CTRL_C_EVENT, pi.dwProcessId))
{
> printf("Successfully sent signal\n");
> } else {
> printf("ERROR: %d Failed to send signal to
> app.\n",GetLastError());
>}
> break;
> case 'b':
> if (GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,
> pi.dwProcessId)) {
> printf("Successfully sent signal\n");
> } else {
> printf("ERROR: %d Failed to send signal to
> app.\n",GetLastError());
>}
> break;
>}
Re: How to run a program silently with CreateProcessWithLogonW()?
4
Re: How to run a program silently with CreateProcessWithLogonW()?
>}
> //PRINTF("*");
> } while (WaitForSingleObject(pi.hProcess, 13) != WAIT_OBJECT_0);
> CloseHandle(pi.hProcess);
> return TRUE;
>}
>
> void main(char argc, char *argv[])
>{
>
> PRINTF("тИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТ\n");
> if (!RunCPW("testchild.exe")) {
> PRINTF("Error %d\n",GetLastError());
> return;
>}
> PRINTF("тИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТтИТ\n");
>}
>
>
> тИТтИТ
> Hector Santos, Santronics Software, Inc.
> http://www.santronics.com
>
>
>
Thanks very much, Hector. I ran the same code under Windows XP, and the
window did not show up. It seems that the function is not doing what it's
supposed to do in Windows Server 2003. I am trying my best to find a
solution, but I am not quite sure if I can find one.
.
тАв FollowтИТUps:
тЩж Re: How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Hector Santos
тАв References:
тЩж How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Alex Hong
тЩж Re: How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Hector Santos
тЩж Re: How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Alex Hong
тЩж Re: How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Hector Santos
тЩж Re: How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Alex Hong
тЩж Re: How to run a program silently with CreateProcessWithLogonW()?
Re: How to run a program silently with CreateProcessWithLogonW()?
5
Re: How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Hector Santos
тЩж Re: How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Alex Hong
тЩж Re: How to run a program silently with CreateProcessWithLogonW()?
тЧК From: Hector Santos
тАв Prev by Date: Re: DeleteFile fails after FreeLibrary
тАв Next by Date: Re: How to run a program silently with CreateProcessWithLogonW()?
тАв Previous by thread: Re: How to run a program silently with CreateProcessWithLogonW()?
тАв Next by thread: Re: How to run a program silently with CreateProcessWithLogonW()?
тАв Index(es):
тЩж Date
тЩж Thread
Re: How to run a program silently with CreateProcessWithLogonW()?
6
Документ
Категория
Пионер
Просмотров
7
Размер файла
14 Кб
Теги
1/--страниц
Пожаловаться на содержимое документа