ショートカットを作成プログラムからのC#と入力し、"管理者権限で実行して"プロパティ
質問
い方を知っているのでしたら、さらショートカットを作成プログラムから私C#用 IWshRuntimeLibrary
や WshShellClass
.または使ってみました IShellLink
.
だとすると、ユーザーのPCはWindows VistaまたはWindows7にすればよいのでしょうかを自由に設定できる "管理者として実行" 件のショートカットprogrammacticallyしています。
そんなことが可能なのでしょうか?どうすれば良いですか。
解決
がDougの答えが正しいこうした問題をクリアできるのではないの答えい...
設定する物件。lnk利用する必要があり、 IShellLinkDataList COMインタフェース。のレイモンド-陳いて c++サンプルコードを自分のブログ この
他のヒント
る必要がありま 作成マニフェストファイル お願することが要求として実行管理者特典をご利用いただけます。 ここには素敵なチュートリアルできます。
楽しめます!
この例ではPowerShell、同じオブジェクしてC#.
以下のコードをバイト数activtae:
# Find the missing admin byte (use this code, when changing the link):
$adminon = [System.IO.File]::ReadAllBytes($shortCutLocation)
$adminof = [System.IO.File]::ReadAllBytes($shortCutLocation)
for ($i = 0; $i -lt $adminon.Count; $i++) {
if ($adminon[$i] -ne $adminof[$i]) {
Write-Host Location: $i Value: $($adminon[$i])
}
}
またバイト数21およびその値は34.このスクリプトかユーザー:
# Turning on the byte of "Run as Admin"
$lnkBytes = [System.IO.File]::ReadAllBytes($shortCutLocation)
$lnkBytes[21] = 34
[System.IO.File]::WriteAllBytes($shortCutLocation, $lnkBytes)
この方法を作成できるショートカットで"管理者権限で実行して"プロパティを設定:
void CreateShortcut(string shortcutPath, string sourcePath, bool runAsAdmin, params string[] args)
{
var shortcut = new IWshShell_Class().CreateShortcut(shortcutPath) as IWshShortcut;
shortcut.TargetPath = System.IO.Path.GetFullPath(sourcePath);
shortcut.Arguments = "\"" + string.Join("\" \"", args) + "\"";
shortcut.Save();
if (runAsAdmin)
using (var fs = new FileStream(shortcutPath, FileMode.Open, FileAccess.ReadWrite))
{
fs.Seek(21, SeekOrigin.Begin);
fs.WriteByte(0x22);
}
}
信用用として実行管理部門に所属 こちらの
所属していません StackOverflow