wpz Posted September 25, 2009 Share Posted September 25, 2009 Hi supporters, I am logged on as a normal User and I want to start serveral Admin-Tools with my Dom-Admin-Credentials. Therfore I tried to use this code: $ret = RunAs ( $USER, $DOMAIN, $PW, 1, $CmdLine[1], @ScriptDir ) ; The $variables are filled correctly! This is working fine, if I let from the explorer the real exe-file fall onto the compiled AutoItScript-Icon. But unfortunately on my desktop are only the links (lnk-files) for the admin-tools and if I draw one of this lnk-Files to the AutoIt-RunAs-Programm-Shortcut nothing happens. Do you have any idea how I can get this problem solved? Thanks a lot Wolfgang Link to comment Share on other sites More sharing options...
jvanegmond Posted September 25, 2009 Share Posted September 25, 2009 http://www.autoitscript.com/forum/index.php?showtopic=33098 github.com/jvanegmond Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted September 25, 2009 Share Posted September 25, 2009 I would do a check with StringRight() to see if it is a lnk and if it is use FileGetShortcut() to get the real paths. Something like this If StringRight(string, 4) = ".lnk" then $car = FileGetShortcut() Run($car) Else Run(string) Pseudocode FTW .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
GEOSoft Posted September 25, 2009 Share Posted September 25, 2009 (edited) Here is some example usage of a function I use for shortcuts since FileGetShortcut() does not work with .url files. ClipPut("") $hSearch = FileFindFirstFile(@DesktopDir & "\*") If $hSearch <> -1 Then While 1 $sFile = FileFindNextFile($hSearch) If @Error Then ExitLoop ClipPut(ClipGet() & _GetShortcut($sFile) & @CRLF) WEnd FileClose($hSearch) EndIf Func _GetShortcut($sCheck) ;; $sCheck = FULL path and filename If NOT StringRegExp(StringRight($sCheck, 4), "(?i)\.(url|lnk)") Then Return $sCheck Local $aShortcut = FileGetShortcut($sCheck) If NOT @Error Then Return $aShortcut[0] Return IniRead($sCheck, "InternetShortCut", "URL", "") EndFunc Edited September 25, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
GEOSoft Posted September 25, 2009 Share Posted September 25, 2009 Oooops. Just found this old one too which actually may be better for you so I just changed the example usage. $sClip = "" $hSearch = FileFindFirstFile(@DesktopDir & "\*") If $hSearch <> -1 Then While 1 $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If _File_IsLink($sFile) Then $sClip &= _File_GetShortcut($sFile) & @CRLF WEnd FileClose($hSearch) ClipPut(StringStripWS($sClip, 2)) EndIf Func _File_GetShortcut($sCheck) ;; $sCheck = FULL path and filename Local $aShortcut = FileGetShortcut($sCheck) If Not @error Then Return $aShortcut[0] Return IniRead($sCheck, "InternetShortCut", "URL", "") EndFunc ;==>_File_GetShortcut Func _File_IsLink($sCheck) ;; $sCheck = FULL path and filename If StringRegExp($sCheck, "(?i)\.(url|lnk)") Then Return 1 Return 0 EndFunc ;==>_File_IsLink George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
wpz Posted September 29, 2009 Author Share Posted September 29, 2009 Thank you for your input, now I have this working solution. The problem was, that a link can contain a real exe-file but it also can contain a filetype like msc or xls .... Unfortunately there is no "ShellExecute" with "RunAs": If (StringLower($tmp) == ".lnk") then $CMD = FileGetShortcut($CmdLine[1]) If ($CMD[2] > "" ) Then $tmp = $CMD[0] & " " & $CMD[2] Else $tmp = $CMD[0] EndIf If ($CMD[1] > "" ) Then $WDIR = $CMD[1] Else $WDIR = @SystemDir EndIf $tmp2 = StringRight($tmp, 4) If (StringLower($tmp2) == ".exe") Then $CLINE = $tmp $SHOWFLAG = "" Else $CLINE = @COMSPEC & " /C " & $tmp $SHOWFLAG = @SW_HIDE EndIf $ret = RunAs ( $USER, "NVG", $PW, 4, $CLINE, $WDIR, $SHOWFLAG ) EndIf If you know a better solution, I would like to know it. Best regards Wolfgang Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now