1

Sorry very new to all of this. I am currently trying to put together a basic script to create a folder based on use input. I can get to the point where the input can be done and the folder is created but not with inputbox data.

dim UserName

UserName = InputBox ("Please enter user name")

if Username = "" then
MsgBox("No username entered")

do while(UserName = "")
UserName = InputBox ("Please enter user name")
    if Username = "" then
    MsgBox("No Username entered")
    else
    MsgBox("Please click OK to continue")
    end if
Loop

else
MsgBox ("Please click ok to continue")

end if

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "cmd /c mkdir c:\temp\UserName"

As I said am very new to this so am open to any tips or pointers in the right direction.

Cheers in advance

4

2 回答 2

1

我不明白为什么人们把一切都搞得这么复杂。一个非常简单的脚本在这里:

*strfolder = InputBox("Please enter a name for your new folder:")
set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CreateFolder "c:\" & strfolder*
于 2014-03-19T16:25:29.573 回答
0

为了让它工作,你所要做的就是把最后一行改成这样:

objShell.Run "cmd /c mkdir c:\temp\" & UserName

这样,您可以使用值UserName而不是单词 UserName。

通过提示...

您的流程有点多余,您可以通过更新循环来做同样的事情。这是一种可能的路线:

dim UserName
Do
   UserName = InputBox ("Please enter user name")
   If UserName = "" then
      Msgbox "No Username entered"
   end if
Loop Until UserName <> ""

MsgBox "Please click OK to continue"

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "cmd /c mkdir c:\temp\" & UserName

UserName = ""此外,如果单击取消""是 InputBox 的返回值,最好只结束脚本。

于 2012-11-22T04:36:25.217 回答