问题描述
在我的VBA过程中,我需要运行应用程序Skitch,并使用它来打开一个JPEG文件。这是我一直在使用的命令:
In my VBA procedure, I need to run the app "Skitch" and use it to open a JPEG file. This is the command I've been using:
ReturnValue = Shell(C:\Program Files(x86)\Evernote\Skitch\Skitch.exe && aPic&1)
ReturnValue = Shell("C:\Program Files (x86)\Evernote\Skitch\Skitch.exe " & """" & aPic & """", 1)
...其中aPic是路径和文件名。
...where "aPic" is the path and filename.
经过一些实验,我想我需要运行命令,就像它在一个Elevated Command窗口(换句话说,运行它作为管理员)。是否可以运行Shell提升?
After some experimenting, I think I need to run the command as if it were in an Elevated Command window (in other words, run it "as Administrator"). Is it possible to run Shell elevated?
如果这不可能:如果我理解正确,使用ShellExecute而不是Shell将自动提升命令。但我不太熟悉它。有人可以告诉我如何使用ShellExecute运行我的命令? (BTW,我知道ShellExecute适用于运行与文件类型相关联的命令,但在此用户的计算机上* .jpg可能不会与Skitch相关联。)
If that's not possible: If I understand correctly, using ShellExecute instead of Shell will automatically elevate the command. But I'm much less familiar with it. Can someone show me how to run my command using ShellExecute? (BTW, I know that ShellExecute is good for running commands associated with the file type, but on this user's computer *.jpg will likely not be associated with Skitch.)
感谢。
推荐答案
尝试:
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
Const SW_SHOWNORMAL = 1
Public Sub test()
ShellExecute 0, "runas", "C:\Program Files (x86)\Evernote\Skitch\Skitch.exe", aPic, vbNullString, SW_SHOWNORMAL
End Sub
skitch
所以不能尝试这个,但它应该工作。
I don't have skitch
so can't try this, but it should work.
有关 ShellExecute
,在MSDN上看看。
For more information about ShellExecute
, click here to have a look on MSDN.
这篇关于VBA:运行“升高”命令(Shell vs. ShellExecute)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!