14

現在、これは私のスクリプトです

Set oWS = WScript.CreateObject("WScript.Shell")
' Get the %userprofile% in a variable, or else it won't be recognized
userProfile = oWS.ExpandEnvironmentStrings( "%userprofile%" )

私がやろうとしているのは、ログインしている現在のユーザーを取得することです。ディレクトリ D:\"personsuser"\Appdata\Roaming\Local をチェックして、フォルダー "Local" が作成されていない場合は作成されているかどうかを確認しますvbs で createobject を使用して作成したいと考えています。私が知っている上記のスクリプトは、現在ログオンしているユーザーを取得しますが、この変数を使用してフォルダーを作成する方法がわかりません。

私はこれらの行に沿って何かを組み込む必要があることを知っています:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("C:\FSO")

そして、またはこれらの行に沿った何か:

Dim objNetwork
Dim userName
Dim FSO

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objNetwork = CreateObject("WScript.Network")
userName = objNetwork.userName

If fso.driveExists("D:\" & userName & "\AppData\Local\") Then
    FSO.CreateDirectory ("D:\" & userName & "\AppData\Local\")
End If

VBS にはあまり詳しくありませんが、VBS を使用している環境で操作できる唯一のプラットフォームです。

4

2 に答える 2

21
Set oWS = WScript.CreateObject("WScript.Shell")
' Get the %userprofile% in a variable, or else it won't be recognized
userProfile = oWS.ExpandEnvironmentStrings( "%userprofile%" )

Dim objNetwork
Dim userName
Dim FSO
Dim Folder

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objNetwork = CreateObject("WScript.Network")
userName = objNetwork.userName

If NOT (FSO.FolderExists(userProfile + "\AppData\Roaming\Local")) Then
    ' Delete this if you don't want the MsgBox to show
    MsgBox("Local folder doesn't exists, creating...")
    splitString = Split(userProfile, "\")

    ' Create folder
    MsgBox("D:\" + splitString(2) + "\AppData\Roaming\Local")
    'FSO.CreateFolder(splitString(2) + "\AppData\Roaming\Local")
End If

ほら、ほら、これは完璧に機能するはずです、ダニエルについて。

于 2013-06-04T05:25:30.760 に答える