ShellExecute Command not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to shutdown xpe through my application (written in delphi) by using the following line

ShellExecute(Handle, 'Open', 'xpepm.exe /shutdown', nil, nil, SW_SHOWNORMAL

however, it doesn't seem to work. This works perfectly well in windows 95 (although I call a different .exe to shutdown 95). Any help is appreciated

-saaby
 
I don't want to analyze why this does not work, but I have a simple
question.

Why don't you use xpepm.dll and functions in it to do the work?

Regards,
Slobodan

Saaby said:
I am trying to shutdown xpe through my application (written in delphi) by using the following line:

ShellExecute(Handle, 'Open', 'xpepm.exe /shutdown', nil, nil, SW_SHOWNORMAL)

however, it doesn't seem to work. This works perfectly well in windows 95
(although I call a different .exe to shutdown 95). Any help is appreciated,
 
Good question. Because I really don't know what I am doing. I am developing on a win2000 machine in delphi. How can I access functions in the dll which seems to only be located in xpe and compile. Forgive me if my questions are dumb...I just need to be directed in the right direction

-saaby
 
Saaby said:
I am trying to shutdown xpe through my application (written in
delphi) by using the following line:

ShellExecute(Handle, 'Open', 'xpepm.exe /shutdown', nil, nil,
SW_SHOWNORMAL)

however, it doesn't seem to work. This works perfectly well in
windows 95 (although I call a different .exe to shutdown 95). Any
help is appreciated,

-saaby

You need to give a fully qualified path to the executable.

Also, did you check the return code? My guess is that it is returning
ERROR_FILE_NOT_FOUND.
 
I don't think that you test shutdown function on your development computer,
right?

If you do, then you should probably copy xpepm.dll to your development
machine.

Regards,
Slobodan


Saaby said:
Good question. Because I really don't know what I am doing. I am
developing on a win2000 machine in delphi. How can I access functions in
the dll which seems to only be located in xpe and compile. Forgive me if my
questions are dumb...I just need to be directed in the right direction.
 
I assumed that you know how to use dll files from Delphi.

You can easily declare entry function in Delphi to any dll function.

Or if you prefer you can always use LoadLibrary, GetProcAddress API
functions.

No need to use h or lib files.

Regards,
Slobodan


Saaby said:
Ok I think I got it. I have to use the xpepm.lib and xpepm.h file in my
delphi project somehow. I found this out through research...but there is a
problem. I don't have the xpe cd...I downloaded xpe from microsoft's
website and there is no ValueAdd folder from the downloaded version. The
files that I need are supposedly in that folder. Does this mean I have to
get the CD???
 
Thanks for all the responses. Ok I am all set. For future reference this is what I did. I found the function call that will force xpe to shutdown. But my application had to aquire the right priviledges to shutdown xpe...that is what most of the code is doing. I used this junk of code from www.experts-exchange.com

function ExitWindows(RebootParam: Longword): Boolean
var
TTokenHd: THandle;
TTokenPvg: TTokenPrivileges;
cbtpPrevious: DWORD;
rTTokenPvg: TTokenPrivileges;
pcbtpPreviousRequired: DWORD;
tpResult: Boolean;
const
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
tpResult := OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
TTokenHd);
if tpResult then begin
tpResult := LookupPrivilegeValue(nil,
SE_SHUTDOWN_NAME,
TTokenPvg.Privileges[0].Luid);
TTokenPvg.PrivilegeCount := 1;
TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
cbtpPrevious := SizeOf(rTTokenPvg);
pcbtpPreviousRequired := 0;
if tpResult then
Windows.AdjustTokenPrivileges(TTokenHd,
False,
TTokenPvg,
cbtpPrevious,
rTTokenPvg,
pcbtpPreviousRequired);
end;
end;
Result := ExitWindowsEx(RebootParam, 0);
end;
 
The RebootParam should be set to "EWX_SHUTDOWN or EWX_FORCE". So the second to last line of the previous function should be
Result := ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE,0);
 
Slobodan Brcin \(eMVP\) said:
I don't want to analyze why this does not work, but I have a simple
question.

Why don't you use xpepm.dll and functions in it to do the work?

Regards,
Slobodan


(although I call a different .exe to shutdown 95). Any help is appreciated,


Here is what I use in C++ Builder
ShellExecute(NULL, "open", "shutdown.exe", "-s -t 00", NULL, SW_SHOW);

joe
 
Back
Top