简体   繁体   English

我可以在没有提升权限的情况下从visual studio运行程序吗?

[英]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 . 好吧,原来我打算在Windows 7中询问有关拖放的问题。我找到了我在这里寻找的答案: C#Drag drop在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. 基本上它说,由于我使用提升的权限运行Visual Studio(以及随后的程序),某种隔离层阻止我将文件从资源管理器拖放到我的程序中。

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. 我使用提升权限运行visual studio的原因是因为在IIS上本地运行站点以及Web应用程序在我的解决方案中需要管理员权限。 Is there a way I can tell visual studio to run and debug my other apps as a normal user? 有没有办法告诉visual studio以普通用户身份运行和调试我的其他应用程序?

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

MSDN states : MSDN声明

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®. 这可以通过使用WindowsVista®中的任务计划程序来完成。 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. 您可以使用它并实现一个简单的启动器应用程序(可能是VS宏),而不是您的应用程序。 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 将VS调试器连接到已启动的进程

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. 然后在Studio中按F5。

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. VS调试器与启动VS的浏览器实例绑定,但您仍可以使用其他浏览器实例浏览受测试的站点。 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). 服务器端的操作仍然可以通过调试器运行(但是你不会得到客户端调试 - IE8开发人员工具和FireBug当然仍然可用)。

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,以允许拖放到提升的应用程序和非提升的应用程序(如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 图片来源: 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. 您可以使用提升的Visual Studio进行编程,您只是无法让Visual Studio启动可执行文件。

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. 我喜欢0xA3的答案,但是如果你不想去创建VS宏和计划任务来启动你的程序,你可以在桌面上创建一个可执行文件的快捷方式(调试或发布版本) )并使用它来启动您的程序。

If you launch the debug version, you can use "Attach to Process" in the Visual Studio Debug menu to attach and do some debugging. 如果启动调试版本,则可以使用Visual Studio调试菜单中的“附加到进程”来附加并执行一些调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可以使用 Mono 运行程序,但不能使用 Visual Studio Mac - Can run program with Mono but not with Visual Studio Mac 如何运行具有提升权限的wpf应用程序? - How ca i run a wpf application with elevated permissions? 我需要从Visual Studio中获得什么才能在没有Visual Studio的情况下运行应用程序 - What do I need from visual studio to run application without visual studio 我可以在Visual Studio 2010中运行NUnit测试吗? - Can I run NUnit tests from within Visual Studio 2010? 检测程序是否由Visual Studio运行,而不是从Windows资源管理器运行 - Detecting if a program was run by Visual Studio, as opposed to run from Windows Explorer 为什么在未安装Visual Studio的计算机中无法运行.NET程序的调试版本 - Why can't I run debug version of .NET program in the machine didn't install visual studio 当我运行程序时,Visual Studio移动标签 - Visual Studio moves labels when I run my program 我可以在没有Visual Studio的情况下编译DLL吗? - Can I compile DLLs without Visual Studio? 我可以在没有Visual Studio的情况下创建ClickOnce吗? - Can I create ClickOnce without Visual Studio? 部署无需安装即可运行的 Visual Studio 应用程序的最佳方法 - Best way to deploy Visual Studio application that can run without installing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM