Jump to content
rudi

Create a File Shortcut with advance option "Run ad administrator" checked

Recommended Posts

rudi

Hello.

Windows shortcuts have the option to check "Run as administrator" in the "advanced settings" on the tab "Shortcut"

 

  1. Is it possible to use the function FileCreateShortcut() to define this? Or to use this function and modify this option afterwards?
  2. Is it possible to "read" this option's current state for a given LNK file? (FileGetShortcut() doesn't seem to offer that?)

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
gruntydatsun

 

Share this post


Link to post
Share on other sites
rudi

Hi,

thanks for your reply.

 

HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

 

Wasn't aware that this place in the registry does exist.

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
rudi

Hello.

at that Registry Key it looks like, that values with the name "EXE-full-file-path-name" are created at the moment, that EXE was started for a first time.

Example:

RegistryValue (REG_SZ)
"H:\DATEN\PUBLIC\Kataloge\Festo\DKI3\xDKIBrowser.EXE" = "DisableNXShowUI"

Where the "Checkbox" status is stored, I couldn't figure out so far.

Modifyiong the CheckBox status doesn't seem to alter the according registry value, even not if the EXE is started again.

 

Any suggestions?

 

 

Regards, Rudi.

Edited by rudi
typo

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
Juvigy

Why would you need to create a shortcut with autoit to run as admin when you can just runas with elevated credentials?

Share this post


Link to post
Share on other sites
JLogan3o13

@Juvigy There could be a number of reasons. I have done it often when pushing out a shortcut to 1000 desktops through a deployment suite like SCCM. 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Earthshine

well, it's been done... apparently you can do it with a registry entry. http://forums.winamp.com/showthread.php?t=278764

Quote

OK, I am not sure if there is something is wrong with this method, but I came across this and have not seen a reference to it anywhere on NSIS forum. I think it is way easier than anything else proposed here and seems to work great.

Basically the "Run As Administrator" is simply a registry value stored in "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\layers" , so you can use:
 


code:


WriteRegStr HKLM "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\layers" \
"$MY_SHORCUT_OR_EXE" "RUNASADMIN"



Obviously replace $MY_SHORCUT_OR_EXE with your executable or shortcut. You can replace HKLM with HKCU for user specific setting instead of all users.


I figured I'd share.

-HH

 


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
rudi

Thanks for your replies.

I'm still not really seeing where the *CHECKBOX STATUS* is instantly stored, without running the associated EXE at least once.

 

Meanwhile the vendor of this catalog software has provided a bug fix, so that the need to be run with "as Administrator" is eliminated. It's a new version of a file named xDKIFrameworkComponents.bpl

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
KaFu
rudi

Thanks for your replies.

I'm still not really seeing where the *CHECKBOX STATUS* is instantly stored, without running the associated EXE at least once.

 

Meanwhile the vendor of this catalog software has provided a bug fix, so that the need to be run with "as Administrator" is eliminated. It's a new version of a file named xDKIFrameworkComponents.bpl

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
KaFu
14 hours ago, rudi said:

I'm still not really seeing where the *CHECKBOX STATUS* is instantly stored, without running the associated EXE at least once.

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", @ScriptFullPath, "REG_SZ", "RUNASADMIN")

Share this post


Link to post
Share on other sites
Danyfirex

Hello You can do this:

 

Local $sShortcut = "C:\Users\User\Desktop\someshortcut.lnk"

_SetShortcutRunAsAdmin($sShortcut);Enable-Set advanced settings  Run as administrator true
;~ _SetShortcutRunAsAdmin($sShortcut,False);Disable-Set advanced settings  Run as administrator false

Func _SetShortcutRunAsAdmin($sShortcutFullPath, $bRunAsAdmin = True)
    Local $hFile = FileOpen($sShortcutFullPath, 17)
    FileSetPos($hFile, 21, 0)
    FileWrite($hFile, $bRunAsAdmin ? 0x20 : 0x00)
    FileClose($hFile)
EndFunc   ;==>_SetShortcutRunAsAdmin

 

Saludos

  • Like 1

Share this post


Link to post
Share on other sites
rudi

@Danyfirex

thanks, I'll try that one, looks great.

Where from did you grab the information for that offset within the LNK file?

 

Regards, Rudi.

 


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
Danyfirex

I found that trick time ago in stack overflow written in another lenguage. I don't remeber the thread. 

 

