|
-
May 2nd, 2007, 05:54 PM
#1
My program don't reboot system
Hi, i have a problem with this code:
Code:
#include <windows.h>
#include <tchar.h>
#include <shellapi.h>
#include <stdio.h>
bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true)
{
int len = _tcslen(lpszDir);
TCHAR *pszFrom = new TCHAR[len+2];
_tcscpy(pszFrom, lpszDir);
pszFrom[len] = 0;
pszFrom[len+1] = 0;
SHFILEOPSTRUCT fileop;
fileop.hwnd = NULL; // no status display
fileop.wFunc = FO_DELETE; // delete operation
fileop.pFrom = pszFrom; // source file name as double null terminated string
fileop.pTo = NULL; // no destination needed
fileop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT; // do not prompt the user
if(!noRecycleBin)
fileop.fFlags |= FOF_ALLOWUNDO;
fileop.fAnyOperationsAborted = FALSE;
fileop.lpszProgressTitle = NULL;
fileop.hNameMappings = NULL;
int ret = SHFileOperation(&fileop);
delete [] pszFrom;
return (ret == 0);
}
int main()
{
printf("Borrando archivos temporales de instalacion...\n");
printf("Porfavor espere...\n\n");
DeleteDirectory("C:\\Archivos de programa\\Servicios en l*nea",false);
DeleteDirectory("C:\\Archivos de programa\\ComPlus Applications",false);
DeleteDirectory("C:\\Archivos de programa\\Microsoft Office CD para actualizaciones",false);
DeleteDirectory("C:\\Documents and Settings\\Administrador\\Menú Inicio\\Programas\\WinRAR",false);
DeleteDirectory("C:\\Documents and Settings\\All Users\\Menú Inicio\\Programas\\WinRAR",false);
_unlink("C:\\Documents and Settings\\All Users\\Menú Inicio\\Programas\\Asistencia remota.lnk");
_unlink("C:\\Documents and Settings\\All Users\\Menú Inicio\\Programas\\POWERPOINT presentacion.lnk");
_unlink("C:\\Documents and Settings\\All Users\\Menú Inicio\\Programas\\ACCESS base de datos.lnk");
_unlink("C:\\Documents and Settings\\Administrador\\Menú Inicio\\Programas\\Asistencia remota.lnk");
_unlink("C:\\Documents and Settings\\Administrador\\Menú Inicio\\Programas\\POWERPOINT presentacion.lnk");
_unlink("C:\\Documents and Settings\\Administrador\\Menú Inicio\\Programas\\ACCESS base de datos.lnk");
printf("Se han eliminado todos los archivos.\n");
Sleep(2000);
printf("El equipo se reiniciara en 10 segundos...");
::ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 10);
return 0;
}
this:
::ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 10);
and this don't work
ExitWindowsEx(EWX_SHUTDOWN, 10);
why?
-
May 2nd, 2007, 06:24 PM
#2
Re: My program don't reboot system
May be you have to elevate your privileges?.
Check your privilege level.
C++ is divine.
-
May 2nd, 2007, 06:42 PM
#3
Re: My program don't reboot system
-
May 2nd, 2007, 07:03 PM
#4
Re: My program don't reboot system
I meant your calling application should have SE_SHUTDOWN_NAME privilege.
Refer this link
http://msdn2.microsoft.com/en-us/library/aa376871.aspx
C++ is divine.
-
May 2nd, 2007, 07:46 PM
#5
Re: My program don't reboot system
Fixed!
change this:
Code:
::ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 10);
or
Code:
ExitWindowsEx(EWX_SHUTDOWN, 10);
for this:
Code:
WinExec("c:\\windows\\system32\\shutdown.exe -r -t 10", SW_SHOW);
thats work perfect! =D
-
May 3rd, 2007, 02:09 AM
#6
Re: My program don't reboot system
Additionally, take a look at this post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|