简体   繁体   English

vbscript从specialfolders启动exe文件

[英]vbscript launching an exe file from specialfolders

I want to launch an exe that is a messagebox from a specialfolders using vbscript, but I get nothing. 我想使用vbscript从特殊文件夹中启动一个消息框的exe,但是我什么也没得到。 this is my code 这是我的代码

option explicit
dim shellobj,startup,objShell,objFolder,filesystemobj,installdir,installname
set shellobj = wscript.createobject("wscript.shell")
set filesystemobj = createobject("scripting.filesystemobject")
Set objShell = CreateObject("Shell.Application")
installdir = "%appdata%\Microsoft"
installname = wscript.scriptname
filesystemobj.copyfile wscript.scriptfullname,installdir & installname,true
startup = shellobj.specialfolders("%appdata%\Microsoft") &"\msg.exe"
if filesystemobj.fileexists(startup) Then
  shellobj.run "wscript.exe //B " & chr(34) & startup & chr(34)    
  Wscript.Quit
end if
  1. startup = shellobj.specialfolders("%appdata%\\Microsoft") &"\\msg.exe"

    The SpecialFolders property doesn't expand environment variables. SpecialFolders属性不会扩展环境变量。 You need the ExpandEnvironmentStrings method for that: 您需要ExpandEnvironmentStrings方法:

     shellobj.ExpandEnvironmentStrings("%APPDATA%\\Microsoft") & "\\msg.exe" 

    The SpecialFolders property must be used like this: SpecialFolders属性必须按以下方式使用:

     shellobj.SpecialFolders("APPDATA") & "\\Microsoft\\msg.exe" 
  2. if filesystemobj.fileexists(startup) Then

    Since specialfolders("%appdata%\\Microsoft") returns an empty string the value of startup becomes \\msg.exe , which doesn't exist. 由于specialfolders("%appdata%\\Microsoft")返回空字符串,因此startup值变为\\msg.exe ,该值不存在。 Thus the statements in the Then branch are never executed. 因此,则从不执行Then分支中的语句。

  3. shellobj.run "wscript.exe //B " & chr(34) & startup & chr(34)

    And even if the "\\msg.exe" existed, you cannot run it with wscript.exe . 并且即使存在“ \\ msg.exe”,也无法使用wscript.exe运行它。 wscript.exe is one of the interpreters for VBScripts. wscript.exe是VBScript的解释器之一。 Change that statement to this: 将该语句更改为此:

     shellobj.Run Chr(34) & startup & Chr(34), 1, True 

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

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