Hello everyone-
I am trying to execute a DOS command from a VBScript file. I basically want to be able to build a string and then execute it. For some reason my code will not work with my string. Let me just show you my code, it will make more sense.
The above code does not work. When I hard code that line in there, as in below it works fine:
Does anyone know how to get it to work the first way, so that I can build the command I want to execute into a string?
Thanks!
-Mark
I am trying to execute a DOS command from a VBScript file. I basically want to be able to build a string and then execute it. For some reason my code will not work with my string. Let me just show you my code, it will make more sense.
Code:
DIM objShell
DIM iReturn
set objShell = wscript.createObject("wscript.shell")
dim command
command = "CMD /C DIR p:\ /s > "
dim path
path = "C:\Documents and Settings\User\Desktop\"
dim fileName
fileName = "FILE.TXT"
dim finalCommand
finalCommand = command & path & fileName
''so at this point the finalCommand is this:
''"CMD /C DIR p:\ /S > C:\Documents and Settings\User\Desktop\FILE.TXT"
iReturn = objShell.Run(finalCommand, , True)
The above code does not work. When I hard code that line in there, as in below it works fine:
Code:
DIM objShell
DIM iReturn
set objShell = wscript.createObject("wscript.shell")
'iReturn = objShell.Run("CMD /C DIR p:\ /S > C:\Documents and Settings\User\Desktop\FILE.TXT", , True)
Does anyone know how to get it to work the first way, so that I can build the command I want to execute into a string?
Thanks!
-Mark