|
If you want to determine if you are being run during logon by a script you may want to look at your parent processes. I believe, don't remember right now, but during logon the scripts are executed by USERINIT.EXE and not WINLOGON.EXE (If they are executed by WINLOGON.EXE USERINIT.EXE will still be present and it goes away after you have logged in).
So, either a) your parent process or parent's parent will be USERINIT or it will be WINLOGON and USERINIT will still be running and present on the system.
You should do some experiments with walking your parent process. USERINIT does not go away until all logon scripts have run (They are synchronous unless you start a seperate process and don't wait). So, even if USERINIT is your parent after logon, USERINIT goes away so you will see it as the parent of explorer, but the process will not exist anymore.
This is one way; there are other methods which can be attempted some more complex and require system components.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Toby,
Yes, this is exactly the information I was seeking (except you
filled in the details so eloquently) ... I will try this strategy
this weekend and report back.
Thank you again.
-Shawn
|
|
|
|
|
You can find the logon sid of window station winsta0 if that is same as the logon sid of the process it means that the process is running in interactive logon session.
I have some code in the following article
http://www.codeproject.com/buglist/dbgfix.asp[^]
There is some code that finds out whether the user is interactive user or not
|
|
|
|
|
Thanks Rama,
Well, it not so much that I want to find-out if the user
is interactive or not. Its more to do if whether he is currently
being logged-in or not.
Point being - I have an executable i want him to be able to run
from his login script, but not afterwards ... And if this user
was to manually kick-off his login script (therefore this
program) later, that it would detect this, and the program
would alert.
Do you still think there is anything in your article worth
investigating because to be honest, my ideal solution would
be something more "straight-forward" like your suggesting.
-Shawn
|
|
|
|
|
I am afraid that will not work. You have to find out the parent process of your script and see if it is userinit.exe as suggested by Toby.
-- modified at 15:50 Friday 20th January, 2006
|
|
|
|
|
WlxActivateUserShell() will start the USERINIT process which occurs after the user has logged in and I also believe at this time switches to the interactive desktop. Then the login scripts are run (I don't remember if they are run on the interactive desktop or security desktop but I belive the interactive desktop).
If this is true, this means that you would not be able to determine if you were run during the login process/scripts by using this detection as you would already be logged in. You also couldn't find out what the current desktop is to determine this if you are already on the interactive desktop when the scripts are run, which I believe is the case.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
I misunderstood the question. The logon scripts are run in interactive desktop so my method will fail.
|
|
|
|
|
Toby, Rama
You guys are great help. The other thing is, this strategy has to work
with both Windows XP Professional Fast Logon Optimization AND with
login scripts running synchronously or non-synchronously.
So again, looks like my best bet is enuming userinit.
Cant say thanks enough.
-Shawn
|
|
|
|
|
You can also look if explorer is running yet (unless the shell was replaced) as a backup verification.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Ok gents ... just walked my procs on a typical logon ... here's are
the results (proc.exe is my proc).
pid=1484 proc=proc.exe
pid=3412 proc=cmd.exe
pid=3120 proc=userinit.exe
pid=972 proc=winlogon.exe
pid=892 proc=smss.exe
pid=4 proc=System
pid=0 proc=[System Process]
so looks like userinit is the ticket, unless you guys see something
else I should be keying in on.
|
|
|
|
|
Just make sure in Windows 2000 that USERINIT goes away after starting the shell; I don't remember if it does or not but in XP it does.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Good point. Walking my procs from the command line, after
being logged in yields this:
pid=2704 proc=proc.exe
pid=472 proc=cmd.exe
pid=3188 proc=explorer.exe
Like you say, this is on XP as well. Will do both
these tests on Windows 2000 and advise.
|
|
|
|
|
Here is my first stab at a function - LogonMode returns 1 if running during logon, 0 (zero) otherwise.
#include <TlHelp32.h>
LONG LogonMode()
{
LONG pid = GetCurrentProcessId();
PROCESSENTRY32 pe;
pe.dwSize = sizeof(pe);
while((pid = GetParentPid(pid,&pe)) != 0)
{
if(_tcsncicmp(pe.szExeFile,"userinit.exe",12) == 0)
{
return 1;
}
}
return 0;
}
LONG GetParentPid(LONG pid, PROCESSENTRY32* pe)
{
LONG lRet = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hSnapshot != INVALID_HANDLE_VALUE)
{
if(Process32First(hSnapshot, pe))
{
do
{
if(pe->th32ProcessID == pid)
{
return pe->th32ParentProcessID;
}
}
while((lRet = Process32Next(hSnapshot,pe)));
}
}
return lRet;
}
|
|
|
|
|
Can anyone help me in making a source code for a profeller
EXAMPLE
enter a number[1-10]: 5
*****
* ****
** ***
*** **
**** *
***** *****
* ****
** ***
*** **
**** *
*****
pls can someone help me....
|
|
|
|
|
need4change wrote: Can anyone help me in making a source code for a profeller
I assume you meant to say profiler. What's wrong with the one that ships with Visual Studio?
need4change wrote: EXAMPLE
Just out of curiosity, what is this an example of?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
Looks like a CS homework assignment.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
need4change wrote: pls can someone help me....
Yes, if you ask the right question. I don't see any question in your post. And your post is also very unclear. If you ask for people to do the job for you, be very carefull then. You'll be warned
|
|
|
|
|
I've got a c++ win32 (non MFC) dialog based app with a custom control
that listens to WM_KEYDOWN,WM_KEYUP for keypress/releases to
behave like a synth keyboard - so i NEED keyup events.
Thing is, it's BEEPING! (a "default beep" type beep)
In my custom control i've tried returning 0, returning 1 and
calling the default message handler - STILL beeps.
I tried with and without calling TranslateMessage() in my msgloop.
STILL BEEPS!
Can anybody help meee?
Here's my custom control - pretty basic:
(KeyMap and Canvas are my own classes, but are pretty simple and DON'T BEEP)
struct {key k; ubyte nt;} KyNt [] = {
{'z', M_NT(M_C,0)}, {'x', M_NT(M_D,0)},
{'c', M_NT(M_E,0)}, {'v', M_NT(M_F,0)},
{'b', M_NT(M_G,0)}, {'n', M_NT(M_A,0)},
{'m', M_NT(M_B,0)}, {',', M_NT(M_C,1)},
{'.', M_NT(M_D,1)}, {'/', M_NT(M_E,1)},
{'s', M_NT(M_Db,0)}, {'d', M_NT(M_Eb,0)},
{'g', M_NT(M_Gb,0)}, {'h', M_NT(M_Ab,0)},
{'j', M_NT(M_Bb,0)}, {'l', M_NT(M_Db,1)},
{';', M_NT(M_Eb,1)},
{'q', M_NT(M_C,1)}, {'w', M_NT(M_D,1)},
{'e', M_NT(M_E,1)}, {'r', M_NT(M_F,1)},
{'t', M_NT(M_G,1)}, {'y', M_NT(M_A,1)},
{'u', M_NT(M_B,1)}, {'i', M_NT(M_C,2)},
{'o', M_NT(M_D,2)}, {'p', M_NT(M_E,2)},
{'[', M_NT(M_F,2)}, {']', M_NT(M_G,2)},
{'\\', M_NT(M_A,2)},
{'2', M_NT(M_Db,1)}, {'3', M_NT(M_Eb,1)},
{'5', M_NT(M_Gb,1)}, {'6', M_NT(M_Ab,1)},
{'7', M_NT(M_Bb,1)}, {'9', M_NT(M_Db,2)},
{'0', M_NT(M_Eb,2)}, {'=', M_NT(M_Gb,2)},
{BSP_KEY, M_NT(M_Ab,2)}
};
struct CtlKbd {
public:
void Init ()
{
TRC("CtlKbd::Init bgn");
MemSet (& _wc, 0, sizeof (_wc));
_wc.lpszClassName = "KBD";
_wc.lpfnWndProc = WinProc;
_wc.cbSize = sizeof (WNDCLASSEX);
_wc.hCursor = ::LoadCursor (0, IDC_ARROW);
if (::RegisterClassEx (& _wc) == 0)
DieWn ("CtlKbd::CtlKbd RegisterClassEx");
TRC("CtlKbd::Init end");
}
private:
WNDCLASSEX _wc;
static LRESULT CALLBACK WinProc (HWND hwnd, UINT msg, WPARAM w, LPARAM l)
{ static bool foc = false;
static ubyte oct = 4;
static ubyte vel = 100;
switch (msg) {
case WM_LBUTTONDOWN:
::SetFocus (hwnd);
return 0;
case WM_SETFOCUS:
foc = true; ::RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE);
return 0;
case WM_KILLFOCUS:
foc = false; ::RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE);
return 0;
case WM_PAINT:
{ PAINTSTRUCT p;
Canvas c (::BeginPaint (hwnd, & p));
c.SetBg (foc ? 0 : 255, foc ? 255 : 0, 0);
c.Text (0, 0, "in");
::EndPaint (hwnd, & p);
}
return 0;
case WM_ERASEBKGND:
return 0;
case WM_KEYDOWN: case WM_KEYUP:
{ KeyMap km;
key k;
ubyte i;
TrkEv e;
char buf [900];
if ((l & 0x80000000) || (!(l & 0x40000000))) if (k = km.Map (w)) {
for (i = 0; i < BITS (KyNt); i++)
if (k == KyNt [i].k) {
e.ctrl = (ubyte)(KyNt [i].nt + oct*12);
e.valu = (l & 0x80000000) ? 0 : vel;
if ((l & 0x80000000) == 0) e.valu |= 0x80;
e.chan = 0;
sprintf (buf, "kbd ctl: $%02X $%02X\n", e.ctrl, e.valu);
DBG(buf);
break;
}
}
return 0;
}
}
return ::DefWindowProc (hwnd, msg, w, l);
}
};
|
|
|
|
|
Seems to me you could play around with the various messages you are handling by calling DefWindowProc() instead until you find the message that is in question. From there, you could narrow it down to the actual statement that is causing the problem.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
Well, I suspect the DefWindowProc itself is actually DOING the beeping.
But I don't know why???
I must be doing something wrong, but I don't know what...
|
|
|
|
|
Hmm, I took everything out and it still beeps.
So it has to be due to IsDialogMessage of the MsgLoop
or DefWindowProc of my custom control...
When focus is on a combo box, holding down keys doesn't cause "default beep".
But when my custom control has focus it DOES do the "default beep".
Maybe my control has to say "hey i need keypresses" so IsDialogMessage doesn't
beep (I'm guessing due to not being able to navigate to a static with that mnemonic???)
Hmmmmmmmmmm......
(And thanks for the reply!)
...Steve
|
|
|
|
|
Ok. I needed to handle WM_GETDLGCODE for my custom control to get wm_keyup/down...
No more beeping.
Buuuut, now I can't tab outa the field once I'm in it.
I can click out, but can't tab/shift-tab out...
Anybody know how to correctly handle tab, shift-tab, cursor up/down/left/right, mnemonic???
Sighhh...
...Steve
struct CtlKbd {
public:
void Init ()
{
TRC("CtlKbd::Init bgn");
MemSet (& _wc, 0, sizeof (_wc));
_wc.lpszClassName = "KBD";
_wc.lpfnWndProc = WinProc;
_wc.cbSize = sizeof (WNDCLASSEX);
_wc.hCursor = ::LoadCursor (0, IDC_ARROW);
if (::RegisterClassEx (& _wc) == 0)
DieWn ("CtlKbd::CtlKbd RegisterClassEx");
TRC("CtlKbd::Init end");
}
private:
WNDCLASSEX _wc;
static LRESULT CALLBACK WinProc (HWND hwnd, UINT msg, WPARAM w, LPARAM l)
{ static bool foc = false;
static ubyte oct = 4;
static ubyte vel = 100;
switch (msg) {
case WM_GETDLGCODE:
return DLGC_WANTALLKEYS;
case WM_LBUTTONDOWN:
::SetFocus (hwnd);
return 0;
case WM_SETFOCUS:
foc = true; ::RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE);
return 0;
case WM_KILLFOCUS:
foc = false; ::RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE);
return 0;
case WM_PAINT:
{ PAINTSTRUCT p;
Canvas c (::BeginPaint (hwnd, & p));
c.SetBg (foc ? 0 : 255, foc ? 255 : 0, 0);
c.Text (0, 0, "in");
::EndPaint (hwnd, & p);
}
return 0;
case WM_ERASEBKGND:
return 0;
case WM_KEYDOWN: case WM_KEYUP:
{ KeyMap km;
key k;
ubyte i;
TrkEv e;
char buf [900];
if ((l & 0x80000000) || (!(l & 0x40000000))) if (k = km.Map (w)) {
for (i = 0; i < BITS (KyNt); i++)
if (k == KyNt [i].k) {
e.ctrl = (ubyte)(KyNt [i].nt + oct*12);
e.valu = (l & 0x80000000) ? 0 : vel;
if ((l & 0x80000000) == 0) e.valu |= 0x80;
e.chan = 0;
sprintf (buf, "kbd ctl: $%02X $%02X\n", e.ctrl, e.valu);
DBG(buf);
return 0;
}
}
break;
}
}
return ::DefWindowProc (hwnd, msg, w, l);
}
};
|
|
|
|
|
Steve Hazel wrote: case WM_GETDLGCODE:
return DLGC_WANTALLKEYS;
What about DLGC_WANTARROWS and DLGC_WANTTAB ?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
handling WM_GETDLGCODE with return DLGC_WANTALLKEYS tells the dialog manager
that I want keys and to NOT beep when a key doesn't resolve to a static to navigate to.
The keys I want to watch go up and down don't include arrows or tab.
I was -hoping- that the msgloop's IsDialogMessage() or control's DefWindowProc
would handle tabbing(and shift tabbing and arrowing) to other controls,
but noooooo...
So now I gotta figure out how to correctly tab/shift-tab/etc...
...Steve
|
|
|
|
|
How about changing it to DLGC_WANTCHARS instead, so the dialog manager will still process the arrow keys and the tab character if the IsDialogMessage is properly introduced into whatever main message loop you have for your application.
If not, then you need to handle the arrow keys and TAB/SHIFT+TAB your self and translate them into setting focus of appropriate next and previous dialog controls.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|