VBScript 如何找到文件路径?

How to VBScript find file path?

好的,所以我正在创建一个 HTML 打开时没有工具栏或任何东西,但我无法让它在其他计算机上工作

这就是我得到的

set webbrowser = createobject("internetexplorer.application")

webbrowser.statusbar = false

webbrowser.menubar = false

webbrowser.toolbar = false

webbrowser.visible = true

webbrowser.navigate2 ("C:\Users\unknown\Desktop\Folder\myhtml.html")

使用 ActiveX 对象 "WScript.Network" 的用户名 属性 获取其他计算机上当前用户的名称。

如:

>> sUser = CreateObject("WScript.Network").UserName
>> WScript.Echo "Just for Demo:", sUser
>>
Just for Demo: eh

(该对象与 C|WScript.exe 主机提供的 WScript 对象不同,因此可从其他主机使用。不使用浏览器 (.html),但 mshta.exe host (.hta) - 正如@omegastripes 所建议的那样 - 是合理的建议。)

你应该处理:

  • 可以更改用户桌面文件夹位置
  • 用户看到的桌面是文件系统中多个文件夹的虚拟视图。直接搜索用户桌面内的文件夹将遗漏为所有用户配置的桌面文件夹。

所以,最好让 OS 检索所需的信息

Option Explicit

' folder in desktop and file in folder 
Const FOLDER_NAME = "Folder"
Const FILE_NAME = "myhtml.html"

Dim oFolder
Const ssfDESKTOP = &H00&
    ' Retrieve a reference to the virtual desktop view and try to retrieve a reference
    ' to the folder we are searching for
    With WScript.CreateObject("Shell.Application").Namespace( ssfDESKTOP )
        Set oFolder = .ParseName(FOLDER_NAME)
    End With 

    ' If we don't have a folder reference, leave with an error
    If oFolder Is Nothing Then 
        WScript.Echo "ERROR - Folder not found in desktop"
        WScript.Quit 1
    End If 

Dim strFolderPath, strFilePath    
    ' Retrieve the file system path of the requested folder
    strFolderPath = oFolder.Path

    ' Search the required file and leave with an error if it can not be found
    With WScript.CreateObject("Scripting.FileSystemObject")
        strFilePath = .BuildPath( strFolderPath, FILE_NAME )
        If Not .FileExists( strFilePath ) Then 
            WScript.Echo "ERROR - File not found in desktop folder"
            WScript.Quit 1
        End If 
    End With 

    ' We have a valid file reference, navigate to it
    With WScript.CreateObject("InternetExplorer.Application")
        .statusBar = False 
        .menubar = False 
        .toolbar = False 
        .visible = True 
        .navigate2 strFilePath 
    End With 

您可以找到有关 shell 个脚本化对象的更多信息 here