我能得到 Shell.Application 的 ShellExecute 的返回值吗? [英] Can I get the return value of Shell.Application's ShellExecute?

查看:44
本文介绍了我能得到 Shell.Application 的 ShellExecute 的返回值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VBScript 为批处理文件创建 UAC 提示.我不知道如何获取UAC提示的返回值.例如,如果我尝试 UAC 一个不存在的文件,我应该得到一个错误,对吗?

I'm using VBScript to create a UAC prompt for a batch file. I don't know how to get the return value of the UAC prompt. For example if I try to UAC a file that doesn't exist I should get an error, right?

例如:

Dim rc
Set UAC = CreateObject("Shell.Application") 
rc = UAC.ShellExecute("thisdoesntexist.exe", "", "", "runas", 1)
WScript.Echo rc

rc 不包含代码.另外,有什么方法可以获取我正在执行的任何内容的错误代码?VBScript 中的 ShellExecute 是异步的吗?

rc doesn't contain a code. Also, is there any way I can get the error code of whatever I'm executing? Is ShellExecute asynchronous in VBScript?

推荐答案

IShellDispatch2.ShellExecute 方法

对指定文件执行指定操作.

IShellDispatch2.ShellExecute method

Performs a specified operation on a specified file.

语法

IShellDispatch2.ShellExecute(sFile [, vArguments] [, vDirectory] ​​[,vOperation] [, vShow]) 参数

IShellDispatch2.ShellExecute(sFile [, vArguments] [, vDirectory] [, vOperation] [, vShow]) Parameters

sFile 必需.包含文件名的字符串ShellExecute 将执行 vOperation 指定的操作.

sFile Required. String that contains the name of the file on which ShellExecute will perform the action specified by vOperation.

vArguments 可选.包含以下参数值的变体操作.

vArguments Optional. Variant that contains the parameter values for the operation.

vDirectory 可选.包含完全限定路径的变体包含由 sFile 指定的文件的目录.如果这未指定参数,则使用当前工作目录.

vDirectory Optional. Variant that contains the fully qualified path of the directory that contains the file specified by sFile. If this parameter is not specified, the current working directory is used.

vOperation 可选.指定要执行的操作的变体执行.它应该设置为动词字符串之一文件支持.有关动词的讨论,请参阅备注部分.如果不指定该参数,则默认操作为执行.

vOperation Optional. Variant that specifies the operation to be performed. It should be set to one of the verb strings that is supported by the file. For a discussion of verbs, see the Remarks section. If this parameter is not specified, the default operation is performed.

vShow 可选.推荐属于的窗口的变体应显示执行操作的应用程序最初.应用程序可以忽略此建议.vShow 可以取以下值之一.如果没有指定这个参数,应用程序使用其默认值.0

vShow Optional. Variant that recommends how the window that belongs to the application that performs the operation should be displayed initially. The application can ignore this recommendation. vShow can take one of the following values. If this parameter is not specified, the application uses its default value.0

打开带有隐藏窗口的应用程序.

Open the application with a hidden window.

1 用普通窗口打开应用程序.如果窗户是最小化或最大化,系统将其恢复到原始大小和位置.

1 Open the application with a normal window. If the window is minimized or maximized, the system restores it to its original size and position.

2 以最小化的窗口打开应用程序.

2 Open the application with a minimized window.

3 以最大化的窗口打开应用程序.

3 Open the application with a maximized window.

4 以最新大小的窗口打开应用程序,然后位置.活动窗口保持活动状态.

4 Open the application with its window at its most recent size and position. The active window remains active.

5 使用当前大小的窗口打开应用程序,然后位置.

5 Open the application with its window at its current size and position.

7 以最小化的窗口打开应用程序.活动窗口保持活跃.

7 Open the application with a minimized window. The active window remains active.

10 打开应用程序,窗口处于指定的默认状态通过应用程序.

10 Open the application with its window in the default state specified by the application.

返回值

无返回值.

备注

这个方法相当于启动了关联的命令之一带有文件的快捷菜单.每个命令由一个动词标识细绳.支持的动词因文件而异.最常见的支持的动词是open",这通常也是默认动词.其他文件可能仅受某些类型的文件支持.为了更进一步的Shell 动词的讨论,请参阅启动应用程序或扩展快捷菜单.

This method is equivalent to launching one of the commands associated with a file's shortcut menu. Each command is identified by a verb string. The supported verbs vary from file to file. The most commonly supported verb is "open", which is also usually the default verb. Others might be supported only by certain types of files. For further discussion of Shell verbs, see Launching Applications or Extending Shortcut Menus.

此方法目前在 Microsoft Visual Basic 中不可用.

This method is not currently available in Microsoft Visual Basic.

示例

以下示例使用 ShellExecute 打开 Microsoft 记事本.显示了 Microsoft JScript 和 Visual Basic Sc​​ripting 的正确用法版本(VBScript).

The following example uses ShellExecute to open Microsoft Notepad. Proper usage is shown for Microsoft JScript and Visual Basic Scripting Edition (VBScript).

<script language="VBScript">
    function fnShellExecuteVB()
        dim objShell

        set objShell = CreateObject("Shell.Application")

        objShell.ShellExecute "notepad.exe", "", "", "open", 1

        set objShell = nothing
    end function
</script>

现在所有的 COM 调用看起来像这样 HResult = methodcall(param1, param2, ..., paramn, OUTPARAM).

Now all COM calls look like this HResult = methodcall(param1, param2, ..., paramn, OUTPARAM).

VB 假装它 OUTPARAM = methodcall(param1, Param2, ..., paramn) 并且 HResult 出现在 err.object 中.

VB pretends it OUTPARAM = methodcall(param1, Param2, ..., paramn) with HResult appearing in the err.object.

所以错误仍然会触发,只是它不会等待发现.

So errors will still fire, it's just that it doesn't wait to find out.

这篇关于我能得到 Shell.Application 的 ShellExecute 的返回值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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