Hiho,
falls jmd sowas gebrauchen kann. hintergrund:
ich habe auf der arbeit nur eingeschränkte recht, jedoch auch einen admin user. hin und wieder brauche ich diesen, sei es als cmd, explorer oder um dateien zu installieren. leider geht zB. bei msi-dateien kein "rechtsklick - ausführen als" (dann muss ich die datei über cmd/explorer mit adminrechten starten).
dabei ist es nervig, immer das pw einzugeben.
jetzt läuft im systray dieses tool, mit dem man schnell die cmd, den explorer oder bestimmte dateien mit adminrechten starten kann. diese werden einmal eingegeben und dann gespeichert.
klein aber ... aber erfüllt meinen/seinen zweck =)
[autoit]#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=RunAsA.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <String.au3>
#include <Process.au3>
#include <array.au3>
Opt("TrayAutoPause",0) ;0=no pause, 1=Pause
Opt("TrayIconDebug", 0) ;0=no info, 1=debug line info
Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon
Opt("TrayMenuMode",1) ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return
Opt("TrayOnEventMode",1) ;0=disable, 1=enable
Dim $data[2]
$key = "1234"
If Not FileExists("Settings.ini") Then
$User = InputBox("Admin", "Please enter the Admin-User ID", "", "", Default, 50)
If $User = "" Or @error Then Exit
$Pw = InputBox("Password", "Please enter the Admin-User PW", "", "*", Default, 50)
If $Pw = "" Or @error Then Exit
IniWrite("Settings.ini", "Data", "User", _StringEncrypt(1, $User, $key, 4))
IniWrite("Settings.ini", "Data", "Password", _StringEncrypt(1, $Pw, $key, 4))
EndIf
TrayCreateItem("Admin CMD")
TrayItemSetOnEvent(-1, "_CMD")
TrayCreateItem("Admin Explorer")
TrayItemSetOnEvent(-1, "_EXP")
TrayCreateItem("Run As Admin")
TrayItemSetOnEvent(-1, "_RunAs")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")
While 1
Sleep(100)
WEnd
Func _CMD()
_GetData()
RunAs($data[0], @ComputerName, $data[1], 0, @ComSpec, @SystemDir)
_ClearData()
EndFunc
Func _EXP()
_GetData()
RunAs($data[0], @ComputerName, $data[1], 0, "explorer.exe", @SystemDir)
_ClearData()
EndFunc
Func _RunAs()
$File = FileOpenDialog("File", @DesktopCommonDir, "Executables (*.exe;*.msi;*.bat;*.cmd)")
If Not $File = "" Or @error Then
$Split = _PathSplit1($File)
If Not @error Then
_GetData()
If $Split[7] = "msi" Then
FileDelete(@TempDir & "\runmsi.bat")
$sCmdFile = '@echo off' & @CRLF _
& '"' & $File & '"' & @CRLF _
& 'del ' & @TempDir & '\runmsi.bat'
FileWrite(@TempDir & "\runmsi.bat", $sCmdFile)
$File = @TempDir & "\runmsi.bat"
RunAs($data[0], @ComputerName, $data[1], 0, $File, @TempDir)
Exit
Else
RunAs($data[0], @ComputerName, $data[1], 0, $Split[5], $Split[2])
EndIf
EndIf
EndIf
_ClearData()
EndFunc
Func _GetData()
$data[0] = _StringEncrypt(0, IniRead(@ScriptDir & "\Settings.ini", "Data", "User", ""), $key, 4)
$data[1] = _StringEncrypt(0, IniRead(@ScriptDir & "\Settings.ini", "Data", "Password", ""), $key, 4)
Return $data
EndFunc
Func _ClearData()
Dim $data[2]
EndFunc
Func _Exit()
Exit
EndFunc
;===============================================================================
; Function Name: _PathSplit1()
; Description: Split the path to 8 elements.
; Parameter(s): $sPath - Path to split.
; Requirement(s): AutoIt 3.2.2.0.
; Return Value(s): On seccess - Array $RetArray that contain 8 elements:
; $RetArray[0] = Full path ($sPath)
; $RetArray[1] = Drive letter
; $RetArray[2] = Path without FileName and extension
; $RetArray[3] = Full path without File Extension
; $RetArray[4] = Full path without drive letter
; $RetArray[5] = FileName and extension
; $RetArray[6] = Just Filename
; $RetArray[7] = Just Extension of a file
;
; On failure - If $sPath not include correct path (the path is not splitable),
; then $sPath returned.
; If $sPath not include needed delimiters, or it's emty,
; then @error set to 1, and returned -1.
;
; Note(s): The path can include backslash as well (exmp: C:/test/test.zip).
;
; Author(s): G.Sandler a.k.a CreatoR (MsCreatoR) - Thanks to amel27 for help with RegExp
;===============================================================================
Func _PathSplit1($sPath)
If $sPath = "" Or StringRegExp($sPath, ('.*\\.*\/')) Then Return SetError(1, 0, -1)
Local $RetArray[8], $pDelim = ""
If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+$') Then $pDelim = "\"
If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+$') Then $pDelim = "//"
If $pDelim = "" Then $pDelim = "/"
If Not StringInStr($sPath, $pDelim) Then Return $sPath
If $pDelim = "\" Then $pDelim &= "\"
$RetArray[0] = $sPath
$RetArray[1] = StringRegExpReplace($sPath, $pDelim & '.*', $pDelim)
$RetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']*$', '')
$RetArray[3] = StringRegExpReplace($sPath, '\.[^.]*$', '')
$RetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & ')', '')
$RetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '')
$RetArray[6] = StringRegExpReplace($RetArray[5], '\.[^.]*$', '')
$RetArray[7] = StringRegExpReplace($sPath, '^.*\.', '')
Return $RetArray
EndFunc ;==>_PathSplit1