我在Npackd中使用以下脚本来卸载 Dropbox。它适用于 XP 和 Vista,但在 Windows 7/64 上失败。它不显示任务栏(通常位于屏幕底部的任务栏),而是显示一个 Windows 资源管理器窗口,其内容为 C:/。这与 Dropbox 无关,因为删除具有基于 DLL 的外壳扩展的其他包也显示出相同的效果。
Uninstall.exe /S _?=%CD%
taskkill /f /fi "IMAGENAME eq explorer.exe"
del DropboxExt.13.dll
del DropboxExt64.13.dll
rem start explorer from the root directory so it does not lock this one
start "" /D\ explorer.exe
脚本有什么问题?如何修改它以在 Windows 7 上正常工作?
谢谢
编辑:我真的厌倦了这个问题。以下批处理文件以普通用户或“以管理员身份”启动:
taskkill /f /fi "IMAGENAME eq explorer.exe"
ping -n 5 127.0.0.1
pushd \
rem runas /trustlevel:0x20000
start "" /D\ explorer.exe
popd
这是从我的程序启动 .bat 的代码(path="Uninstall.bat",只定义了 2 个新的环境变量):
QDir d = this->getDirectory();
QProcess p(0);
p.setProcessChannelMode(QProcess::MergedChannels);
QStringList params;
p.setWorkingDirectory(d.absolutePath());
QString exe = d.absolutePath() + "\\" + path;
for (int i = 0; i < env.count(); i += 2) {
p.processEnvironment().insert(env.at(i), env.at(i + 1));
}
p.start(exe, params);
Qt/qprocess_win.cpp中对应的代码:
DWORD dwCreationFlags = CREATE_NO_WINDOW;
dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
STARTUPINFOW startupInfo = { sizeof( STARTUPINFO ), 0, 0, 0,
(ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
(ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
0, 0, 0,
STARTF_USESTDHANDLES,
0, 0, 0,
stdinChannel.pipe[0], stdoutChannel.pipe[1], stderrChannel.pipe[1]
};
success = CreateProcess(0, (wchar_t*)args.utf16(),
0, 0, TRUE, dwCreationFlags,
environment.isEmpty() ? 0 : envlist.data(),
workingDirectory.isEmpty() ? 0 : (wchar_t*)QDir::toNativeSeparators(workingDirectory).utf16(),
&startupInfo, pid);
为什么资源管理器认为已经有任务栏了?
EDIT2:我知道现在出了什么问题。终止资源管理器后,svchost.exe 进程会使用以下参数自动启动一个新的资源管理器:/factory,{682159d9-c321-47ca-b3f1-30e36b2ec8b9}。GUID 用于 DesktopExplorerFactory。这可能是 COM 服务的崩溃保护。我对 explorer.exe 的调用不会启动新的 Explorer,因为已经有一个。一两分钟后,如果没有打开任何窗口,此过程将自动关闭。所以我认为 Ben Voigt 是对的,“真的没有什么好的方法可以在不注销所有用户的情况下完全卸载 shell。”