J'ai fait un petit install.bat simplissime qui copie des fichiers sur C:\ comme suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
@echo off
title Installation du logiciel

xcopy "\\serveur\Logiciel\LastVersion\*" /D /Y C:\
xcopy "\\serveur\Logiciel\update.bat" /D /Y "C:\Documents and Settings\All Users\Start Menu\Programs\Startup"
copy "\\serveur\Logiciel\Logiciel.lnk" /Y "C:\Documents and Settings\All Users\Desktop\"

echo Installation terminee
start C:\Logiciel.exe
pause
exit
Note : dans le dossier LastVersion il y a le fichier Logiciel.exe et une dll.

Le probleme c'est que des fois l'utilisateur n'est pas admin donc n'a pas acces aux dossiers all users donc j'ai creer un 2eme .bat en remplacant "All users" par %USERNAME% comme suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
@echo off
title Installation du logiciel

xcopy "\\serveur\Logiciel\LastVersion\*" /D /Y C:\
xcopy "\\serveur\Logiciel\update.bat" /D /Y "C:\Documents and Settings\%USERNAME%\Start Menu\Programs\Startup"
copy "\\serveur\Logiciel\Logiciel.lnk" /Y "C:\Documents and Settings\%USERNAME%\Desktop\"

echo Installation terminee
start C:\Logiciel.exe
pause
exit
Ma question est comment detecter qu'il y eu un "Access denied" pour la copie "All users" et enchainer sur une copie "One user" ?

Sur le site de Microsoft j'ai trouve ca :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
xcopy %1 %2 /s /e 

if errorlevel 4 goto lowmemory 
if errorlevel 2 goto abort 
if errorlevel 0 goto exit
La liste des errorlevel retournes par xcopy est la :
  • 0 => Files were copied without error.
  • 1 => No files were found to copy.
  • 2 => The user pressed CTRL+C to terminate xcopy.
  • 4 => Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
  • 5 => Disk write error occurred.

Rien qui parle d'un "Access denied" ! Une idee ?