Windows Vista 以降では runas.exe による管理者権限を持つユーザーへの切り替えから管理者権限が落とされるようになりました。
todo
管理者権限を付与する方法を Windows XP と Windows Vista 以降で大きな変更なしに透過的に利用したい。
ランチャーからの実行を想定しています。
todo
- 管理
- Microsoft Application Compatibility Toolkit 5.5
- UAC を切る
- ユーザーに結び付けられた権限
- Windows に関する管理者権限
- アプリケーション
- manifest ファイルによる UAC の指定
- 場面による権限の使い分け
- バッチファイルを作成する
- jscript による簡易な呼び出し
runasuac.js もしくは runasuac.bat の名前で保存してください。ファイル名のつけ方によって動作が若干かわります。後者では cscript から呼び出します。前者では js ファイルの規定のアプリケーションから呼び出します。通常は wscript が使われます。
@if(0)==(0) ECHO OFF CScript.exe //NoLogo //E:JScript "%~f0" %* GOTO :EOF @end usage = function() { msg = '\nusage: runasuac.{js,bat} <runas.exe option...> command "arguents"'; msg += '\n\nexample: runasuac /user:admin cmd.exe "/k"'; WScript.echo( msg ); WScript.quit( 0 ); } fail = function( iPart, e ) { WScript.echo( "failure: part of " + iPart + ": " + e.description ); WScript.quit( 1 ); } argv = WScript.arguments; argc = argv.count(); if ( argc < 1 || argv(0).match( /^[-/][hH?]$/ ) ) { usage(); } command = null; arguments = null; try { command = argv( argc - 2 ); arguments = argv( argc - 1 ); } catch ( e ) { fail( "get command and arguments", e ); } options = ""; try { for( var i = 0; i < argc - 2; i++ ) { options += ( '"' + argv( i ) + '"' ); options += " "; } } catch ( e ) { fail( "join options", e ); } osver = null; try { // List the Operating System Running on a Computer - script center // // Windowsスクリプティング環境比較:PowerShell vs WSH − @IT // http://www.atmarkit.co.jp/fwin2k/operation/pshvswsh/pshvswsh_04.html var strComputer = "."; // var objWbemServices = GetObject( "winmgmts:" + // "{impersonationLevel=impersonate}!\\\\" + strComputer + "\\root\\cimv2" ); var objWbemServices = GetObject( "winmgmts:\\\\" + strComputer ) var objSWbemObjectSet = objWbemServices.ExecQuery( "Select * from Win32_OperatingSystem" ); for( var e = new Enumerator( objSWbemObjectSet ); ! e.atEnd(); e.moveNext() ) { objOperatingSystem = e.item(); osver = objOperatingSystem.version; } osver = parseInt( osver ); // 5.1.2600 -> 5 if ( null == osver ) { throw new Error( null, "unknown." ); } } catch ( e ) { fail( "get os version", e ); } shell = null; try { shell = WScript.CreateObject( "Shell.Application" ); if ( null == shell ) { throw new Error( null, "unknown." ); } } catch ( e ) { fail( "get Shell.Application object", e ); } runas = null; try { // List Items in the System32 Folder - script center // http://gallery.technet.microsoft.com/ScriptCenter/ja-JP/4df28892-1d54-4ae1-8541-4c491c32b99d // Hey, Scripting Guy! VBScript のスクリプトを Windows PowerShell のスクリプトに変換する方法はありますか // http://technet.microsoft.com/ja-jp/scriptcenter/ee692369.aspx SYSTEM = 0x25; var folder = shell.namespace( SYSTEM ); var folderItem = folder.self; var path = ( folderItem.path + "\\runas.exe" ); var fso = WScript.CreateObject( "Scripting.FileSystemObject" ); if ( fso.fileExists( path ) ) { runas = path; } if ( null == runas ) { throw new Error( null, "runas.exe file not found." ); } } catch ( e ) { fail( "find 'runas.exe'", e ); } result = null; try { if ( osver <= 5 ) { // xp or erst a = ( options + '"\\"' + command + '\\" ' + arguments + '"' ); result = shell.shellExecute( runas, a, "", "" ); } else { // vista or later result = shell.shellExecute( command, arguments, "", "runas" ); } } catch ( e ) { fail( "shell execute", e ); } WScript.quit( result );
タグ
コメントをかく