जैसा कि तमास ने बताया कि आपको ऊंचे अधिकारों के साथ एक नई प्रक्रिया शुरू करने की आवश्यकता है। मैंने अतीत में बहुत कुछ खोजा लेकिन मुझे वर्तमान प्रक्रिया के अधिकारों को बढ़ाने के लिए कोई रास्ता नहीं मिला।
मान लें कि आपका प्राथमिक ऐप App1.exe है और फिर आप द्वितीयक प्रक्रिया App2.exe को कॉल करते हैं जिसके लिए उच्च अधिकारों की आवश्यकता होती है।
ए आप अपने App2.exe में प्रकट एम्बेड कर सकते हैं, लेकिन सरल तरीके से मालसूची फ़ाइल [एक पाठ फ़ाइल] निम्नलिखित सामग्री के साथ App2.exe.manifest नामित बना सकते हैं और इसे डाल करने के लिए है App2.exe के समान निर्देशिका। नोट: !! आश्चर्यजनक रूप से पर्याप्त है, यदि आपके एप्लिकेशन का नाम App2.exe नहीं है, लेकिन App2_install.exe या App2_setup.exe (यानी यदि एप्लिकेशन नाम में "इंस्टॉल" या "सेटअप" होता है) तो एक यूएसी संवाद स्वचालित रूप से विंडोज विस्टा/विंडोज 7 में दिखाई देगा और ऊंचे अधिकारों के लिए पूछेगा यहां तक कि कोई प्रकट फ़ाइल नहीं है !!
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
B. आप App2.exe
QString AppToExec = qApp->applicationDirPath() + "/App2.exe";
// Put any required parameters of App2.exe to AppParams string
QString AppParams = "";
if (0 != genWin32ShellExecute(AppToExec,
"", // default verb: "open" or "exec"
AppParams,
false, // run hidden
true)) // wait to finish
{
// (...) handle error
}
लांच करने के लिए App1.exe में निम्नलिखित की तरह एक कोड का उपयोग कर सकते हैं: इस मैनिफ़ेस्ट फ़ाइल का एक नमूना है। ..
हैडर:
#ifdef Q_OS_WIN // Implement genWin32ShellExecute() especially for UAC
#include "qt_windows.h"
#include "qwindowdefs_win.h"
#include <shellapi.h>
int genWin32ShellExecute(QString AppFullPath,
QString Verb,
QString Params,
bool ShowAppWindow,
bool WaitToFinish);
#endif
और अंत में, इस Win32 समारोह genWin32ShellExecute का कोड() मैं एक प्रक्रिया का शुभारंभ या जब एक Win32 हे/एस पर क्यूटी का उपयोग कर एक दस्तावेज़ को खोलने के लिए बनाया है सीपीपी:
// Execute/Open the specified Application/Document with the given command
// line Parameters
// (if WaitToFinish == true, wait for the spawn process to finish)
//
// Verb parameter values:
// "" The degault verb for the associated AppFullPath
// "edit" Launches an editor and opens the document for editing.
// "find" Initiates a search starting from the specified directory.
// "open" Launches an application. If this file is not an executable file, its associated application is launched.
// "print" Prints the document file.
// "properties" Displays the object's properties.
//
// Ret: 0 = success
// <0 = error
#ifdef Q_OS_WIN
int genWin32ShellExecute(QString AppFullPath,
QString Verb,
QString Params,
bool ShowAppWindow,
bool WaitToFinish)
{
int Result = 0;
// Setup the required structure
SHELLEXECUTEINFO ShExecInfo;
memset(&ShExecInfo, 0, sizeof(SHELLEXECUTEINFO));
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
if (Verb.length() > 0)
ShExecInfo.lpVerb = reinterpret_cast<const WCHAR *>(Verb.utf16());
ShExecInfo.lpFile = NULL;
if (AppFullPath.length() > 0)
ShExecInfo.lpFile = reinterpret_cast<const WCHAR *>(AppFullPath.utf16());
ShExecInfo.lpParameters = NULL;
if (Params.length() > 0)
ShExecInfo.lpParameters = reinterpret_cast<const WCHAR *>(Params.utf16());
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = (ShowAppWindow ? SW_SHOW : SW_HIDE);
ShExecInfo.hInstApp = NULL;
// Spawn the process
if (ShellExecuteEx(&ShExecInfo) == FALSE)
{
Result = -1; // Failed to execute process
} else if (WaitToFinish)
{
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
}
return Result;
}
#endif
यह वास्तव में मुझे था जिसने मेरे शोध के बाद इसे इंगित किया: पी। विस्तृत उत्तर के लिए धन्यवाद। अगर निष्पादन योग्य नाम में स्ट्रिंग "अपडेट" भी शामिल है तो यह यूएसी को भी ट्रिगर करेगा। –
मैंने अपना जवाब संपादित किया और क्रेडिट में अपना नाम डाल दिया :-) मुझे यह कोड स्निपेट प्रकाशित करने का मकसद देने के लिए धन्यवाद देना चाहिए। मुझे याद है कि मुझे कम से कम 1-2 दिन बिताए हैं जब मुझे इस कोड की आवश्यकता थी क्योंकि SO में कोई संबंधित प्रश्न नहीं था। –
धन्यवाद कि आवश्यक नहीं था :)। मैं वास्तव में सराहना करता हूं कि आपने इस विस्तृत उत्तर को लिखने का समय लिया, भले ही प्रश्न पहले से ही एक स्वीकार्य उत्तर था। –