Destruction de raccourcis sans être admin
Bonjour,
Mon application a besoin de détruire un raccourci sur le bureau (situé dans "AllUsers", sous Windows XP). Puisque les utilisateurs ne sont pas administrateurs, j'utilise le code suivant pour me connecter avec un compte admin dédié. Le raccourci à effacer est "bcFile".
Ce code fonctionne correctement avec un adminisatrateur et retourne sans erreur pour les utilisateurs "normaux". Dans ce dernier cas, le raccourci disparaît du bureau, seulement pour réapparaître lorsque l'utilisateur force un "refresh" avec la touche F5. Je crois que le problème pourrait être relié au guillements dans wCommand et wParams.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| PROCESS_INFORMATION pi;
AnsiString sCommand = "C:\\windows\\system32\\cmd.exe";
int iBuffSize = sCommand.WideCharBufSize();
wchar_t* wCommand = new wchar_t[iBuffSize];
wCommand[0] = 0;
sCommand.WideChar(wCommand, iBuffSize);
AnsiString sParams = " del \"/C \"" + bcFile + "\"\" ";
wchar_t wParams[MAX_PATH + 1];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sParams.c_str(), -1, wParams, MAX_PATH);
ShowMessage(sCommand + " " + sParams);
AnsiString sUsername = "masteraccount";
AnsiString sDomain = "production";
AnsiString sPassword = "234l2k3j4";
if (CreateProcessWithLogonW(
static_cast(sUsername.data()),
static_cast(sDomain.data()),
static_cast(sPassword.data()),
LOGON_NETCREDENTIALS_ONLY, wCommand,
wParams, 0, NULL, NULL, NULL, &pi) != 0) {
// Notify the shell for delete operation.
SHChangeNotify(SHCNE_DELETE, SHCNF_PATH, bcFile.c_str(), NULL);
}
else {
CustomErrorHandler(ERR_ABORT, ERR_DEL_SHORTCUT);
} |
Toute aide sur ce code (ou sur une autre manière de faire l'opération) sera appréciée...