Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 运行VBS脚本的VB GUI界面_User Interface_Vbscript_Batch File - Fatal编程技术网

User interface 运行VBS脚本的VB GUI界面

User interface 运行VBS脚本的VB GUI界面,user-interface,vbscript,batch-file,User Interface,Vbscript,Batch File,我有一个VBS脚本,我需要每月运行一次,它可以捕获文件名、类型、修改日期等文件信息。当我处理每个文件时,它会将所有文件保存到CSV文件中,以便我可以在Excel上处理它 为了运行脚本,我设置了一个批处理文件.bat 问题是我需要某种GUI界面,这样当批处理或vbs文件运行时,它会要求用户输入要扫描的驱动器号 这是我的代码: test.vbs: Option Explicit Dim objFS, objFld Dim objArgs Dim strFolder, strDestFile, bln

我有一个VBS脚本,我需要每月运行一次,它可以捕获文件名、类型、修改日期等文件信息。当我处理每个文件时,它会将所有文件保存到CSV文件中,以便我可以在Excel上处理它

为了运行脚本,我设置了一个批处理文件.bat

问题是我需要某种GUI界面,这样当批处理或vbs文件运行时,它会要求用户输入要扫描的驱动器号

这是我的代码:

test.vbs:
Option Explicit
Dim objFS, objFld
Dim objArgs
Dim strFolder, strDestFile, blnRecursiveSearch
Dim strLines()
Dim i
Dim strCsv

    i = 0
    
'   'Get the commandline parameters
'   Set objArgs = WScript.Arguments 
'   strFolder = objArgs(0)
'   strDestFile = objArgs(1)
'   blnRecursiveSearch = objArgs(2)
    
    '###################################
    'MAKE SURE THESE VALUES ARE CORRECT
    '###################################
    strFolder = "C:\" 
    strDestFile = "C:\test\Output.csv" 
    blnRecursiveSearch = True
    
    'Create the FileSystemObject
    Set objFS=CreateObject("Scripting.FileSystemObject")
    'Get the directory you are working in 
    Set objFld = objFS.GetFolder(strFolder)
    
    'Now get the file details
    GetFileDetails objFld, blnRecursiveSearch 
    
    'Write the csv file
    Set strCsv = objFS.CreateTextFile(strDestFile, True)
    strCsv.Write Join(strLines, vbCrLf)
    
    'Close and cleanup objects
    strCsv.Close
    Set strCsv = Nothing
    Set objFld = Nothing
    Set strFolder = Nothing
    Set objArgs = Nothing

    
Private Sub GetFileDetails(fold, blnRecursive)
Dim fld, fil
dim strLine(5)

    If blnRecursive Then
        'Work through all the folders and subfolders
        For Each fld In fold.SubFolders
            GetFileDetails fld, True 
        Next
    End If
    
    'Now work on the files
    For Each fil in fold.Files
        strLine(0) = fil.Path
        strLine(1) = fil.Type
        strLine(2) = fil.Size
        strLine(3) = fil.DateCreated
        strLine(4) = fil.DateLastModified
        strLine(5) = fil.DateLastAccessed
        
        Redim Preserve strLines(i)
        strLines(i) = Join(strLine, ",")
        i = i + 1
    Next
end sub
还有跑步。蝙蝠

cscript.exe C:\script\test.vbs
如您所见,test.vbs指定要扫描和捕获的节。代码:
strFolder=“C:\”


你最好的建议是什么,运行这个的人在VB方面比我经验少很多,所以他们需要某种GUI界面,要求输入驱动器号,然后将行代码修改为他们输入的任何驱动器号,然后运行test.vbs。

您可以使用输入框


InputBox是最简单的解决方案,不过您可能需要进行一些错误检查

还有BrowseForFolder,它允许用户选择一个文件夹。同样,如果您想将用户限制在驱动器的根文件夹中,您可能需要执行一些错误检查

为什么不使用vb.net

对于驱动器号,您甚至可以使用下拉框

Dim driveLetter as String = combobox.text

If (Directory.Exists(driveLetter)) Then
 strFolder = combobox.text
Else
 msgbox("Drive letter does not exist")
End If

只需将驱动器号添加为vbscript的一个参数就可以了

Set oArgs = WScript.Arguments
DriveLetter = oArgs(0)
strFolder = DriveLetter & ":\"
然后,您可以像运行附加驱动器号的脚本一样运行脚本

cscript.exe C:\script\test.vbs C
然后,如果用户确实需要脚本,可以将其包装在VB GUI(前面建议的输入框)中。或者更好的是,你的脚本可以让他们输入驱动器号


旁注(取决于您使用的windows版本以及您需要日期的方式),dir命令将使用/t开关打印特定的文件日期。因此,
dir/ta
将打印最后访问的日期。不幸的是,它一次只做一个(访问、修改、创建)。您可能可以使用它并将其传输到文件(
dir/ta>Output.txt
)中,而不是编写单独的脚本

使用HTA应用程序。它是vbscript和jscript的最佳GUI

听起来很简单,但对我来说不幸的是不是这样,你能不能把它和我的代码联系起来。创建costum批处理文件的东西或修改test.vbs并运行它的gui。Thanks@MalsiaPro,那么您需要一个GUI来用用户输入路径的正确代码更新vbs文件?是的,好的,这正是我需要的。我无法将其他建议与我的代码相匹配,如果可能,请提供帮助。切切克解决方案。