![](/img/trans.png)
[英]How to do tutorial in app and launch it just on first start up in Xamarin?
[英]How to launch app at start as administrator?
我的問題很簡單。 我找不到兩個問題的解決方案。 我的問題是在啟動時在沒有管理員許可的情況下啟動程序。 我只想獲取安裝程序的管理員權限。 我正在使用regedit在啟動程序時啟動我的程序,而沒有管理員權限。 如果我嘗試授予應用清單的管理員權限,則程序不會在啟動時啟動。 我該如何解決呢? 另外程序需要一個GUI,所以我不能使用服務。 謝謝您的幫助。
有我的啟動代碼
private void SetStartup()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (chkStartUp.Checked)
{
rk.SetValue("_connectorEthernet", Environment.CurrentDirectory + @"\_connectorEthernet");
WriteToSettingFile("true");
}
else
{
rk.DeleteValue("_connectorEthernet", false);
WriteToSettingFile("false");
}
}
好吧,我想我解決了。 首先我做了
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
對於程序在啟動時啟動。 如果不這樣做,該程序將不會啟動。
之后,我在解決方案資源管理器窗口中使用settings.setting。
這是為了獲取設置
chkStartUp.Checked = Properties.Settings.Default.chk;
這是用於更改和保存設置
Properties.Settings.Default.chk = true;
Properties.Settings.Default.Save();
最后,此代碼用於以管理員身份運行cmd並獲得響應。
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "netsh.exe",
Arguments = "lan reconnect",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true,
Verb = "runas"
}
};
proc.Start();
string line = proc.StandardOutput.ReadToEnd();
MessageBox.Show(line);
這就是我解決問題的方式。 希望對其他人有幫助。 如果您還有其他想法,請與我聯系。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.