Saludos

  • Like 1

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • meows
      By meows
      236 This works perfect for desktop shortcuts
      $ink = "\cleaner.lnk" $cmd = "C:\AutoIt3\Code\00_Trials\Installer\Cleaner.exe" $icon = "C:\32.ico"                    ; & "\au3", FileCreateShortcut($cmd , @DesktopDir & $ink  , @ScriptDir, "", "Tooltip description of the shortcut.", $icon,  @SW_MINIMIZE) This works perfect for the Program Files Menu
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> $cmd = "C:\AutoIt3\Code\00_Trials\Installer\Cleaner.exe" $icon = "C:\32.ico" $ink = "\cleaner.lnk" FileCreateShortcut($cmd , @ProgramsDir & $ink  , @ScriptDir, "", "Tooltip description of the shortcut.", $icon,  @SW_MINIMIZE) However this has me so confused and dazed I had to change DishNet to Sirius 60's/70's Motown to chill.
      My problem is I have confirmed variables for each section of the script but it does not put the variable in the correct place or it ignores it altogether,
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> Global $ifullpath Global $iicoFile Global $iSoftTitle Global $iincFile Global $incthing ;------------------$cmd = "C:\00test_Installer\00bons1.exe" $cmd = $ifullpath ;------------------$icon = "C:\32.ico" $icon = $iicoFile ;----------------------------$ink = "\file.ini" $ink = $incthing ;------------------------- $iSoftTitle = \SoftTitle.ini $Tooltip = $iSoftTitle IniRead(@ScriptDir & "\SoftTitle.ini", "General", ".", $iSoftTitle) Local $iSoftTitle = IniRead(@ScriptDir & "\SoftTitle.ini", "General", ".", "") MsgBox(4096,"$iSoftTitle", $iSoftTitle) ; Retrieve the system environment variable called %PATH%. Local $sEnvVar = EnvGet("PATH") ; Assign the system environment variable called %PATH% with its current value as well as the script directory. ; When you assign an environment variable you do so minus the percentage signs (%). EnvSet("PATH", $sEnvVar & ";" & @ScriptDir) ; Refresh the OS environment for changes to take affect. EnvUpdate() IniRead(@ScriptDir & "\fullpath.ini", "General", ".", $ifullpath) Local $ifullpath = IniRead(@ScriptDir & "\fullpath.ini", "General", ".", "") MsgBox(4096,"$ifullpath", $ifullpath) Local $sEnvVar = EnvGet("PATH") ; Assign the system environment variable called %PATH% with its current value as well as the script directory. ; When you assign an environment variable you do so minus the percentage signs (%). EnvSet("PATH", $sEnvVar & ";" & @ScriptDir) ; Refresh the OS environment for changes to take affect. EnvUpdate() IniRead(@ScriptDir & "\icoFile.ini", "General", ".", $iicoFile) Local $iicoFile = IniRead(@ScriptDir & "\icoFile.ini", "General", ".", "") MsgBox(4096,"$iicoFile", $iicoFile) Local $sEnvVar = EnvGet("PATH") ; Assign the system environment variable called %PATH% with its current value as well as the script directory. ; When you assign an environment variable you do so minus the percentage signs (%). EnvSet("PATH", $sEnvVar & ";" & @ScriptDir) ; Refresh the OS environment for changes to take affect. EnvUpdate() IniRead(@ScriptDir & "\File.ini", "General", ".", $iincFile) Local $iincFile = IniRead(@ScriptDir & "\File.ini", "General", ".", "") MsgBox(4096,"$iincFile", $iincFile) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"\" & $iincFile &".ink" = $incthing $incthing=("\" & $iincFile &".ink") MsgBox(4096,"$incthing", $incthing) FileCreateShortcut($cmd , @ProgramsDir & $ink , @ScriptDir, "", $Tooltip, $icon, @SW_MINIMIZE) This does make a programfiles menu item
      The target is Computer and not the var $Cmd
      The start in is the correct directory
      It added a shortcut key! that I did not add
      It ignored the comment altogether and that is empty
      and the wrong icon.

      Are there different rules if you use a variable instead of a text string?
      Thanks for looking.
      Oh yes I almost forgot, I use this fancy piece of code I found in the forums one day that really saved me.
      I could not get things straight bouncing between things and put this in and all of a sudden the path I wanted was there,
      I do apologize as I do not remember who posted it
      Local $sEnvVar = EnvGet("PATH") ; Assign the system environment variable called %PATH% with its current value as well as the script directory. ; When you assign an environment variable you do so minus the percentage signs (%). EnvSet("PATH", $sEnvVar & ";" & @ScriptDir) ; Refresh the OS environment for changes to take affect. EnvUpdate()
    • YGYL
      By YGYL
      when i use WIN2012,my computer name is SERVER
      FileCreateShortcut(@WindowsDir & "explorer.exe", "1.lnk", @WindowsDir, "/e,c:", "Tooltip description of the shortcut.", "servershell32.dll", "^!t", "15", @SW_MINIMIZE)
      "servershell32.dll" will be auto change to  %COMPUTERNAME%shell32.dll
      if use Another PC of WIN8 to open this lnk,the LNK ico can't be Correct read
×