A
AJ
Unregistered / Unconfirmed
GUEST, unregistred user!
现在做了一个程序, 用一些u盘量产工具,copy到了u盘里, 插入优盘时会自动运行, 主程序有个功能是退出优盘,我把退出优盘的功能做了个exe文件, 因为主程序不能推出, 因为自己还在运行, 所以我的做法是, 先把退出优盘的Eject.exe拷贝到系统目录下,然后主程序执行推出优盘的时候,关闭自己,然后执行Eject.exe,退出优盘;但不行,提示不能退出优盘,直接执行Eject.exe是没问题的, 应该是调用ShellExecute执行Eject.exe的时候, 还是占用了优盘, 所以退不出去
这是我的退出代码
procedure TMainFrm.act_EjectDeviceExecute(Sender: TObject);
var
sDriveName, sEjectFileName, sDestEjectFileName : String;
hHandle : THandle;
si:STARTUPINFO;
piROCESS_INFORMATION;
dwExitCode : DWORD;
begin
sDriveName:= GetDiskDriverName();
// sEjectFileName:= ExtractFilePath(Application.ExeName) + 'Eject.exe';
sDestEjectFileName:= FEjectFilePath + 'Eject.exe';
// CopyFile(PChar(sEjectFileName), PChar(sDestEjectFileName), false);
//
// sEjectFileName:= ExtractFilePath(Application.ExeName) + 'EjectTimer.exe';
// sDestEjectFileName:= FEjectFilePath + 'EjectTimer.exe';
// CopyFile(PChar(sEjectFileName), PChar(sDestEjectFileName), false);
FCanClose:= True;
hHandle:= GetDesktopWindow();
sDestEjectFileName:= 'D:/EjectTimer.exe';
//ShellExecute(0, 'open', PChar(sDestEjectFileName), PChar('-'+sDriveName), nil,0);
FillChar(si,SizeOf(si),0);
FillChar(pi,SizeOf(pi),0);
si.cb:=SizeOf(si);
CreateProcess(PAnsiChar(sDestEjectFileName),PAnsiChar('-J'),nil,nil,False,0,nil,nil,si,pi);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
// GetExitCodeProcess(pi.hProcess, dwExitCode);
// ExitProcess(dwExitCode);
Close;
//Application.Terminate;
end;
我想我用ShellExecute和CreateProcess到调用别的地方的exe程序, 应该就和主程序没关系了, 应该能退出优盘啊, 但是不知道应该怎么处理。
我的QQ:46810878
这是我的退出代码
procedure TMainFrm.act_EjectDeviceExecute(Sender: TObject);
var
sDriveName, sEjectFileName, sDestEjectFileName : String;
hHandle : THandle;
si:STARTUPINFO;
piROCESS_INFORMATION;
dwExitCode : DWORD;
begin
sDriveName:= GetDiskDriverName();
// sEjectFileName:= ExtractFilePath(Application.ExeName) + 'Eject.exe';
sDestEjectFileName:= FEjectFilePath + 'Eject.exe';
// CopyFile(PChar(sEjectFileName), PChar(sDestEjectFileName), false);
//
// sEjectFileName:= ExtractFilePath(Application.ExeName) + 'EjectTimer.exe';
// sDestEjectFileName:= FEjectFilePath + 'EjectTimer.exe';
// CopyFile(PChar(sEjectFileName), PChar(sDestEjectFileName), false);
FCanClose:= True;
hHandle:= GetDesktopWindow();
sDestEjectFileName:= 'D:/EjectTimer.exe';
//ShellExecute(0, 'open', PChar(sDestEjectFileName), PChar('-'+sDriveName), nil,0);
FillChar(si,SizeOf(si),0);
FillChar(pi,SizeOf(pi),0);
si.cb:=SizeOf(si);
CreateProcess(PAnsiChar(sDestEjectFileName),PAnsiChar('-J'),nil,nil,False,0,nil,nil,si,pi);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
// GetExitCodeProcess(pi.hProcess, dwExitCode);
// ExitProcess(dwExitCode);
Close;
//Application.Terminate;
end;
我想我用ShellExecute和CreateProcess到调用别的地方的exe程序, 应该就和主程序没关系了, 应该能退出优盘啊, 但是不知道应该怎么处理。
我的QQ:46810878