简体   繁体   中英

Can I run a program from visual studio without elevated permissions?

Okay, so originally I was going to ask about dragging and dropping in Windows 7. I found the answer I was looking for here: C# Drag drop does not work on windows 7 . Basically it says that since I'm running Visual Studio (and subsequently, my program) with elevated permissions, some sort of isolation layer prevents me from dragging and dropping files from explorer into my program.

The reason I run visual studio with elevated permissions is because admin privileges are needed to run a site locally on IIS and the web app is in my solution. Is there a way I can tell visual studio to run and debug my other apps as a normal user?

为什么不在桌面上创建另一个快捷方式,启动devenv.exe而不提升?

MSDN states :

Launching an Un-Elevated Application from an Elevated Process

A frequently asked question is how to launch an un-elevated application from an elevated process, or more fundamentally, how to I launch a process using my un-elevated token once I'm running elevated. Since there is no direct way to do this, the situation can usually be avoided by launching the original application as standard user and only elevating those portions of the application that require administrative rights. This way there is always a non-elevated process that can be used to launch additional applications as the currently logged on desktop user. Sometimes, however, an elevated process needs to get another application running un-elevated. This can be accomplished by using the task scheduler within Windows Vista®. The elevated process can register a task to run as the currently logged on desktop user.

You could use that and implement a simple launcher app (possibly a VS macro) that you start instead of your application. The launcher app would:

  • Create a scheduled task that would run immediately or that is triggered by an event
  • Start the debuggee
  • Connect the VS debugger to the started process

I use old-school command line for this purpose:

runas /trustlevel:0x20000 "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"

And then just press F5 in Studio.

The VS debugger is tied to the browser instance that VS is launched, but you can still use with another browser instance to browse the site under test. Actions on the server side will still operate through the debugger (but you'll not get client side debugging—IE8 developer tools and FireBug are still available of course).

From your application, call ChangeWindowMessageFilter with the following values to allow dragging and dropping to/from your elevated application and non-elevated applications like Explorer:

ChangeWindowMessageFilter (WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter (WM_COPYDATA, MSGFLT_ADD);
ChangeWindowMessageFilter (0x0049, MSGFLT_ADD);

Credit: http://blog.helgeklein.com/2010/03/how-to-enable-drag-and-drop-for.html

You can use the elevated Visual Studio to do your programming, you just can't have Visual Studio launch the executable.

I like 0xA3's answer, but if you don't want to go to the trouble of creating a VS macro and a scheduled task to launch your program, you can just create a shortcut on the desktop to the executable (either the debug or release version) and use that to launch your program.

If you launch the debug version, you can use "Attach to Process" in the Visual Studio Debug menu to attach and do some debugging.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM