Check if folder is there, if not create it on current user logged in VBS

后端 未结 2 1849
孤街浪徒
孤街浪徒 2021-02-13 12:15

Currently this is my script

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


        
2条回答
  •  逝去的感伤
    2021-02-13 12:33

    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
    

    Here you go man, this should work perfect, regards Daniel.

提交回复
热议问题