0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VBScript用Includeモジュール(WScript.Shellラッパー)

Last updated at Posted at 2024-08-12
WShllModule.vbs
Option Explicit

Dim WShll
Set WShll = CreateObject("WScript.Shell")

'Call TEST_20240812_175759
'// デスクトップのパスを返す

Function DesktopPath()

    DesktopPath = WShll.SpecialFolders("Desktop")

End Function
'// マイドキュメントのパスを返す

Function MyDocumentPath()

    MyDocumentPath = WShll.SpecialFolders("MyDocuments")

End Function
'// ユーザ名を返す

Function UsrName()

    UsrName = CreateObject("WScript.Network").UserName

End Function
'// コンピュータ名を返す

Function PcName()

    PcName = CreateObject("WScript.Network").ComputerName

End Function
'// ダウンロードフォルダのパスを返す

Function DownloadPath()

    DownloadPath = CreateObject("Shell.Application").Namespace("shell:Downloads").Self.Path

End Function
'// 環境変数の値を返す

Function EnvStr(ByVal env_name)

    EnvStr = WShll.ExpandEnvironmentStrings(env_name)

End Function
'// 作成したフォルダのパスを返す
'// mdコマンドを使うことで、すでにフォルダが存在していてもエラーにならないし、
'// 途中のフォルダも自動的に作成してくれる

Function MakeFolder(ByVal folder_path)

    WShll.Run "cmd /c md " & chr(34) & folder_path & chr(34), 0, True
    MakeFolder = folder_path

End Function
'// ファイルを選択した状態でフォルダを開く(ファイルを指定した場合)

Sub OpenFolder(Byval path)

    Dim optn: optn = ""
    If CreateObject("Scripting.FileSystemObject").FileExists(path) Then optn = "/select, "
    WShll.Run "explorer.exe /e, " & optn & path, 1

End Sub
Sub TEST_20240812_175759()

    Dim cmd, tb: tb = vbTab
    
    cmd = "echo UsrName"                    & tb & tb & "|" & UsrName
    cmd = cmd & " & echo PcName"            & tb & tb & "|" & PcName
    cmd = cmd & " & echo ^%USERPROFILE^%"        & tb & "|" & EnvStr("%USERPROFILE%")
    cmd = cmd & " & echo ^%OneDrive^%"           & tb & "|" & EnvStr("%OneDrive%")
    cmd = cmd & " & echo ^%LOCALAPPDATA^%"       & tb & "|" & EnvStr("%LOCALAPPDATA%")
    cmd = cmd & " & echo ^%APPDATA^%"            & tb & "|" & EnvStr("%APPDATA%")
    cmd = cmd & " & echo MyDocumentPath"         & tb & "|" & MyDocumentPath
    cmd = cmd & " & echo DownloadPath"           & tb & "|" & DownloadPath
    cmd = cmd & " & echo. & pause"

    WShll.Run "cmd /c " & cmd

End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?