Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to open applications as admin #305

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/Classes/ProgramShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class ProgramShortcut
{
public string FilePath { get; set; }
public bool isWindowsApp { get; set; }

public bool openAsAdmin;
public string name { get; set; } = "";
public string Arguments = "";
public string WorkingDirectory = MainPath.exeString;
Expand Down
239 changes: 149 additions & 90 deletions main/Forms/frmGroup.Designer.cs

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions main/Forms/frmGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ public void LoadShortcut(ProgramShortcut psc, int position)
Shortcut = psc,
Position = position,
};

pnlShortcuts.Controls.Add(ucPsc);
ucPsc.Show();
ucPsc.BringToFront();

openAsAdmin.Checked = psc.openAsAdmin;

if (pnlShortcuts.Controls.Count < 6)
{
pnlShortcuts.Height += 50;
Expand Down Expand Up @@ -863,5 +866,15 @@ private void frmGroup_MouseClick(object sender, MouseEventArgs e)
{
resetSelection();
}

private void openAsAdmin_CheckedChanged(object sender, EventArgs e)
{
if (selectedShortcut == null || Category.ShortcutList.Count < selectedShortcut.Position)
{
return;
}

Category.ShortcutList[selectedShortcut.Position].openAsAdmin = openAsAdmin.Checked;
}
}
}
19 changes: 13 additions & 6 deletions main/Forms/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private void BuildShortcutPanel(int x, int y, ProgramShortcut psc)
this.shortcutPic.BackgroundImage = ThisCategory.loadImageCache(psc); // Use the local icon cache for the file specified as the icon image
this.shortcutPic.BackgroundImageLayout = ImageLayout.Stretch;
this.shortcutPic.TabStop = false;
this.shortcutPic.Click += new System.EventHandler((sender, e) => OpenFile(psc.Arguments, psc.FilePath, psc.WorkingDirectory));
this.shortcutPic.Click += new System.EventHandler((sender, e) => OpenFile(psc));
this.shortcutPic.Cursor = System.Windows.Forms.Cursors.Hand;
this.shortcutPanel.Controls.Add(this.shortcutPic);
this.shortcutPic.Show();
Expand All @@ -335,13 +335,20 @@ private void BuildShortcutPanel(int x, int y, ProgramShortcut psc)
}

// Click handler for shortcuts
public void OpenFile(string arguments, string path, string workingDirec)
public void OpenFile(ProgramShortcut psc, string mainPath = null)
{
// starting program from psc panel click
ProcessStartInfo proc = new ProcessStartInfo();
proc.Arguments = arguments;
proc.FileName = path;
proc.WorkingDirectory = workingDirec;
var proc = new ProcessStartInfo
{
Arguments = psc.Arguments,
FileName = mainPath ?? psc.FilePath,
WorkingDirectory = psc.WorkingDirectory
};

if (psc.openAsAdmin)
{
proc.Verb = "runas";
}

/*
proc.EnableRaisingEvents = false;
Expand Down
5 changes: 2 additions & 3 deletions main/User controls/ucShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ public void ucShortcut_Click(object sender, EventArgs e)
} else
{
if(Path.GetExtension(Psc.FilePath).ToLower() == ".lnk" && Psc.FilePath == MainPath.exeString)

{
MotherForm.OpenFile(Psc.Arguments, Psc.FilePath, MainPath.path);
MotherForm.OpenFile(Psc, MainPath.path);
} else
{
MotherForm.OpenFile(Psc.Arguments, Psc.FilePath, Psc.WorkingDirectory);
MotherForm.OpenFile(Psc);
}
}
}
Expand Down
21 changes: 17 additions & 4 deletions main/client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -23,12 +25,11 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -53,6 +54,18 @@
<PropertyGroup>
<ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>C7D4586BFEB63E9F4FA660C4A372DDEC996746B3</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>client_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="ChinhDo.Transactions.FileManager, Version=1.4.0.36, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\TxFileManager.1.4.0\lib\netstandard2.0\ChinhDo.Transactions.FileManager.dll</HintPath>
Expand Down Expand Up @@ -160,6 +173,7 @@
<EmbeddedResource Include="User controls\ucShortcut.resx">
<DependentUpon>ucShortcut.cs</DependentUpon>
</EmbeddedResource>
<None Include="client_TemporaryKey.pfx" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down Expand Up @@ -199,7 +213,6 @@
</ItemGroup>
<ItemGroup>
<Content Include="Icon.ico" />
<Content Include="Taskbar groups icon.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Add.png" />
Expand Down