0

I have an application's shortcut on the desktop; the application works different according to the user permissions. What I want is to call the shortcut from the less privilegiated user and automatically access to the admin account hidding the admin's password to the current user. In this way, the normal user will have access to more options in the application without knowing another user's account data.

I have tried creating bat files, but the password can be seen easily. I am looking the way to do it with VB but I'm not sure if this is the best option. This software does what I want, the thing is that isn't free.

https://4sysops.com/archives/run-a-program-with-administrator-rights-runasspc-cpau-and-steel-run-as-compared/ http://www.robotronic.de/runasspcEn.html

Thanks for the help.

4
  • Why not just give the normal user the requisite privileges?
    – RB.
    Sep 14, 2016 at 20:25
  • However, if you want to write a program to do this, one place to start would be investigating the Windows DPAPI (Data Protection API). This allows you to encrypt passwords and things based on a key specific to that machine. Typically, you set and encrypt the passwords at install time.
    – RB.
    Sep 14, 2016 at 20:28
  • @RB. can't give the normal user the privilages because the admin account uses another applications, and talking about system, only one admin account is admitted. I want the normal user only to have permission for 1 application, and as you can imagine, its a trouble to call the administrator each time normal user wants to execute it.
    – iaredi
    Sep 14, 2016 at 20:45
  • You could execute the app using the command line runas with /savecred. You have to enter the admin password only once and it'll continue to run. However there are a load of security issue surrounding it so do some research before using this approach. Sep 14, 2016 at 23:00

1 Answer 1

0
#Create a Desktop Shortcut with Windows PowerShell
If(!$ShortcutFileName)
{
    $ShortcutFileName = (Get-Item $TargetFile).Basename
}
$ShortcutFile = "$env:Public\Desktop\$ShortcutFileName.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
#Run as different user, saves the password  
$a="runas.exe /savecred /user:$RunAsUser ""$TargetFile"""
$Shortcut.TargetPath = "runas.exe"
$Shortcut.Arguments = "/savecred /user:$RunAsUser ""$TargetFile"""
$Shortcut.IconLocation = $TargetFile
$Shortcut.Save()  

You can download detail SQL script from how to create a shortcut to run an application as a different user(PowerShell)

1
  • While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.
    – DimaSan
    Dec 13, 2016 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.