CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2007
    Posts
    24

    Angry 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?

  2. #2

    Re: My program don't reboot system

    May be you have to elevate your privileges?.
    Check your privilege level.
    C++ is divine.

  3. #3
    Join Date
    Feb 2007
    Posts
    24

    Re: My program don't reboot system

    I have privileges :/

  4. #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.

  5. #5
    Join Date
    Feb 2007
    Posts
    24

    Smile 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

  6. #6
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: My program don't reboot system

    Additionally, take a look at this post.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured