我正在删除窗口启动菜单中的快捷方式,作为基于应用程序中自动启动设置的删除/创建的一部分。
我最初通过安装创建快捷方式(我正在使用InnoSetup)。问题是我的代码不会删除快捷方式。但是,如果我自己删除快捷方式,让我的代码创建它,而不是删除它。但是快捷方式名称是完全相同的,我甚至在代码中检查它是否存在,并且每次都会这样做。作为安装的一部分,我需要做什么才能删除它?
void SettingsDialog::on_checkBoxAutoStart_clicked()
{
QSettings settings;
QString startupFolder = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/Startup";
QString installPath = settings.value( INSTALL_PATH, "").toString();
// if path is empty, return
if (installPath.isEmpty() )
return;
QString appPath = installPath+ "\\MyApp.exe";
// if the exe doesn't exist for any reason, return
if( !QFile(appPath).exists() )
return;
QString shortcutName = startupFolder + "/MyApp.lnk";
if ( ui->checkBoxAutoStart->checkState() == Qt::Checked )
{
QFile::link( appPath, shortcutName);
settings.setValue( AUTO_START, "true" );
}
else
{
QFile shortcut( shortcutName);
if ( !shortcut.exists() )
qDebug() << "shortcut don't exist";
int shortcut_permissions = shortcut.permissions();
shortcut.setPermissions(QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ExeUser);
shortcut_permissions = shortcut.permissions();
shortcut.remove();
qDebug() << shortcut.errorString();
settings.setValue( AUTO_START, "false" );
}
}我正在Windows 7上运行这个程序。
更新
创建快捷方式的inno-设置行是这样的(我已经将我的应用程序名称重命名为泛型)。
[Icons]
Name: "{commonstartup}\MyApp"; Filename: "{app}\MyApp.exe"发布于 2015-08-16 07:30:32
TL;DR问题完全在于您的安装程序,以及您错误地认为一个非特权进程(如Qt应用程序)可能会扰乱常见的配置文件快捷键等等。
安装程序确实将其安装在当前用户配置文件中。
这是假的。参考见这里。
在{commonstartup}位置创建的快捷方式应用于所有用户,并且只能由以管理员身份运行的进程进行修改。
如果希望为当前用户创建快捷方式,请在{userstartup}中创建快捷方式,然后以用户权限运行的进程将能够修改该快捷方式。
请注意,仅仅因为在管理帐户上运行,除非强制启动Qt进程,或者设置二进制标志使Windows将其作为管理进程启动,否则Qt进程不会以管理权限运行。
我必须有一个方法,通过应用程序删除快捷方式,使它自动启动或不启动,这是相当标准的。
这在Windows 95上是相当标准的。在Windows上,这是不应该的,但是没有人注意到文档。由于Vista和UAC的到来,如果启动快捷方式在Public帐户(以前的AllUsers)中,就不能通过非管理进程来完成。
此外,您可以轻松地从Explorer中删除或修改该快捷方式,因为您是管理员,但这是因为Explorer具有管理功能。您的Qt进程没有。非管理(默认)命令提示符也不会。
https://stackoverflow.com/questions/32018631
复制相似问题