Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29230 Discussions

Runing external tools with admin rights

netphilou31
New Contributor III
2,998 Views

Dear all,

I don't know if this forum is the right place for this question (probably not) but I am looking for a way to run external tools in DeveloperStudio with admin rights. I my project, I generate a dll that needs to be copied into a directory with is located Inside the "Program Files" folder and because of the UAC I need to  enter the admin ID and password. I don't want to remove the UAC feature (because of our internal Policy).

Is there a way to do that ?

Best regards,

 

0 Kudos
1 Solution
netphilou31
New Contributor III
2,998 Views

Hi,

I am coming back to inform you that I have found a small tool that can be used to run scripts with elevated rights.

For those who are interested it is available at the following address:

http://code.kliu.org/misc/elevate/

And It does exactly what I was looking for, I have just created a new external tool that makes use of the elevate.exe app with passing the command line I needed to run.

Best regards,

View solution in original post

0 Kudos
15 Replies
FortranFan
Honored Contributor III
2,998 Views

Conventional wisdom, as you know, says not to copy files, especially DLLs, to "Program Files" folder directly.  Instead it is better to have some sort of installer (which has the corresponding uninstall functionality also) that performs such steps.  If this need is just for testing, you can create a test folder and add it to the Windows path ahead of the "Program files" folder and it can normally be empty.  However when testing, it can include the relevant DLLs that then picked up for the unit tests ahead of those in "Program Files".  

Now to copy DLLs to a particular folder following build, a post-build event can be added to the Visual Studio project (under project Properties -> Build Events -> Post-build events) to accomplish this.  If you must have the destination to be a "Program Files" folder, you can try running the Visual Studio with admin rights (e.g., with "Run as Administrator" option) and see if that helps. 

0 Kudos
netphilou31
New Contributor III
2,998 Views

Hi,

Thanks for your answer. I understand your point of view related to using an installer, however I may have to perform the copy a lot of times (for every build in fact) and I cannot use this way. Unfortunately I neither can not use a test folder because I cannot change the location of these files (they must be placed in the Common files folder). I know that I could run VisualStudio with admin rights but this is not what I wanted to do. I rather wanted to know if there was a way to set up admin rights for external Tools that you can run from the Tools menu.

Best regards,

0 Kudos
Steven_L_Intel1
Employee
2,998 Views

Not that I know of. Seems like a very dangerous thing to do. What is it about your test environment that mandates use of Common Files?

0 Kudos
netphilou31
New Contributor III
2,998 Views

Hi Steve,

The files I build in my VisualFortran project belong to a software we are developping. Whatever the place where it is installed, some files are copied to a subfolder of the "Common files" folder located in the Program files directories (one for each 32 bit and 64 bit versions). I cannot change this. For the other software we are developing I can change the installation folder so I can copy easily the files there but not for this one. I can do this copy automatically by using a batch file ran as administrator but I wanted to automate this a little bit more (I have several projects generating files that must be copied in these folders).

Best regards,

0 Kudos
Steven_L_Intel1
Employee
2,998 Views

I'm not even sure that running VS with admin rights would do it, but maybe. Did that work for you? Seems the most straightforward and least dangerous solution.

0 Kudos
netphilou31
New Contributor III
2,998 Views

I never tried myself but some of my colleagues use this way successfuly.

I use this feature with a sofwtare we use to automate builds (FinalBuilder from VSoft) and it works perfectly.

Thanks.

0 Kudos
FortranFan
Honored Contributor III
2,998 Views

netphilou31 wrote:

... I rather wanted to know if there was a way to set up admin rights for external Tools that you can run from the Tools menu.

You can try running a command batch file from External Tools option which invokes a shortcut for the actual tool and this shortcut can have the "Run as Administrator" option checked.

0 Kudos
netphilou31
New Contributor III
2,998 Views

Hi,

Thanks for the suggestion, it worked perfectly. I still have to figure out how to the gather the output but I should find a way.

Best regards,

0 Kudos
netphilou31
New Contributor III
2,998 Views

Hi

Ultimately, even if it seemed to work, it wasn't the case. It is possibly because I created a BAT file which launched a .lnk file which in turn launched a vbs script and the admin rights don't seems to be inherited.

Ultimately, I think I will still have to copy the files manually (even because the vbs file cannot be run as admin).

Best regards and thanks for your comments and advices,

Phil.

 

0 Kudos
andrew_4619
Honored Contributor III
2,998 Views

You create a last in the task scheduler that has admin rights option ticked, you then create a shortcut to that task schedule and invoke the shortcut as a post build event.

If you Google you will find detailed instructions somewhere.

I did something similar recently to run lockhunter to unlock   locked VS pdb files.

0 Kudos
netphilou31
New Contributor III
2,998 Views

Thanks,

I will try that

Best regards,

0 Kudos
FortranFan
Honored Contributor III
2,998 Views

netphilou31 wrote:

Hi

Ultimately, even if it seemed to work, it wasn't the case. It is possibly because I created a BAT file which launched a .lnk file which in turn launched a vbs script and the admin rights don't seems to be inherited.

Ultimately, I think I will still have to copy the files manually (even because the vbs file cannot be run as admin).

Best regards and thanks for your comments and advices,

Phil.

 

Well, if you're running a VB script, then you can simply add the following to the beginning of your vbs file and invoke it as a post-build event from Visual Studio:

  Set WshShell = WScript.CreateObject("WScript.Shell")
  If WScript.Arguments.length = 0 Then
  Set ObjShell = CreateObject("Shell.Application")
  ObjShell.ShellExecute "wscript.exe", """" & _
  WScript.ScriptFullName & """" &_
  " RunAsAdministrator", , "runas", 1
  End if

 

0 Kudos
netphilou31
New Contributor III
2,998 Views

That's a good idea.

However

  1: Do you mean a script that runs another one ?

  2:: I absolutely need to pass an argument to the VBScript I want to run (the name of the project).

Thanks

0 Kudos
netphilou31
New Contributor III
2,998 Views

I have tried the following code

Set ObjShell = CreateObject("Shell.Application")
strParams= "V:\Update.vbs " & WScript.Arguments(0) & " RunAsAdministrator"
ObjShell.ShellExecute "wscript.exe", strParams, "", "runas", 1

It seemed to works, because I have been asked to login as admin and I could see some message boxes I have put in the Update.vbs script, but when the script tried to copy the files into the destination folder (C:\Program Files (x86)\...) I get a VBS error "Permission denied".

Best regards,

0 Kudos
netphilou31
New Contributor III
2,999 Views

Hi,

I am coming back to inform you that I have found a small tool that can be used to run scripts with elevated rights.

For those who are interested it is available at the following address:

http://code.kliu.org/misc/elevate/

And It does exactly what I was looking for, I have just created a new external tool that makes use of the elevate.exe app with passing the command line I needed to run.

Best regards,

0 Kudos
Reply