Visual Basic Shell 管理员? [英] Visual Basic Shell Administrator?

查看:28
本文介绍了Visual Basic Shell 管理员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 Visual Basic 使用 Shell() 命令运行可执行文件,我将如何以管理员身份运行该可执行文件?我的方法至少在实践中有效,但一个可执行文件无法正常运行,我认为这就是问题所在.

If I'm using Visual Basic to run an executable using the Shell() command, how would I run that executable as an administrator? My method works, at least in practice, but one executable won't run properly and I think that's the issue.

这是我尝试运行的命令的示例.

Here's an example of the command I'm trying to run.

Shell("%temp%\ninite.exe")

抱歉,这是 VB.net,不是 VBA.我在那里贴了一个坏标签.

Sorry, this is VB.net, not VBA. I put a bad tag on there.

推荐答案

要严格使用 VBA,没有 .NET 依赖项,您应该能够使用 ShellExecute Win32 函数.

To stay strictly in VBA with no .NET dependencies, you should be able to use the ShellExecute Win32 function.

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hWnd As Long, _
        ByVal lpOperation As String, 
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long 

您可以将runas"传递给 lpOperation 而不是更常见的open"(通常称为动词).请注意,这可能会导致出现一个对话框,提示用户输入凭据.

You can pass "runas" to lpOperation instead of the more usual "open" (commonly called the verb). Note that this may cause a dialog box to come up prompting the user for credentials.

更好的方法可能是使用 CreateProcessCreateProcessAsUser 函数,这可能是在 Windows 中启动任何东西的最强大的方式,但这肯定更复杂,我无法告诉您如何使其正常工作的细节.

A better way might be to use the CreateProcess or CreateProcessAsUser function which is probably the most powerful way to launch anything in Windows, but that is certainly more complex and I cannot tell you the details of how to get it to work right.

这篇关于Visual Basic Shell 管理员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