Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command prompt closes too fast

Status
Not open for further replies.

holidayIT

IS-IT--Management
Apr 2, 2004
138
0
0
US
Does anyone know a command to "pause" the command prompt when being called from a vbscript? it executes the prompt window, but i need to see any output from it.
 
You have twoi options.

Run the cmd with a /K option.

If the cmd is executing a batch file, put pause at the end of the bat.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Could always put a
Code:
wscript.echo "Message"
at the end of your vbs this would leave the command prompt window open until OK is pressed on the message box
 
sorry I said that completly wrong! what I meant was

Code:
msgBox "Message"

So you VBS would look something like

Code:
Run whatever script
msgBox "Message"

And the bat file

Code:
cscript test.vbs
 
afraid that didn't work. the command prompt just opens and closes
 
Did running it with /K work?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
it seems like none of the switches work. i am using an xcopy and the entire code doesn't seem to actually copy. so i need to see the output to see what the problem is.
 
Pipe the output to a text file a la:
SomeCommand.exe > C:\Temp\SomeName.log

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
i'm sorry Tom, i don't really know how to do that. do you mean in the command prompt where i run the script(vbs)? or do you mean as far as the line of code where i execute the command prompt.

Here is the line of code i am using btw, this might help:

Call WSHShell.Run("cmd.exe /C xcopy Q:\" & myFile & " R:\ /y /k")

 
Try this first:
Call WSHShell.Run("cmd.exe /K xcopy Q:\" & myFile & " R:\ /y")

If that doesn't work, then:
Call WSHShell.Run("cmd.exe /C xcopy Q:\" & myFile & " R:\ /y > c:\CMD.Log")


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Try this:
WSHShell.Run "cmd.exe /K xcopy ""Q:\" & myFile & """ R:\ /y", 1, True


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
i actually discovered my problem. my draves are not mapping correctly.

WSHNetwork.MapNetworkDrive "Q:", sourceDir,True

i have tried putting "True" in quotes, i've added the admin password and username, and i even tried getting rid of the string variable and writing explicitly the drive that i need to map. nothing works. any ideas?
 
nothing works
Any error message ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
i just gives me "device unavailable" when i do a getdrive on the mapped drive. no other error message.

Here is my code(written with the help of numerous people, including markdmac and tsuji, as well as you, phv:



On Error Resume Next

Wscript.Echo "Beginning Script "

' define ADSI status constants
Const ADS_SERVICE_STOPPED = 1
Const ADS_SERVICE_START_PENDING = 2
Const ADS_SERVICE_STOP_PENDING = 3
Const ADS_SERVICE_RUNNING = 4
Const ADS_SERVICE_CONTINUE_PENDING = 5
Const ADS_SERVICE_PAUSE_PENDING = 6
Const ADS_SERVICE_PAUSED = 7
Const ADS_SERVICE_ERROR = 8

' define string constants for service methods
Const START_SERVICE = "START"
Const STOP_SERVICE = "STOP"
Const PAUSE_SERVICE = "PAUSE"
Const CONTINUE_SERVICE = "CONTINUE"

' declare global variables
Dim objWsh
Dim objEnv
Dim strComputerName

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
Set objEnv = WSHShell.Environment("PROCESS")

'pwd = InputBox ("Please Enter the Administrator Password", "Network Password")

password = pwd

myFile=<myfile>
sourceDir="\\server\folder\"
destDir="\program files\folder\"

Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.MapNetworkDrive "Q:/", sourceDir, True', "administrator", password
Wscript.Echo "Mapped Drive Q:"

For Each strWorkstation In RemotePC
'Do something useful with strWorkstation

strComputerName = strWorkstation

set objShell = CreateObject("WScript.Shell")
' Wscript.Echo "Pinging " & strComputerName
response = ping(strComputerName)
intSuccess = instr(response," Received = 0")
wscript.echo intSuccess

if intSuccess = 0 then
Wscript.Echo "Connected " & strComputerName
blnSeverUp = true
else
blnServerUp = false
Wscript.Echo "Not Connected " & strComputerName
end if

'If blnServerUp = true Then
If intSuccess = 0 Then

wscript.Echo "blnServerUp = true"
destDir2 = "\\" & strComputerName & "\C$" & destDir

Wscript.Echo destDir2

WSHNetwork.MapNetworkDrive "R:", destDir2, "False"', "administrator", password
Wscript.Echo "Mapped R:"

' call CycleService() to stop all the services
CycleService strComputerName,"FSMA",STOP_SERVICE,True
CycleService strComputerName,"FSPM",STOP_SERVICE,True

'make sure there is "on error resume next" above
'this seems to be the case
'of your script
dim oitem, fso
set fso=createobject("scripting.filesystemobject")
set oitem=fso.getdrive("Q:")
if err.number<>0 then
Wscript.echo "Q: drive is not recognized. XCopy would fail. Error is: " & err.number & " " & err.Description
err.clear
end if
set oitem=fso.getdrive("R:")
if err.number<>0 then
Wscript.echo "R: drive is not recognized. XCopy would fail."
err.clear
end if
set oitem=fso.getfile("Q:\" & myFile)
if err.number<>0 then
Wscript.echo "Q:\<myFile> is not recognized. XCopy would fail."
err.clear
end if
set oitem=nothing : set fso=nothing

Call WSHShell.Run("cmd.exe /k xcopy Q:\" & myFile & " R:\ /y /k")

'msgBox "Message"

wscript.Echo "cmd.exe /C xcopy Q:\" & myFile & destDir2

'Wscript.Echo "Copied"

' call CycleService() to start all the services
CycleService strComputerName,"FSPM",START_SERVICE,False
CycleService strComputerName,"FSMA",START_SERVICE,False

'Else
' WScript.Echo strComputerName & " did not respond to ping."
End If

' Wscript.Echo strComputerName & " Completed"

If err.number <> 0 Then
wscript.Echo "Error!!! " & err.Description & "Error: " & err.number
End If

Next

Set oFSO = Nothing
Set WSHShell = Nothing
Set WSHNetwork = Nothing
Wscript.Echo "All done"
WScript.Quit(0)

' ****************************************
' CycleService() subroutine
' this subroutine is passed four variables:
' 1. strComputer = the name of the computer
' 2. strService = the name of the service (e.g. w3svc, smtpsvc, etc.)
' 3. strOperation = the operation to be completed (e.g. start, stop)
' 4. boolTrace = True will output trace information, False will not
' ****************************************
Sub CycleService(strComputer,strService,strOperation,boolTrace)
On Error Resume Next

' declare variables
Dim objComputer
Dim objService
Dim strTrace
Dim boolSuccess

' get ADSI objects and initial variables
Set objComputer = GetObject("WinNT://" & strComputer & ",computer")
Set objService = objComputer.GetObject("Service",strService)
strTrace = strOperation & " " & strService & " on " & strComputer
boolSuccess = False

' output trace information if needed
If boolTrace Then Trace "Attempting to " & strTrace & "..."

' determine the operation and carry it out
Select Case (strOperation)
Case START_SERVICE
If (objService.Status = ADS_SERVICE_STOPPED) Then
objService.Start
' If Err.Number<>0 Then ErrorHandler strTrace
While objService.Status <> ADS_SERVICE_RUNNING: Wend
boolSuccess = True
End If
Case STOP_SERVICE
If (objService.Status = ADS_SERVICE_RUNNING) Or (objService.Status = ADS_SERVICE_PAUSED) Then
objService.Stop
' If Err.Number<>0 Then ErrorHandler strTrace
While objService.Status <> ADS_SERVICE_STOPPED: Wend
boolSuccess = True
End If
Case PAUSE_SERVICE
If (objService.Status = ADS_SERVICE_RUNNING) Then
objService.Pause
' If Err.Number<>0 Then ErrorHandler strTrace
While objService.Status <> ADS_SERVICE_PAUSED: Wend
boolSuccess = True
End If
Case CONTINUE_SERVICE
If (objService.Status = ADS_SERVICE_PAUSED) Then
objService.Continue
' If Err.Number<>0 Then ErrorHandler strTrace
While objService.Status <> ADS_SERVICE_RUNNING: Wend
boolSuccess = True
End If
End Select

' output trace information if needed
If boolTrace And boolSuccess Then Trace strTrace & " was successful."

End Sub

' ****************************************
' Trace() subroutine
' outputs time and trace information
' ****************************************
Sub Trace(strText)
WScript.Echo Now & " : " & strText
End Sub

' ****************************************
' ErrorHandler() subroutine
' outputs error status and exits
' ****************************************
Sub ErrorHandler(strText)

'Dim strError
'strError = Now & " : The following error occurred trying to " & strText & vbCrLf
'strError = strError & vbCrLf & "0x" & Hex(Err.Number)& " - " & Err.Description
'WScript.Echo strError
'WScript.Quit
Err.Clear

End Sub

function ping(strTarget)
'cmdline="%COMSPEC% /c ping " & response
wscript.Echo strTarget
cmdline="ping " & strTarget
Call ExternalCMDCall(cmdline,strOut)
ping=strOut
wscript.echo ping
end function

Sub ExternalCMDCall(cmdline,strOut)
set objExCmd = objShell.Exec(cmdline)
strOut=objExCmd.StdOut.ReadAll
End Sub





You may see where i commented out the username and password for mapnetworkdrive.
 
Replace this:
WSHNetwork.MapNetworkDrive "Q:/", sourceDir, True', "administrator", password
By this:
WSHNetwork.MapNetworkDrive "Q:", sourceDir, True ', "administrator", password


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
sorry, i added the slash just to check to see if i needed it. originally i did not have it. i was just trying little things to see if it would work. according to the few books i have, it looks like my code is right (without the slash), but i can't figure out why it won't work.
 
it is now finished, and working. please see thread329-872632 for solution. thanks to all of you, for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top